Sign in to follow this  

Using RECT arrays to display a set about of brick sprites

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm quite confused on a game I've been developing recently. It's just a simple ball and paddle game. Common names such as Breakout, Brick Break, Breakin' Bricks, and so on. I have practically everything figured out, but I just can't figure out how to display a set amount of bricks on the screen in a uniform patten (pretty much rectangle design). So far I declared the RECT array as such: RECT bricks[NUMBRICKS]; NUMBRICKS I have earlier defined as 100, thus 100 bricks in the array. I've successfully loaded the block sprite into the game, and actually was able to display a single block (although I haven't added any collision detecting yet, I'm fairly certain I know how). Here is the RECT array coding I have: //draw the bricks RECT bricks[NUMBRICKS]; D3DXVECTOR3 position(SCREEN_WIDTH/2-brick.x,100,0); int n; for (n=0; n<NUMBRICKS; n++) { bricks[n].left = brick.x + brick.x; bricks[n].top = brick.y + brick.y; bricks[n].right = brick.x + brick.width-brick.width; bricks[n].bottom = brick.y + brick.height-brick.height; sprite_handler->Draw( brick_image, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255)); } and here is the SPRITE declare coding: //brick sprite LPDIRECT3DTEXTURE9 brick_image; SPRITE brick; All this manages to do though is display a single block in the screen. Can anyone help me display my block sprite in a rectangular pattern?

Share this post


Link to post
Share on other sites
Ok....
So, should I put the position variable inside the loop, and include variables for its parameters?

I think I'll try that and see what happens...

Thanks :)

Share this post


Link to post
Share on other sites
Ok.


Here is the code I have now. The position variable is inside the loop, but it does not seem to be changing...

//draw the bricks
RECT bricks[NUMBRICKS];

int n, posy=SCREEN_HEIGHT/2-brick.y, posx=SCREEN_WIDTH/2-brick.x;
for (n=0; n<NUMBRICKS; n++)
{
D3DXVECTOR3 position(posx,posy,0);
sprite_handler->Draw(
brick_image,
NULL,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));
posx += SCREEN_WIDTH/2-brick.x;
posy += SCREEN_HEIGHT/2-brick.y;
}


The block (just one is visible) is drawn in the middle of the screen...

Share this post


Link to post
Share on other sites
No, it still doesn't change. Positon is equal to posx and posy which are set only once, hence why everything still draws in the same spot.

Edit: Also don't cross post, one thread per topic is enough.

Share this post


Link to post
Share on other sites
numbers may vary, but you'll get the idea...

Quote:

posx += SCREEN_WIDTH/2-brick.x;
posy += SCREEN_HEIGHT/2-brick.y;


So, if SCREEN_WIDTH = 640, and SCREEN_HEIGHT = 480, and your sprite.x=0 and sprite.y=0...then for the first brick...


posx = 640/2-0 = 320
posy = 480/2-0 = 240
------------------------
| |
| |
| ---- |
| | | |
| ---- |
| |
------------------------


for the second brick...

posx += 640/2-0 = 320+320 = 640
posy += 480/2-0 = 240+240 = 480
//the high-extent of the screen
------------------------
| |
| |
| |
| |
| |
| |
-----------------------|----
| |
-----


check exactly what you're adding to posx and posy

Share this post


Link to post
Share on other sites

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this