Results 1 to 8 of 8
Thread: Check The Collisions
- 06-22-2010, 04:12 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
Check The Collisions
Hello, I'm pretty new to Java, I used to use C++ and SDL before.
But anyway.
My problem is like this, I'm doing a Shmup and it all went well until, I were going to the collisions. I' using 2 CopyOnWriteArrayLists just like this:
It all went smooth creating them:Java Code:CopyOnWriteArrayList<Bullet> Bullets = new CopyOnWriteArrayList<Bullet>(); CopyOnWriteArrayList<Square> Enemies = new CopyOnWriteArrayList<Square>();
And drawing them:Java Code:Bullet Bullet = new Bullet(Player.getX() + 4, Player.getY() - 8, 8); Bullets.add(Bullet);
But now for checking collisions between those two, Bullets and Enemies I have no AJD. I can't do one of those for loops, so I got no clue.Java Code:for (Bullet bullets : Bullets) { B.setColor(Color.white); B.fillRect(bullets.getX(), bullets.getY(), bullets.getWidth(), bullets.getHeight()); }
Plz help, and comment if you need more info.
- 06-22-2010, 04:39 PM #2
What is AJD?I have no AJD
Is a collision when the boundary of one object touches/crosses the boundary of another?checking collisions
- 06-22-2010, 04:47 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
Oh, AJD = Idea - e;
I got these Rectangle things thats return a Rectangle which is called getBounds.
I've done collisions before like this:
But that isn't working here.Java Code:if (me.getBounds().intersects(you.getBounds()) {
- 06-22-2010, 05:11 PM #4
English is the preferred language here. Lots of English as a second language posters.
Can you explain?that isn't working here
How are the boundaries of the objects in question stored? The code you posted uses the fillRect() method which makes one think the objects are rectangles.
- 06-22-2010, 05:50 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
In my Two classes 'Square' n' 'Bullet' I've got these functions? Is it functions when they return something? Oh well, I uses something like this:
That isn't the problem I guess, the problem is that I don't know how to check the collision with only one of those two instances in the Bullets and Enemies.Java Code:public Rectangle getBounds() { return new Rectangle(getX(), getY(), getWidth(), getHeight()); }
- 06-22-2010, 06:24 PM #6
If you only have one instance of an object. Does mean there are no other objects and hence there can not be any collisions? Can you explain what you mean?problem is that I don't know how to check the collision with only one of those two instances
The gross way to check for collisions would be to go thru all the enemy's one by one and see it it collides with each bullet one by one.
Another way would be to only check the object(s) that moved to see if they have collided with something. No sense checking something that hasn't moved.
- 06-23-2010, 11:21 AM #7
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
Yes, but via that for loop I only can check for instances thats out of the ArrayList. Äh, I got no idea how to explain it....
- 06-23-2010, 12:30 PM #8
Similar Threads
-
how to check jsp or servlet?
By waqar100 in forum New To JavaReplies: 2Last Post: 06-04-2010, 04:39 AM -
check registry key
By anilkumar_vist in forum Advanced JavaReplies: 5Last Post: 11-22-2009, 04:52 PM -
Don't know what to check for
By Chasingxsuns in forum New To JavaReplies: 8Last Post: 08-26-2009, 05:59 AM -
pls check it
By aRTx in forum New To JavaReplies: 0Last Post: 03-24-2009, 02:35 PM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks