Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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. [http://styrman.madtracker.net/Diamonds3.rar]

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]
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!