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

 

Let's Get Moving!

Now that we have a piece to play with, we need to do just that, play with it. Get your minds out of the gutter!

Anyway, here is the code

Popup : Source Listing 5

These two functions Rotate_Shape() and Move_Shape() are pretty big, so it is good they are twins. Yet, what they do, is fairly cut and dried. Let's cover, just in general, what it is they do.

The rotate function first decided if it is at the last frame. If so, it has code to wrap it around for all of the test, otherwise it just uses the next frame. Then, it loops through all of the bits, finding the valid ones, just like Test_Collision(). If there is already a bit set in the place the shape would be at then it is not allowed to move and the call fails. And ... that is that.

NOTE: Code is not in there to check for out of bounds on the grid. So, if you rotate at a corner, you may slide out of the grid and into the background area. This has been left as AN EXERCISE FOR YOU. I wanted to see something interactive come out of this article series, and I decided this would be as good of a place as any to start asking for it. I will present my solution in the next article. Compare yours to mine at that time.

Back to the code at hand: Move_Shape(). This function will move the shape to the left, or to the right, depending on the value passed into it. It merely tests the bits once again. Only this time we have to find the leftmost, or rightmost, valid bit in each row. Then, we check the grid block to the left or right and see if it is empty. Accordingly, either we move it, or we don't, and then return to the caller.

There isn't much else to talk about in this section. You have seen how to access everything many times now. The only thing that changes is the things we need to access, or the order in which we test stuff. These are the kinds of things that need to be resolved at design time.



Next : Time to Clear the Bases?