Alien Attack Game – Complete

Save the world from an alien attack.

The Program of the Game

The HTML code creates the visual game elements inside the stage. The images are stacked in layers, just as they are with Photoshop.



JavaScript

Define variables:
The code initializes all the variables it needs so that it can be accessed and modified these objects.

Using the Enter key to input numbers.

Validate the input numbers:
Prevents players from entering anything except numbers.
Moving the game objects:
The render( ) function moves all the game’s object based on the game information:
Figuring out if the alien has been hit:
When the player clicks the button, the playGame( ) function is called.
The playGame function finds the alien’s next new position. It gives a random X position between 0 and 280 and then and 30 to its current Y position.If the gameWon variable is true, then the player has won and the appropriate message is displayed. But if gameWon is false, the function tells the player that he or she has lost.


Files to Download
Alien Attack (HTML)
Alien Attack Font 

Advertisements