Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Arkanoid, first game attempt  (Read 1523 times)
0 Members and 1 Guest are viewing this topic.
Offline steeg

Junior Newbie





« Posted 2006-01-24 21:58:34 »

Hi, I'm programming an arkanoid/breakout clone (very basic since this is my first game) and for the collision detection between the ball and the bricks, I wrapped each ot these objects with a rectangle (Rectangle class) and used its intersects() method.

I am not using any angles or anything, only position and speed variables. The thing is that if the ball hits a brick on its top or bottom, then I multiply its ySpeed by -1, and if it hits the brick on its side, the same has to be done with the ball's xSpeed.

Is this the best approach for this type of game? Also, how can I detect on which side the ball has hit the bricks? If there is a more efficient way of doing this, please let me know.

Thanks.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2006-01-24 22:22:45 »

>Is this the best approach for this type of game?

No. The best approach is priori-ish. You predict if a collision will happen and act accordingly. Like you have the normalized time interval of 1 from one frame to the next, you check if a collision will happen (with some sweeping algorithm), the you subtract the (normalized) timespan from your remaining timespan (started with 1) and continue with that until you run out of (normalized) time. Thats it... basically.

Its horrible complicated... mind you. But the advantage is that the simulation is *very* accurate. It does look and feel a tad more solid/real than breakout games usually look like. (You also dont lose speed when collisions happen.)

Well, I suggest to keep it like that. <edit>I mean the simple approch, you're currently using</edit> If your timestep is small enough it works pretty well. If the displacement gets too big the ball might warp through bricks and/or the paddle.

*copy&paste*



Eg the brick is 16px heigh and the ball radius is 6. 16+6+6=28. So don't move more than 27px otherwise the ball can warp through bricks. (It's really "fun" if the ball warps through the paddle Roll Eyes).

弾幕 ☆ @mahonnaiseblog
Offline steeg

Junior Newbie





« Reply #2 - Posted 2006-01-24 22:48:35 »

Let's say I check to see if a collision will happen within the ball's path (imaginary line starting at the center of the ball), how could I detect from which side the ball will be hitting the bricks? Thanks.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #3 - Posted 2006-01-25 02:30:57 »

The ball follows the path... it hits a brick on the side that intersects the path and is closest to the balls current position.

Offline steeg

Junior Newbie





« Reply #4 - Posted 2006-01-25 19:18:49 »

Thanks for the opinions, I'll take them into consideration for when I'm a bit more advanced in game programming. For the time being, I used outcome(Rectangle e) in the java.awt.Rectangle class and checked its return value (eg. Rectangle.OUT_BOTTOM) to determine where the collision took place.

Thanks.
Offline Serethos

Junior Member




Java games rock!


« Reply #5 - Posted 2006-01-30 21:19:24 »

ahh thats my topic! i can only underline to use a very basic collision detection. my first java project
was a (never finished) arkanoid. as more as i advanced in the game and used more complex
techniques the problems really grew exponentially!
there are questions like how to measure if a ball hits exactly a corner of a ball. or the problem
of multiple reflections, e.g. the ball hits a brick, so that its velocity vector gets reflected. after each
collision you would need to check another time for a collision (if the ball gets "reflected" into another
brick) etc.
another issue is how you generally deal with movement. if you add a dx/dy to your with bigger values
for fast movement the ball can jump over small objects without collision or even get stuck in them.
most methods to avoid this result in another compromise: precalculating a collision, to move a stuck
ball out of its position etc.

i really noticed that an atomic clear arkanoid becomes a physical snooker simulator. to make things
short, take the easiest way to have a collision, test, if any of your little inaccuracynesses are detected
by your eye or by the game feeling. and then consider more complex improvements.
Offline steeg

Junior Newbie





« Reply #6 - Posted 2006-01-30 21:53:49 »

ahh thats my topic! i can only underline to use a very basic collision detection. my first java project
was a (never finished) arkanoid. as more as i advanced in the game and used more complex
techniques the problems really grew exponentially!
there are questions like how to measure if a ball hits exactly a corner of a ball. or the problem
of multiple reflections, e.g. the ball hits a brick, so that its velocity vector gets reflected. after each
collision you would need to check another time for a collision (if the ball gets "reflected" into another
brick) etc.
another issue is how you generally deal with movement. if you add a dx/dy to your with bigger values
for fast movement the ball can jump over small objects without collision or even get stuck in them.
most methods to avoid this result in another compromise: precalculating a collision, to move a stuck
ball out of its position etc.

i really noticed that an atomic clear arkanoid becomes a physical snooker simulator. to make things
short, take the easiest way to have a collision, test, if any of your little inaccuracynesses are detected
by your eye or by the game feeling. and then consider more complex improvements.


lol, I pretty much had all of those problems myself. Since it was (is) my first game project, I didn't expect certain things to happen, that now seem obvious...like the ball skipping over objects where it should collide, as a result of it travelling too fast and not implementing a  collision detection system where it would check throughout the ball's path, etc...but I guess the best way to truly learn is finding these things out for yourself...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (15 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (38 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!