Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Jump Start CoffeeScript > 5. Bringing a Game to Life

Chapter 5
Bringing a Game to Life

This chapter is going to apply all that we’ve learned, rigorously and unrelentingly. We have a long day ahead of us: block collisions, entity collisions, gravity, ladders, AI, collectibles, digging, and building. It seems like a forest of features but, thankfully, our base lets us easily add them one tree at a time.

Block Collision Detection

Our levels are ephemeral at the moment; pretty pictures in the background with no effect on our players. We need some collision detection, as evident in Figure 5.1.

block collision detection collision detection Up against the wall

Figure 5.1. Up against the wall

The principle behind our block collision code goes like this: starting from a current picture (the first image in Figure 5.1), the entity will register its intent to move (either through AI for the ninjas, or by pressing the keys for the player). We take this intent and see how many pixels it would move if nothing was blocking it (the second image in Figure 5.1). We test this new position, and if something is blocking the entity, we move it back a little to the correct position so that it’s touching the edges of the block, without overlapping it (the final image in Figure 5.1).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint