Advertisement

Arcanoid AI: problem in the ball

Started by September 03, 2006 03:04 PM
11 comments, last by apatriarca 18 years, 5 months ago
Per prima cosa -

wait, my Italian isn't so good...

First of all, you can't know if the ball is hitting the paddle just by looking at the y-position. Surely the ball can go past the paddle if the paddle isn't in the right place? So you have to look at both the x- and the y-position.

Once you do that, it won't matter if the ball is going up or down -- either way it should reverse directions.

Really, though, what you need to program is an abstract obstacle that can be anywhere in the area. You create your program so that if the ball touches the obstacle from any direction, it will reverse in the appropriate direction (i.e. if the ball hits one of the edges on either side, it will reverse its horizontal direction).

At that point, you can simply make your four walls and your paddle into "obstacles", and they will take care of the rest. You won't need to hard-code all the different positons.

Buona fortuna!
Quote:
Original post by Asbestos
At that point, you can simply make your four walls and your paddle into "obstacles", and they will take care of the rest. You won't need to hard-code all the different positons.

Buona fortuna!

I agree that he need to write a function that handles all the collisions with obstacles (that in this game are rectangles) but there is some reasons to do something different with the walls. The walls can be approximated with an infinite line. To find the time the ball hits the wall he only have to find the point of intersection between two lines. And most important the function to find that collision is a building block of the code that handles collisions with rectangle obstacles...
The pad isn't in the line y = 0. If the ball "collides" with that line the game ends. The pad is an obstacle like the others.

[Edited by - apatriarca on September 5, 2006 3:57:14 PM]

This topic is closed to new replies.

Advertisement