Games

Mithat Konar

March 21, 2016

Games

Download starter project

In this section, we will demonstrate a number of concepts that will let you take what you have learned in previous sections and put together a complete game.

Concepts to be demonstrated in this section include:

“Start” and “Game Over” screens

enchant.js provides an easy way to add game “Start” and “Game Over” screens. Unlike examples in previous sections, the examples here use the nineleap.enchant.js plugin. You indicate you want to use the plugin by including it in the host HTML file. (In the project files, open index.html and look for the line that reads <script src='misc/plugins/nineleap.enchant.js'></script>)

Once you link to the plugin in the host HTML file, the plugin automatically gives your game a “Start” screen. Adding a “Game Over” screen is almost as easy: just call game.end() where you want the game to end.

Rain Game 1

For our first complete game, we will take the “Collecting raindrops” example from Collisions and turn it into a game that challenges the player to collect all four raindrops as quickly as possible. The game will start when the user clicks on the “Start” screen, will tell the user how long she has been playing, and will display a “Game Over” screen when the player collects all four raindrops.

In this section, you will be introduced to:

Code reorganization


  

Run | Raw code

Adding a label


  

Run | Raw code | Differences

Counting up


  

Run | Raw code | Differences

Ending the game


  

Run | Raw code | Differences

Rain Game 2

The game above challenged the player based on the question, “How quickly can you collect the droplets?” In this second version of the game, we will change the challenge to “How many drops can you collect in (some-number-of) seconds?”

In this section, you will be introduced to:

Keeping score


  

Run | Raw code | Differences

A flood of droplets


  

Run | Raw code | Differences

Counting down


  

Run | Raw code | Differences

Final flourish


  

Run | Raw code | Differences