quick question

Started by
3 comments, last by nobodynews 13 years, 5 months ago
I am programming a "breakout" game using c++ and directx9. I am able to get the ball to bounce off the bricks but cant get the brick to turn off permanently. Basically if flashes off and on and when hit.I am probably overlooking a very minor detail in my code.
Advertisement
yes you are prolly over looking something in your code. what it is no one knows because you display none of your code. this is what i think you are prolly doing.

you have all your bricks in a list or array. every frame you see if the ball hits a brick in this array. you prolly have a bool variable per brick that determines if it is displayed or not. and if you get a hit then you toggle the bool. what you are prolly NOT doing is on the collision detection....ignore the collision if the brick is not displayed. which is what you need to do.
here is some of my code.
	int  col_index;	(int)col_index = 0.005 * ball_left;	int row_index;	(int)row_index = 0.02 * ball_top;	if(bricks[row_index][col_index]==1)	{	bricks[row_index][col_index]=0;	//draw black brick	RECT rect;	rect.left = col_index*200;	rect.right = col_index*200+200;	rect.top = row_index*50;	rect.bottom = row_index*50+50;	d3ddev->StretchRect(surface_six, NULL, backbuffer, &rect, D3DTEXF_NONE);	y_vel*=-1;	}
well I have tried several different things but no success, yet
Quote:Original post by phil67rpg
here is some of my code.
*** Source Snippet Removed ***
The code you provided by itself doesn't tell much. I bet in some other part of your code you essentially reinitialize the 'bricks' 2d array with what was in it originally. Again, hard to say without more detail.

Other issues you probably will encounter based on that code. You change the y_vel if the ball position meets the brick position. But if the ball hits the side of a block then the x_vel should update not the y_vel. Basically you need to know which side of the brick you hit to tell what direction the ball should bounce.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement