import time at top
import time
use time.sleep(.3)
at the bottom of the Game
while running loop
. Place a self.snake.walk()
right before sleep()
, Then Create the snake.walk()
self.snake.walk()
time.sleep(.3)
Make sure
self.snake.walk() and time.sleep(.3) are indented inside for event in ..
Assign a blank value for self.direction
inside __init__
for Snake
self.direction = 'down'
Move block movement logic inside walk()
def walk(self): if self.direction == 'down': self.y += 10 if self.direction == 'up': self.y += 10 if self.direction == 'left': self.x -= 10 if self.direction == 'right': self.x += 10 self.draw()
and inside
the move_
methods, change the self.direction
def move_down(self): self.direction = 'down' def move_up(self): self.direction = 'up' def move_left(self): self.direction = 'left' def move_right(self): self.direction = 'right'
This code now allows for constant movement when key is pressed
and inside
the move_
methods, change the self.direction
def move_down(self): self.direction = 'down' def move_up(self): self.direction = 'up' def move_left(self): self.direction = 'left' def move_right(self): self.direction = 'right'