Fix bug with fruits spawning on top of snake

This commit is contained in:
Juhani Krekelä 2023-01-15 00:37:02 +02:00
parent 9b6df7216f
commit 9f59571d48
1 changed files with 7 additions and 3 deletions

View File

@ -153,12 +153,16 @@ spawn_fruit:
ld i, single_pixel
drw fruit_x_reg, fruit_y_reg, 1
; Did we spawn over the snake?
se vf, 0
jp spawn_fruit
; Did we spawn succesfully?
sne vf, 0
ret
; No, we spawned over the snake. Erase and try again
ld i, single_pixel
drw fruit_x_reg, fruit_y_reg, 1
jp spawn_fruit
turn_up:
; Don't allow 180° turns (which would kill the snake instantly)
se v1, direction_down