Skip to content

Commit

Permalink
[fix]: Disable firing venom when snake is within 3 cells of top or le…
Browse files Browse the repository at this point in the history
…ft margin
  • Loading branch information
chriskerrc committed Apr 15, 2024
1 parent 315815e commit 1f69f1e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/snakeGame/GameScreen.pde
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public class GameScreen {
} else if (keyCode == KeyEvent.VK_SPACE && snakeVenom > 0) {
// Instantiate a Venom using the snake's current velocity and position
PVector snakePosition = snake.getSnakeCells().getLast().gridLocation.copy();
//if snake's position is too close to top or left border, don't create venom (otherwise whole game freezes)
if(snakePosition.x <= 3 || snakePosition.y <= 3){
return;
}
PVector snakeVelocity = snake.getVelocity().copy();
int venomColour = color(200, 0, 200); // Set venom color (e.g., red)
venom.add(new Venom(this, venomColour, snakePosition.add(snakeVelocity).add(snakeVelocity), snakeVelocity, snake));
Expand Down

0 comments on commit 1f69f1e

Please sign in to comment.