Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
96 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Stepping to the
 plate...

 Mr. Structure
 The New Shape
 Maker

 Update takes a few
 practice swings

 Let's Get Moving!
 Time to Clear the
 Bases?

 The Final Batters
 The Loop and His
 Team

 Until Next Time...

 Printable version

 


  The Series

 Part 1
 Part 2
 Part 3
 Part 4
 Part 5
 Part 6

 

Update takes a few practice swings

Update is our power hitter. He has the job of handling all updates. Let's take a look at exactly what it is he does.

Popup : Source Listing 3

Wow! For somebody so important he sure doesn't do very much. Almost like real life, what do you think?

To begin with we make a call to test the collision status of the current shape. If the call returns TRUE then we can not move the shape anymore and need to place it in the grid. So he makes a call to Place_In_Grid(). However, if the call returns FALSE, then we can still move the shape. So, we drop it down a notch by decrementing the Y coordinate of the shape.

The last thing we need to do is return to our manager and tell him whether we succeeded or failed. Before we continue though, let's take a closer look at Test_Collision() and Place_In_Grid() since they are the ones who really do the work.

Popup : Source Listing 4

The Place_In_Grid() function is the simpler of the two so let's cover that one first. It moves to the location in Grid Memory based upon where our current shape is located. Once there, it simply loops through every row in the frame and, if there is a block in that bit position, it sets the block to TRUE by indicating the current block texture + 1. The reason we had to do ( texture + 1 ) is we use zero to indicate that no blocks are there.

Test_Collision() is not quite so simple. It loops through all four columns, and, inside that, loops through all four rows of the current frame. It then tests the bit at its' own ( row, col ) location. If there is a bit turned ON there, it checks whether or not the grid has a block in the position directly under it. If it fails this test, on ANY bit, then the block can not be moved so we return TRUE. Otherwise, at the end, if there have been no collisions we return FALSE. At this point we also check to see if it is at the bottom of the grid. This constitutes the same thing as having a block underneath it.

As you an see, although Update() is very important to our team, he has so much to do that you ALWAYS want to have him delegate his responsibilities out to others. Then, just let him pretend to do what he is supposed to do.

NOTE: In case you missed my crude attempt at symbolism here is a quick explanation. YOU NEVER want to make functions that do many things. The ideal is to only have them accomplish one, maybe two things. Let a manager type function make calls, test for errors, and things like that.



Next : Let's Get Moving!