Dodge Game

3DSpaceship and asteroid

General Instructions:

Click on the link to open the Starter file, it contains images and some code to help you get started.

Now, click on the fork icon .

coloured background

Then at the bottom it will give the option to fork the project to save and modify .

coloured background

Add the code inside the highlighted box in the examples.

coloured background



Spaceship movement :


For making the spaceship move left of the screen, make a conditional statement. Use keyIsDown() and specify the key of your choice.

coloured background


The x-axis of the spaceship is now used to move the ship to the left .

coloured background


Similarly, for making the spaceship move right of the screen, make a conditional statement. Use keyIsDown() and specify the key of your choice.

coloured background


The x-axis of the spaceship is now used to move the ship to the right .

coloured background coloured background

Notice the spaceship is move out of the canvas as the key is pressed down for long.
Add bounds on the left side and the right side , so the spaceship does not move out of the canvas.

coloured background coloured background

Asteroid movement :



Make the asteroid move down incrementing the value of the y-axis of the asteroid.

coloured background

Notice the asteroid after reching the bottom of the canvas just disappear and does not come back.

Make a conditional statement which checks if the y-axis of the asteroid is greater than the maximum height of the canvas.

coloured background

Reset the y-axis of the asteroid to the initial position which is -500.

coloured background coloured background

Randomise the x-axis of the asteroid, so it starts to appear from different positions in the x-axis.

coloured background

Randomise the size of the asteroid, so the shape of the asteroid keep changing.

coloured background

Add score :

Score variable is already present and the score board is also appearing but the score is not changing.

To fix this problem , find the code where the asteroid crossed the maximum height of the canvas , as that will make sure that it didn't hit the spaceship.

Increment the score by any value of your choice.

coloured background

Happy Coding!!

Continue Reading

Map & Random

Learn More

Function

Learn More