Home > Articles > Programming > Games

  • Print
  • + Share This
This chapter is from the book

Recipe: Powerups

Did you put any coins out of Guy’s reach? Let’s give him some winged boots to help him jump higher. In Tiled, you need to add an object layer called boots. Then add objects in the same way as with coins before, declaring the name to be boots with image:boots and spritewidth:16. First, add boots to the resources.js file in Listing 5.22. Remember to watch your commas between each object in the array.

Listing 5.22. Adding the boots Image

  name: "boots",
  type: "image",
  src: "boots.png"

Next, add the boots to the entity pool in main.js, as shown in Listing 5.23.

Listing 5.23. Adding the boots to the entityPool

me.entityPool.add("EnemyEntity", EnemyEntity);
me.entityPool.add("boots", BootsEntity);

Then declare the BootsEntity at the bottom of entity.js, as shown in Listing 5.24.

Listing 5.24. Creating the BootsEntity

var BootsEntity = me.CollectableEntity.extend({
  init: function(x, y, settings) {
    this.parent(x, y, settings);
  onCollision : function (res, obj) {
    this.collidable = false;
    obj.gravity = obj.gravity/4;

This should all look incredibly familiar because it’s basically the same as the CoinEntity, with one notable exception. On the last line is the powerup part. When the player gets these boots, Guy will experience one-fourth the gravity. He should have no problem reaching any coins in the sky now!

The game is now complete. For one last recipe though, let’s take a look at how we might improve the presentation of the game a bit.

  • + Share This
  • 🔖 Save To Your Account