Mars Lander


You are the pilot of a Mars lander! Can you bring it down safely to the surface of Mars?

And here are the coding skills you will learn:
1- "Dampening" -- multiplying game variable (such as thrust) by a constant number, found through trial and error, to make the game playable.
2- Procedural World Generation - writing an algorithm to create the world the game will play on.

To see a working example click here


Directions
  1. If you are coding outside of WoofJS.com (like in Sublime), insert the Woof_JS source tag into the <head>section of your project page:

    <script src="https://rawgit.com/stevekrouse/WoofJS/master/dist/woof.js"></script>

    Your code now speaks Woof!

  2. Select a background appropriate for your game. Create a Lander with an image you like.

  3. Setup variables for:
    * downSpeed
    * sideSpeed
    * downThrust
    * gravity

  4. Add a forever loop. In the loop, move the rocket by downSpeed and sideSpeed.

  5. If a key is pressed, increase downThrust otherwise make downThrust zero. Adjust downSpeed by downThrust and gravity.

  6. You might notice that its hard to play-balance the game, to make the lander change speed smoothly. Add variables for speedDamper, thrustDamper and gravityDamper and use these when you calculate speed:

       lander.y = lander.y - downSpeed/speedDamper;

    Change these till the lander is flying smoothly.

  7. Add text labels to show downThrust and downSpeed. Adjust these so they are human-readable integers (numbers without decimals. Also add a label to show status messages, i.e. “You Landed!”

  8. Check if the lander has hit the bottom of the screen, and if the speed is too great, show a crash, with an appropriate graphic. If the speed is good, congratulate the player on a good landing.

  9. Create your landing terrain. One way to do this is to use a for-loop, and create as many mountain rectangles as you need to fill the screen. Use random numbers to vary the width of each rectangle and also how far the top of each rectangle is away from the previous one. Make sure to add each rectangle to an array.

  10. If the width of that rectangles is above the minimum needed to be a landing pad, add a yellow line indicating its safe to land there.

  11. As the lander is flying, cycle through all the rectangles and check if the lander is touching any of them. Use the code you had from before to check if the landing speed is safe, and if its a crash or a landing.

  12. Test and finish the project till it looks perfect to you.





(c) 2017 by Code Craft Academy