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

 

The New Shape Maker

With the dreary setup stuff behind us we have things ready for the New Shape maker. His responsibility is fairly straight forward so let's take a look at the code before I start explaining things.

Popup : Source Listing 2

Do you see what I am doing with the code? You should start having at least a general idea when looking at the code segments. If not, start studying more ... that means writing code, not staring at mine!

To start with we check the area directly under where we want the block to start to see if there are blocks already in there. If so, then they died. It is a really simple concept. No more room on grid = DEATH!

Next we grab some random numbers to use for the block texture and the shape. I chose just to use the Get_Time() function that we have. We may write a true random number generator later in this article series. For now, this function call will serve our purposes.

In order to get a number between zero and six we divide by seven and take the remainder ( this is placed in EDX after a DIV ) . This way, the highest number we could have is six, and the lowest is zero, which is perfect since we have seven shapes to choose from.

We do something a bit different for the blocks. Instead of performing a MOD operation, we AND the number with ( N-1 ). Where N is the number you would normally MOD with. This only works for numbers that are powers of 2 however. We are taking advantage of another bit manipulation operation to speed things up.

The next step is to merely initialize the starting X and Y coordinates along with the starting frame to use.

That is all we need to do in order to create a new shape during the game. Once this function is finished everything is setup to start moving and manipulating the current shape, whatever it may be.



Next : Update takes a few practice swings