Skip to content

Commit

Permalink
hotfix: apple cant spawn in the snake
Browse files Browse the repository at this point in the history
  • Loading branch information
0riginaln0 committed Apr 3, 2024
1 parent e00d949 commit 8b942b6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func playing() {
if snake.Body[0] == fruit {
score += 1
snake.Body = append(snake.Body, snake.Body[len(snake.Body)-1])
fruit.X = rnd(20)
fruit.Y = rnd(20)

generateNewApple()

switch score {
case 20:
speed = 12
Expand All @@ -149,3 +150,20 @@ func playing() {
*w4.DRAW_COLORS = 0x4321
w4.Blit(&fruitSprite[0], fruit.X*8, fruit.Y*8, 8, 8, w4.BLIT_2BPP)
}

func generateNewApple() {
foundNewPlace := false
p := Point{}
for !foundNewPlace {
foundNewPlace = true
p.X = rnd(20)
p.Y = rnd(20)
for _, body_part := range snake.Body {
if body_part == p {
foundNewPlace = false
break
}
}
}
fruit = p
}

0 comments on commit 8b942b6

Please sign in to comment.