Results 1 to 3 of 3
- 01-18-2013, 01:47 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 1
- Rep Power
- 0
Java game collision detection need help!
I am a first time programmer and i have to make a game in java for a unit at college and i am really struggling with something, my game is about a cannon that shoots cannon balls at the control of the player to try and hit and pop balloons that are by the top of the page, whilst trying to avoid hitting bombs that move from left to right randomly between the cannon and the balloons, each time a player hits a balloon it disappears but each time they hit a bomb they lose a life. I managed to get a code to make the balloons hit disappear and it works but I'm struggling with the part where i make a player lose a life each time they hit a bomb part. i have tried a code for it and it says there are no errors but it doesn't do what it is supposed to do it just does nothing when the ball hits a bomb so i was wondering if there was anyone that could help me out with this problem. Here is the code for the balloon collision and the one that i tried for removing lives, they are all in the ball class
public void act()
{
move(20.0);
hasCollided();
}
public void hasCollided()
{
Actor RedBalloon = getOneObjectAtOffset(0, 0, RedBalloon.class);
Actor Bomb = getOneObjectAtOffset(0, 0, Bomb.class);
Actor Lives = getOneObjectAtOffset(0, 0, Lives.class);
{
if(RedBalloon != null) {
Game world = (Game) getWorld();
world.removeObject(RedBalloon);
if(Bomb != null) {
getWorld();
world.removeObject(Lives);
}
}
}
}
}
Let me know if you need any more information
- 01-18-2013, 02:04 PM #2
Re: Java game collision detection need help!
Why do they call it rush hour when nothing moves? - Robin Williams
- 01-18-2013, 04:16 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Similar Threads
-
Collision detection
By mwr1976 in forum Java 2DReplies: 2Last Post: 04-14-2012, 12:45 PM -
Collision Detection?
By Alerhau in forum New To JavaReplies: 39Last Post: 09-07-2011, 04:55 PM -
Collision Detection for Billiards game
By prashant in forum Java GamingReplies: 3Last Post: 06-02-2011, 04:45 AM -
Collision Detection
By dotabyss in forum Java GamingReplies: 0Last Post: 03-14-2010, 06:13 PM -
Collision Detection (Game)
By mscwd in forum Sun Java Wireless ToolkitReplies: 0Last Post: 01-28-2008, 08:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks