Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Generating energy


We need energy to build the buildings. In this task, we generate energy for each satellite built on the board.

Prepare for lift off

Before we start this task, we need to revert the game parameters that we temporarily changed in the previous section. In the game.js file, we set the initial lives to 20 and the energies to 120:

game.lives = 20;
game.energies = 120;

We have the new display object, an energy bubble, which can be collected when it is generated by satellites. Add the energy.js file to the board-objects folder and include it into the HTML:

<script src="scripts/board-objects/energy.js"></script>

Engage thrusters

Let's work on energy generation:

  1. The graphics are defined in the assets.js file, but we will add more logic to the sprite with the energy.js file:

    ;(function(game, cjs, lib){
      function Energy(x, y) {
        cjs.Container.call(this); //super
        this.addChild(new lib.Energy());
    
        this.cache(-25, -25, 50, 50); // cache the bitmap to improve performance...