note player is a space ship.
in player class i have set up collision so that player cant go above window and below.

player class

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

lets say player got hit so i want my player to fall down. by adding to x, y postion it will look like player is gong down.

public void hit()
{
   x+=dx;
   y+=dx;

}

problem is that i want player to keep going down. this doesnt happen bc of collision function above. is there way i can keep my collision function and some thing in hit methods? that my player will keep going down.

Do you mean keep going down untill it's completely off the screen?

I don't understand your hit method how often will that be executed?

are you talking something similar to snake game???
In that you need one more variable to knw the direction,on collision change the direction variable.Depending on the value of that variable either increment,decrement value of x and similarly for y.
Edit:- don't call playerWCollision() if hit() returns collision by changing direction value.

sorry, let me explain more.
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

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

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:

 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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.