Book Image

Learning Cocos2d-JS Game Development

By : Emanuele Feronato
Book Image

Learning Cocos2d-JS Game Development

By: Emanuele Feronato

Overview of this book

Table of Contents (18 chapters)
Learning Cocos2d-JS Game Development
Credits
Foreword
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Creating Your Own Blockbuster Game – A Complete Match 3 Game
Index

Invulnerability


This feature has nothing to do with the new Cocos2d-JS stuff, it's just some polishing in game design, but remember polishing is always better than adding features.

People played Angry Birds series to death because it's polished, not because wooden blocks did break exactly like a real-world wooden block would.

So, after the player smashed the spaceship into an asteroid, let's make the spaceship invulnerable for a limited period of time; let the player see the ship cannot be destroyed by making it flash.

You are going to add an invulnerability attribute to the spaceship in the ship's ctor constructor:

ctor:function() { 
  this._super(); 
  this.initWithFile("assets/ship.png");
  this.ySpeed = 0;
this.engineOn = false;
this.invulnerability = 0;
}

When invulnerability is set to zero, this means the spaceship is not invulnerable and can be destroyed by asteroids. You have to add this case to Asteroid's update method:

update:function(dt){
  var shipBoundingBox = ship.getBoundingBox...