Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Java game collision detection need help!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: Java game collision detection need help!

    Do you have an int named lives? If so just find out if the cannon intersects then lives--;. Not sure if that helps, the full code would help.

Similar Threads

  1. Collision detection
    By mwr1976 in forum Java 2D
    Replies: 2
    Last Post: 04-14-2012, 12:45 PM
  2. Collision Detection?
    By Alerhau in forum New To Java
    Replies: 39
    Last Post: 09-07-2011, 04:55 PM
  3. Collision Detection for Billiards game
    By prashant in forum Java Gaming
    Replies: 3
    Last Post: 06-02-2011, 04:45 AM
  4. Collision Detection
    By dotabyss in forum Java Gaming
    Replies: 0
    Last Post: 03-14-2010, 06:13 PM
  5. Collision Detection (Game)
    By mscwd in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-28-2008, 08:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •