Thread: Collision

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    62
    Rep Power
    2

    Collision


    in this game i have spaceship on left side on screen that can move up, down and shoot. right side of screen there are enemy spaceships that just more right to left. goal is to shoot as many spaceship as you can.

    bc player shipship can move up and down so i need to set up collision so that player ship cant go above window screen or below.

    //this method is in main game loop

    Code:
      public void playerWCollision()
        {
            if(y < 0)
            {
                y = 0;
            }
            else if(y+height > Main.WINDOW_HEIGHT)
            {
                y = Main.WINDOW_HEIGHT-height;
            }
    }

    now if player spaceship crush into enemy spaceship than i want my player space to go down. and fall down.
    //this method is also in main game loop

    Code:
       public void hit()
        {
           //these are player positions. so if player crush into
          // enemy spaceship than add to x, y position
           //so player spaceship will go forward and down, forward and down, etc..
           x+=dx;
           y+=dx;
        }

    but the problem is that playership will stop at every bottom bc of this line:

    Code:
         else if(y+height > Main.WINDOW_HEIGHT)
                {
                    y = Main.WINDOW_HEIGHT-height;
                }
    so if player get hit there is no way it will go below the screen.
    i want it so that if player is not hit than he cant go out side of screen.(this part is done in collision method)
    but if he get hit than he should go below the screen. this way it will look like spaceship has crushed. (this part doesnt work)
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Location
    Scotland
    Posts
    6
    Rep Power
    0
    Create a boolean that is PLAYER_HIT
    Turn the boolean to true if hit() is called.
    Only run the third part of the code you show us if PLAYER_HIT == false.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    62
    Rep Power
    2
    Originally Posted by jslvtr
    Create a boolean that is PLAYER_HIT
    Turn the boolean to true if hit() is called.
    Only run the third part of the code you show us if PLAYER_HIT == false.

    yea, i was thinking the same think. i though maybe there is different way to do this. but o well, thanks.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Location
    Scotland
    Posts
    6
    Rep Power
    0
    Nae bother

IMN logo majestic logo threadwatch logo seochat tools logo