Here I made a code that takes an object, in this case an enemy ship, and move it to the left. I want that object to bounce to the right when he touches the left side of the screen and bounce to the left when he touches the right side of the screen.
What I get when I run the program is the enemy ship moving to the left and it stays on the left side of the panel without bouncing to the right.
graphicsMan.drawEnemyShip(enemyship, g2d, this); if(enemyship.getX() - enemyship.getSpeed() >= 0) { ship.translate(-enemyship.getSpeed(), 0); } if (gameLogic.leftBorderCollision()){ enemyship.translate(enemyship.getSpeed(), 0); } if (gameLogic.rightBorderCollision()){ enemyship.translate(-enemyship.getSpeed(),0); } In another class named GameLogic I have the collision methods defined as: public boolean rightBorderCollision(){ if(enemyship.getX() + enemyship.width >= 500){ return true; } return false; } public boolean leftBorderCollision(){ if(enemyship.getX() <= 0){ return true; } return false; }