Game Development Reference
In-Depth Information
Note that we checked the object's tag to see whether it's the player or not. Since we
now have different types of objects colliding with one another, we need a way to test
these collisions. Sure, we can keep setting up collision layers, but tags can be handy
too. Perhaps, you have a field of flowers, which are all the same object, but you want
only one of them to be pickable. You could give that one flower a Pickable tag.
Pretty handy, eh? So, make sure that the tag of the Player object is set to Player .
The Player tag is added by default to a new project, so you don't have to worry
about adding it.
Oh, and don't forget to populate the Boss Controller field on the Boss Crush Zone
object. Next, modify PlayerStateListener to listen for the hitByCrusher message.
Add the following function anywhere you want in PlayerStateListener :
public void hitByCrusher()
{
onStateChange(PlayerStateController.playerStates.kill);
}
Now, whenever the boss lands on the player, the player will get killed; however, not
when the boss collides with the player in other ways! As always, feel free to change
and improve on the code as you desire. Note that enemies give the player points
when they are defeated, but you won't want the boss crushing the enemy to earn the
player points. Take a stab at working through the code to make that happen on your
own. If you get stuck, take a look at what we did in the example project.
Summary
Play the game now and enjoy fighting with the enemies, taking on the boss,
and repeating. The game is now a rather complete game that cycles endlessly with
enemies and a boss.
Now that was a rush! A big freaking boss dropping out of the sky? Yeah, those
robots were pretty upset, but your elite coding skills gave them both a defender
and a way to beat that defender.
There are a few final things to do before we're done here, including some cleanup.
In the next and final chapter, we'll discuss:
• Implementing game rounds with an increase in game difficulty
• Creating a basic start screen
 
Search WWH ::




Custom Search