iDevGames Forums
Arkanoid type game question - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Arkanoid type game question (/thread-4937.html)



Arkanoid type game question - Taxxodium - Oct 7, 2005 12:30 PM

Hey,

I'm currently stuck in a world of non game apps, so I want to create a game that has animation. The people on IRC heard me say that I wanted to create a Crystal Quest clone. Unfortunatly I have jumped out of that idea.

Now I have a new idea, creating an arkanoid type game. But something more like an old Mac game called Beebop.

I have tried to recreate it but I'm kinda stuck in the functionality. In other words, I have no idea how to handle the basic game concepts.
What i currently have is

- I have a class for all the objects you see on screen
- in my view controller, I go through an array that contains characters and depending which character I get to, I create an object with a specific image
- in my draw loop, I go through the array that contains the objects and draw them in certain points

The problem lies in handling collision detection of the paddle and also of the ball and of course from the green block which should disappear when they are hit by the ball.

Currently the project is in Cocoa, but I will most likely do it in SDL, mainly because SDL has a topleft zero point and because if I manage to make the game fun, it can be ported to other systems.

The following image is how far I got, but as I said, nothing really works, except the paddle that moves with the mouse Smile

[Image: fusion.jpg]


Arkanoid type game question - JustinFic - Oct 7, 2005 11:11 PM

Oh man! I remember Beebop Smile

Anyway, for the brick collision, you can do a circle vs. rectangle collision test. I did one for a breakout clone I was working on ages ago, I dug up the code and found this. I added the comments in just now. It took me a minute or two to remember just what the hell I was doing here, but hope it helps:

Code:
// Overview: we want to test the distance of the ball
//   to the closest point on our rectangle.
                    
// We first need to determine the closest point.
// Let's start the point at the ball's position:
testX = ballX;
testY = ballY;
                    
// Left, right, bottom and top are the boundaries of our rect
left = testRect.left;
right = testRect.right;
bottom = testRect.bottom;
top = testRect.top;
                    
// Clamp the test position to these boundaries.
// This will give us the closest point to the rect
if (testX < left) testX = left;
if (testX > right) testX = right;
if (testY < top) testY = top;
if (testY > bottom) testY = bottom;
                
// Now it's a simple distance check
distance = (ballX - testX) * (ballX - testX) + (ballY - testY) * (ballY - testY);
if (distance < (balls[i].GetSize() * balls[i].GetSize() / 4.0) &&
    theBricks[k][j].GetState() >= kBrickActive) {
        // Do collision response, determine ball trajectory, break brick, etc
}



Arkanoid type game question - Taxxodium - Oct 8, 2005 12:52 AM

Thanks,

But how would you check for what's on the left or right of the paddle. I thought about getting the mouse position, for the left part subtracting half of the width of the paddle from the mouse position and then do a window coordinates to array coordinates conversion to get the object next to the paddle and see what kind it is.

Is that a good way or are there better ways?


Arkanoid type game question - unknown - Oct 8, 2005 03:38 AM

Crystal Quest was a good idea, Why have you decided to make a breakout clone?


Arkanoid type game question - w_reade - Oct 8, 2005 04:23 AM

I'd be inclined to make the paddle another rectangular collider, just like a brick in that sense, but one which is controlled by the movements of the mouse. That is, every time you get a mouse-moved event, you send it to the paddle, and the paddle updates its in-game state -- position and velocity, perhaps -- according to the information it received.

Then, colliding the ball with the paddle is no harder than colliding it with a brick, and the only difference is the hittee's response (presumably the ball will always bounce in the same way..?); and, you avoid making your collision code dependent on the specific input method the player is using :-).


Arkanoid type game question - unknown - Oct 8, 2005 04:34 AM

Quote:presumably the ball will always bounce in the same way..?
Hopefully not otherwise you wont be able to control the ball and it will just be a game of patience.


Arkanoid type game question - w_reade - Oct 8, 2005 05:38 AM

Uh, what? You seem to have misinterpreted me... I was just saying it might be easiest to have a consistent physics model -- for example, one in which a circle always bounces off a rectangle in such a way that the ball's perpendicular velocity is reversed, and its parallel velocity is modified by the rectangle's velocity. It doesn't have to be physically accurate, as long as it feels right :-).

In this instance, the brick collisions'll still work just the same, because they don't move... and if you ever want moving bricks, they'll hopefully be that much easier to add ;-).


Arkanoid type game question - unknown - Oct 8, 2005 06:10 AM

With a flat paddle and an accurate physics model you cant control the ball, it needs to push the ball left if you hit it with the left of the paddle, or you could use a curved paddle made of gears like I do Rasp


Arkanoid type game question - w_reade - Oct 8, 2005 11:57 AM

Consistent != accurate.

Curved paddle is fine, as long as you show it's curved; inaccurate physics are fine, as long as they're consistent. IMO velocity is a more pleasing x-velocity modifier than collision-position, but YMMV. Up to you :-).


Arkanoid type game question - PowerMacX - Oct 8, 2005 09:45 PM

unknown Wrote:With a flat paddle and an accurate physics model you cant control the ball, it needs to push the ball left if you hit it with the left of the paddle, or you could use a curved paddle made of gears like I do Rasp

Well, it may look flat at screen resolution, but have a "rugged surface" nonetheless (press command-option-= to see it Wink)

Personally, I prefer the velocity modifier rather than the position-based, particularly when the ball goes near the bottom left/right corners, since a position-based reflection is useless there.


Arkanoid type game question - unknown - Oct 8, 2005 10:00 PM

I prefer Crystal Quest.... Sad


Arkanoid type game question - Taxxodium - Oct 9, 2005 01:56 AM

unknown Wrote:I prefer Crystal Quest.... Sad

I'll rethink what game I wanna do, but first I need to finish an update for my current app.

Thanks for the info, it was really helpful!