The Final BattersOur two final hitters are the publicity hounds Draw_Shape() and Draw_Grid(). Below is their code. If you have been able to keep up with this article series so far then this code should be a breeze to understand. Both of them do the same basic thing. The only difference between the two is that one operates on the current shape, and the other draws everything currently in the grid. The basic idea is to loop through every bit in the frame for the shape, or every byte for the grid ( You should be very used to this looping concept by now ). Then, either we use the current shape color, or the number stored in the grid, to access the proper block texture to use. The rest involves a call to draw the surface on the back buffer. The one thing that you need to make sure that you don't forget however is that you need to convert from grid to screen coordinates. If you do not then everything will be drawn at the left-hand side with A LOT of overlap. Also, keep in mind that since we use the DX blitting function the back buffer must NOT be locked prior to the call. Make sure that if you did lock it that you unlocked it before you make the call, otherwise you will crash. That is all that our functions do, and more importantly, all that we need to have on our team for the time being. Now, it is the manager's job to get the game running for us. So, let's go investigate "the loop."
|
|