• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Breakout clone problem :(

## Recommended Posts

Sir_Spritely    122
Hey, I have read TOTWGPG and I am now attempting a simple breakout clone, only it isn''t as simple. I have set up DX and have a bitmap loaded on the screen. My next plan is to have the blocks on the surface in bitmap form rather than the Freakout version in Lamothes book. I can get the blocks loaded onto the surface in random locations peice of cake but I cannot figure out how to put them in a row/column order. I have tried an array but I am having trouble with the pointers and the directx draw_bitmap stuff in terms of putting it all together in a loop to work. If this doesn''t make any sense, then I can post the code if needed. If anyone has a version of this which uses bitmaps and would be kind enough to donate the code (as long as its easy to understand) I would appreciate it very much. Help appreciated on this one! Pk

##### Share on other sites
SpaceRook    160
I''m not quite sure what your problem is. Are you saying that you can display bitmaps, but that you are having trouble getting them to display in rows and columns?

I recently wrote a breakout clone and the way I handled this was with a double array. My array was of the form int gameField[6][20], with 6 rows and 20 columns. A 1 in the array represented a block, and a 0 represented no block (so as you play the game, the array is gradually getting filled with more and more 0''s).

My game field had a base location, and the coordinates of all the blocks where derived from that base location. Teh base location represented the top left corner of the block field. If we call this point (x,y), you can draw your blocks in nice rows and columns with a double loop:

for(int row = 0; row < 6; row++)
for(int col = 0; col < 20; col++)
// draw image at x_coord = col*WIDTH + x
// y_coord = row*HEIGHT + y
// where HEIGHT and WIDTH are the height and width

Generally, whenever you see repetitive graphics in some type of simple geometric structure (square, rectangle, triangle, diamonds), the problem can be solved with creative use of loops. Space Invaders is another game that probably uses this technique.

Does this make sense? If there are still problems, give me some more info and I''ll be glad to help.

##### Share on other sites
Sir_Spritely    122
Hi,

Yeah that is what I''m saying, I''m having trouble getting the blocks which are bitmaps into a row/column order.

I am cool with the loop side of things but my problems lies in where to put the bitmap block loading, blitting commands, in the loop or where?

Pk

##### Share on other sites
If your bitmaps for the blocks are say 40 wide by 10 high, and you want a 5 pixel space between blocks vertically and 10 pixels between them horizontally. Plus you want your blocks to be 25 pixels from both the top and sides, you might try this:
  //using the numbers above, you can have 15 columns with 800x600//I''ll limit it to 6 rowsint baseX=25; //block starting pointint baseY=25; //block starting pointint xOff=50; //offset between the start of each block horizontallyint yOff=15; //offset between the start of each block verticallyRECT source,dest; //rectangles for blittingfor(int r=0;r<6;r++) { //''r'' for row for(int c=0;c<15;c++) { //''c'' for column //if you have more than one type of block, you will have to //set the source RECT differently source.top=0; source.left=0; source.bottom=10; source.right=40; //all dest RECT values start from the base point //and move outwards based on the loop dest.top=baseY+(r*yOff); dest.left=baseX+(c*xOff); dest.bottom=baseY+(r*yOff)+10; dest.right=baseX+(c*xOff)+40; //blit the block backBuffer->Blt(&source,blockSurface,&dest,DDBLT_WAIT,NULL); }}

Hope this is clear enough and what you were looking for.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

##### Share on other sites
Sir_Spritely    122
Anyone got any code for this that I can look at and learn from. Preferablly one which uses bitmaps for the blocks, bat and ball?

##### Share on other sites
You can use that code I gave you. There might be some confusion with a couple of things. ''backBuffer'' is the back buffer for you primary surface, so it is a LPDIRECTDRAWSURFACE7. ''blockSurface'' is also a LPDIRECTDRAWSURFACE7. That would be an OFFSCREEN_PLAIN that you would load your bitmap onto.

Is there anything specifically that you don''t understand?

One more thing, that code I gave you would be placed inside the rendering loop.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

##### Share on other sites
Sir_Spritely    122
Hey,

Yeah it''s pretty much the lot, what I''ve done is use the library modules created with TOTWGPG and then created a basic DirectX screen template which also loads a bitmap onto the back buffer and then flips it.

My problem is looking at code like that, how to implement it, where does it go? Do I use that as a function - bang it in the middle of the main_game or put it with the DirectX loading stuff in Game_Init.

I seem to be having a problem with putting everything together - if you know what I mean. I understand the very basic basics of DirectX, I understand albeit I''m no expert C++. I understand Windows enough to get by and I understand the actual game loop proccess it''s just where to put things like the code above I guess.

Or I need more sleep, could be that LOL!

##### Share on other sites
SpaceRook    160
quote:
Original post by Sir_Spritely
Hey,

Yeah it''s pretty much the lot, what I''ve done is use the library modules created with TOTWGPG and then created a basic DirectX screen template which also loads a bitmap onto the back buffer and then flips it.

My problem is looking at code like that, how to implement it, where does it go? Do I use that as a function - bang it in the middle of the main_game or put it with the DirectX loading stuff in Game_Init.

I seem to be having a problem with putting everything together - if you know what I mean. I understand the very basic basics of DirectX, I understand albeit I''m no expert C++. I understand Windows enough to get by and I understand the actual game loop proccess it''s just where to put things like the code above I guess.

Or I need more sleep, could be that LOL!

Spritely, I just sent you an email of my breakout clone "Paper Shredder". The .zip file includes the source files, the VC++ project file, and all the graphics (I just zipped my entire project directory and sent that). I am new to game programming, too, but I think my main game loop is pretty typical and maybe you can get something from it. I explained a little bit more in my email. If you have any more questions, feel free to ask. Also, if anyone else wants the code to my game, I''ll send it.

##### Share on other sites
Sir_Spritely    122
Hey,

Thanks, I''ll have a scan at the code over the weekend and if I come up against any probs I''ll mail you.

Thanks again!

Pk