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
38 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
 Rotation Solution
 The Sound Module
 One Big Headache
 Screen Transitions
 Putting More Pieces
 Together

 Until Next Time

 Printable version

 


  The Series

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

 

Rotation Solution

The solution to our rotation problem was fairly straightforward. Basically, we already had all of the routines that we needed. What we had to know was if, at any given frame, the current piece would be out of bounds -- which MoveShape() does for us. So, the fix we have is a simple one. We can just call that routine with the frame it "would" be on next, right? Wrong. That is what I tried at first because it makes sense. But, there is a hidden problem with that method.

The problem lies in that fact that any piece could already be out of bounds when you adjust the frame. Move_Shape() only tells you if you can move the shape to the left or right, and does so if it can. If we fake our next frame for that call it may succeed because it is already out of bounds by one column if it was on the edges previously. This means we need a way to prevent it from ever being out of bounds to begin with.

The solution is to move it in towards the center by one column beforehand. Then, when we make the call, the shape is guaranteed to be on the edge, or in the middle, never outside the grid. The way we decide if we could go to the next frame is by seeing if the X coordinate sent before we made the call matches the one we have after the call. If it does, then that means the shape can be rotated ... if they don't match then the shape can not be rotated.

This method has the advantage of eliminating the need for any other code. The Move_Shape() function will not succeed if something else is blocking its move. Therefore, we do not need to do any other tests on the shape to see if other blocks are in the way. Just that simple call based on the next frame. So, we not only solved the problem ... but also made the routine shorter in the process.

The new Rotate_Shape()

Popup : Source Listing 1 : Rotate_Shape()




Next : The Sound Module