|Published (Last):||1 February 2015|
|PDF File Size:||1.26 Mb|
|ePub File Size:||15.93 Mb|
|Price:||Free* [*Free Regsitration Required]|
Start your free trial Creating a Monster Class Creating a monster is similar to creating a player. In fact, we are going to use the same basic class code but change its name and namespace. Create a new file called zombie.
Now, copy the following code into the monster class: 1 ig. This is a simple monster, so there are only a few sprites representing its animation.
You can then click on the map to add the monster where you want it. Select Zombie from the drop-down entity list. Once you have done this, refresh the game in your browser and you should see your new monsters. If it does, we toggle the value of the class flip property. After testing, the direction and velocity are updated before this.
You will see the monster instances moving around, and when they hit the edge of a ledge, they flip and go the other way. We want to make sure our zombies flip direction once they hit a wall or the end of a platform. We just need to add a few more lines of code to clean this up. Collisions with walls and the collision map are handled through the handleMovementTrace function.
Now we have covered all our bases and made sure our zombies will not fall off ledges or platforms, but we still have one issue. There is no collision detection between the monster and the player. The player simply passes through zombies without collision detection. Before we get into adding more code to the monster, we need to talk a little bit about entity-based collision detection in Impact.
However, Impact has built-in collision detection that we can use for interaction between our entities. That is, we can focus on setting up collision relationships instead of creating all that collision code from scratch.
Building HTML5 Games with ImpactJS: An Introduction On HTML5 Game Development (Rev. 3)
Start your free trial Loading New Levels It looks like we are ready to load our next level. Loading levels in Impact is incredibly easy; we actually did it as one of the first steps in setting up this game. In this section, I will talk about building something we call a trigger, which is an invisible area of the map that executes an activity when the player enters it. In this case, we will be building a level exit.
Building HTML5 Games with ImpactJS by Jesse Freeman
Building HTML5 Games with ImpactJS