block by joyrexus 11219270

Lunar-lander

Full Screen

Use the left and right arrow keys to rotate the ship. Press the up arrow key to turn on the engine.

Try to land the ship safely on the ground. You must land gently or the ship will explode!

Notes

This is an example of Asteroids-style motion. The ship moves in straight lines until the engine is turned on and accelerates. When the ship reaches any of the stage boundaries it is repositioned to the opposite side. The ship rotates at ROTATION_SPEED degrees/second.

This example introduces a function getExplosion() which either creates a new explosion object or re-uses one that was created earlier. This approach allows the number of explosion sprites to increase dynamically but never creates more than are needed to display on screen at any one time.

All code here is taken straight from the Game Mechanic Explorer, a collection of concrete examples for various game mechanics, algorithms, and effects. The examples are all implemented in JavaScript using the Phaser game framework, but the concepts and methods are general and can be adapted to any engine.

index.html