Sign in to follow this  
detlion1643

Overall goal/rendering, and a little collision

Recommended Posts

I'm stumbling my way through a lot stuff that would be deemed basic (however not really for me yet) - I'm trying to comprehend my overall thinking and direction.


Figure this could be like a brick breaker type of game. A ball that bounces off a brick:
So, I set out to create a brick class and a ball class. In the ball class I set the xloc, yloc, xvel, yvel, xdir, ydir (and some other stuff). Then I implement the rendering event in the ball class to draw the ball where I need it. I figured it should logically be like this:
1. Change xloc and yloc according to directions and velocity.
2. Check for collisions and change directions (plus "smaller" velocity moves depending).
3. Change xloc and yloc according to directional changes and the "smaller" velocity changes if needed.
4. Render according to the new changes.


The brick class has a Render method, as well as a Hit method. It contains and xloc, yloc, width, height (and some others)
1. Render according to transparency defined in hit method.
2. When transparency hits 100, destroy/remove/dispose that current brick control
So far, does this sound right? Is the ball render method supposed to be responsible for checking all that? I was hoping there won't ever be a time where a Render would be ran without a Render before it finishing...


And, I have concerns about collision detection and direction/velocity changing. If the ball hits a brick, I wouldn't want to just change based on right angles, would I? Don't you want to dynamically change the directional velocities based on the location the ball hit a brick or paddle?
Am I going about it all wrong?

Share this post


Link to post
Share on other sites
Welcome to the world of rigid body dynamics, where you find out that while collision is "as easy as goggle suggests" building on top of it is not.

To consider paddle hits, use a convex polygon/hull.

For boxes, the whole thing is a bit more complicated. Most collisions I've had the chance to observe didn't happen on the edges but rather on some point on the collision faces. So if your ball hits the brick exactly on the vertex... I have no idea how exactly it will work but I know for experience it will behave consistently.

So in short, I encourage you in considering a physics library.

Share this post


Link to post
Share on other sites
[quote name='Krohm' timestamp='1343282885' post='4963200']
Welcome to the world of rigid body dynamics, where you find out that while collision is "as easy as goggle suggests" building on top of it is not.

To consider paddle hits, use a convex polygon/hull.

For boxes, the whole thing is a bit more complicated. Most collisions I've had the chance to observe didn't happen on the edges but rather on some point on the collision faces. So if your ball hits the brick exactly on the vertex... I have no idea how exactly it will work but I know for experience it will behave consistently.

So in short, I encourage you in considering a physics library.
[/quote]

I'll disagree with this post. For a simple breakout clone, you don't need a physics library, and it will help you understand the basics of collision detection and response.

Your ball class doesn't need xDir and yDir as the velocity defines the direction the ball is moving (xVel > 0, it's moving right, xVel < 0, it's moving left, etc.)

Initially, I wouldn't worry about changing the angle of the bounce, just simply reverse the axis it's collided with (so, if it collides with a brick above or below it, set yVel = -yVel, if it hits the wall on the x axis, set xVel = -xVel).

Eventually, you can modify it to use different angles based on the place it hits the paddle, but that should be a feature.

For your brick class, you should always render it, but, when the brick should be removed, the Brick object should be removed from the Brick List, instead of just stopping rendering. once all bricks have been removed form the brick-list, you've broken all bricks, and go to next level.

Good LUck.

Share this post


Link to post
Share on other sites

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