Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Just another collision thread (And some other questions) on: 2007-09-22 15:18:06
It will be pretty much like arcanoid. But no paddle and more puzzle =)

I'll check that out =)
2  Game Development / Newbie & Debugging Questions / Just another collision thread (And some other questions) on: 2007-09-21 17:41:35
I want to start of by saying; sorry for making another collision thread. This is not only about collision though.
I've read through the forum and checked alot of other resources I just can't figure out how to do this and I need some help with my specific code. I'm new to Java and I still have some problems adapting others code to my own.

Anyways. I'm doing a modified bricks game, a little more advanced and a little diffrent. What i have is a ball (Ellipse2D.Double) and a unspecified level of blocks(Rectangle2D.Double) (diffrent kinds and diffrent amounts for each level).

(this part is not done yet, it only exists in my head Tongue)
What I thought of doing is a createLevel class that reads a specific levels layout from a csv or xml file, don't really know how to do that yet. The game panel should be tiled in a grid with tiles the same size as a block (all blocks have the same size). The level file would include a list of each tile and what kind of block (if any) should be present at that specific tile. The createLevel class then renders a level using the level file. I don't really know how to handle empty tiles. Should I place a special kind of invisible block with no collision or none at all?

First off, does that sound like a good idea for handeling diffrent levels?

createLevel would also store all blocks in an array (top left to bottom right tiles I guess). This would be for the collision since I need to check what kind of block the ball hits and in what tile it is.

Then, every time the ball moves I need to check if it hits something. I already made it collide with boundries of the game panel.
My "main question" is: how to do this?

I've tried 3 diffrent approaches. All with little or no luck.

   1. First I tried converting the ball and blocks to Areas and to a simple isEmpty() check on the ball to see if it was overlapping any block. This did how ever not even compile. I must've messed something up. Tried doing it exactly as I found it in another thread here on the forums. No success.
   2. Then I tried getting the x, y and dimensions for each block and checking if they overlapped by using Ellipse2D.intersects. This kinda worked. I got it to respond to colliding with the block (I only draw one just to test it). However the ball did get stuck on the block.. Couldn't get it to bounce of. This was my most successful try. I would think this is the most correct and exact way to do it. Am I right?
   3. Then I tried using the balls x and y coordinates to do a number of checks: first was the ball under the block (ball x > block x and ball x < block x + block width) and then check if the ball was aligned with any of the blocks y coordinates. I think that this failed due to my ball not moving one pixel at a time and therefore skipping the if-statement checking for y coordinates. Could probably be refined to work but would also probably be very ineffecient. So screw number 3.

Since I have 7 classes I'll post a link to a zip with all files in it. It's pretty well commented I think. Maybe not.. at least a little. []

Any tips will be most welcome =)
Thanks for reading my long thread.. ^^

EDIT: Forgot to mention. in the collision method I need to be able to decide from what direction the bal hits the block. if the ball hits top or bottom, just change direction (bounce), if the ball hits sides keep going up/down but bounce the ball a little to the side, if ball hits the corner of a block send it back the same way it came.
Pages: [1]
EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (160 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!