/** Checks if the player collides with a blip, power blip, or a ghost. */ public void checkCollision() { Rectangle playerRect = new Rectangle(player.getCenter().x - 8, player.getCenter().y - 8, 13, 13); for (Enemy enemy : enemies) { Rectangle enemyRect = new Rectangle(enemy.getCenter().x - 8, enemy.getCenter().y - 8, 13, 13); if (playerRect.intersects(enemyRect)) { if (!enemy.isAlive()) { continue; } if (Globals.state == ENEMY_HUNTER_STATE) { Globals.game.playerKilled(); player.loseALife(); // player is dead, so we paint the dead player screen paintDeadPlayer(); try { // sleep to make it stay on screen Thread.sleep(1500); } catch (InterruptedException e) { // DO nothing } resetCanvas(); // we return because only one enemy should be able to make a player lose a life return; } else if (Globals.state == ENEMY_HUNTED_STATE) { if (enemy.isAlive()) { enemy.setAlive(false); player.addPoints(POINTS_FOR_KILLING_ENEMY); } } } else { continue; } } }