return to breakout

Started by
26 comments, last by L. Spiro 11 years, 3 months ago
well I have decided to finish my breakout game using opengl and c++. I am still stuck on how to get the ball to bounce off the brick and get it to disappear. Then when it is removed I want the ball to pass through the space where the brick was. Please don't give me a lot of code. Also I am using magic numbers for now. Here is just a little bit of code. if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f) { ystep = -ystep; g_bBlock[4].m_bActive_three=false; } well this code checks for a brick and then switches the ball's velocity and then turns off the brick. but it still bounces off where the brick was. I know I have asked this question before but I would like a fresh perspective. I am doing my best to finish this project.
Advertisement
You already have an array with a bool inside that tells if a brick is active or not. You only do the collision check if the brick is still active.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

well I have decided to finish my breakout game using opengl and c++. I am still stuck on how to get the ball to bounce off the brick and get it to disappear. Then when it is removed I want the ball to pass through the space where the brick was. Please don't give me a lot of code. Also I am using magic numbers for now. Here is just a little bit of code.


if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f)
	{
	ystep = -ystep;
	g_bBlock[4].m_bActive_three=false;	
	}
well this code checks for a brick and then switches the ball's velocity and then turns off the brick. but it still bounces off where the brick was. I know I have asked this question before but I would like a fresh perspective. I am doing my best to finish this project.

simply check that the brick is still valid when your comparing to hit it, like so:


if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f && g_bBlock[4].m_bActive_three==true) { 
   ystep = -ystep; 
   g_bBlock[4].m_bActive_three=false; 
}

your naming convention is a bit odd(_three?)

edit: also, just to toss this out their for thought: what happens when your ball impacts the block along the side's rather than top or bottom?

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

As Endurion pointed out just use the bool in the condition for collision.


if(g_bBlock[4].m_bActive_three==true)
{
if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f)
{
ystep = -ystep;
g_bBlock[4].m_bActive_three=false;
}
}

But trust me, there are much more efficient ways of detecting collision and removing the blocks. The one you are using is probably the easiest but not accurate in many cases.

I would agree with Endurion and Sam Sandeep. Sounds like you are calculating collision even if the brick is "turned off". I would also like to add why are you keeping the brick in memory at all? If it is "destroyed" once the ball makes impact why don't you just completely remove it from memory? Remove it from the active collection, free up memory don't have to waste time calculating for collision on it (even if it is turned off).

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

Man, I really hate to be a dick, but...

http://www.gamedev.net/topic/636083-little-more-help/
http://www.gamedev.net/topic/635556-little-help/
http://www.gamedev.net/topic/635213-collision-detection/
http://www.gamedev.net/topic/634727-breakout-game/
http://www.gamedev.net/topic/633265-collision-detection/
http://www.gamedev.net/topic/625158-collision-question/
http://www.gamedev.net/topic/622320-collision-code/
http://www.gamedev.net/topic/622165-2d-collision/

The list goes on.

You have this habit of posting a question, getting some answers, maybe posting some final response like "Wow, that is a lot of code", then disappearing for a few weeks. When you come back, you are asking the same exact questions as before. I really hate discouraging anyone, but are you really certain that programming is for you? It just doesn't seem like you are actually learning anything or making any progress at all. There is nothing wrong with not being able to program, but there is something wrong with continuing to ask the same questions over and over, wasting the time and effort of everyone who has posted in your many threads trying to help you out.

Sometimes I feel like Phil is trolling us, and he just chuckles when we post a lot of code to help him.

Then I think maybe he's just struggling very hard and just can't "get it". It happens. At least he's trying hard (if he's not trolling)

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

I am really trying hard, I really like programming but I am kind of slow.
If you're serious, then instead of posting another topic like this, go through all of your previous posts. Read the answers that other people posted, think about what they're saying, try to apply it to your problem. Your thread history has some good advice. Encapsulation. Separating logic from rendering. Collision detection. Go ahead and try to process it, then when you have specific new questions, come back here for clarification. Because the thing is, you are still pretty much doing collision "wrong". Previous answers in your other threads gave you some avenues to follow to learn how to do collision "right". It's really pointless to ignore that advice and keep chasing the wrong things and asking the same questions.
ok blanc I am not the best programmer but I do enjoy it. I graduated from college with a b.s. in c.s. in 2005. I have actually learned a lot since then but there always seems to be more to learn.

This topic is closed to new replies.

Advertisement