Ok so I've just started learning java (I usually program in Objective-C). My first game is a game similar to Pokémon, however, its a lot more simplified obviously...
The trouble I'm having is I can't find a way to stop 2 sprites from 'ghosting' through each other. On screen I have borders set up (boundaries), A player sprite, and an Enemy sprite.
public void playerUpdate(GameContainer gc, int delta) throws SlickException
{
Input input = gc.getInput();
// Right Key Pressed
if (input.isKeyDown(Input.KEY_RIGHT) && (leftKeyPressed == false)
&& (upKeyPressed == false) && (downKeyPressed == false))
{
player = walkRight;
playerX += speed * delta;
rightKeyPressed = true;
if (playerX >= Main.getWindowWidth() - pImageWidth)
{
playerX -= speed * delta;
}
} else if (rightKeyPressed == true)
{
player = standRight;
rightKeyPressed = false;
}
^^ this is where I need to implement the collision detection. I have added rectangles to each image for collision detection, however, I'm not after a way to make one disappear. I need a way to stop one sprite from walking through another.
Any ideas?
I have tried using
if (this.playerBoundingBox.intersects(Enemy.getEnemyBoundingBox())
{
playerX += speed * delta;
}
However, when i implement this the player gets stuck and can not be freed.
Thanks guys