Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions 1_snake_game/3_moving_block_and_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
from pygame.locals import *
import time


class Snake:
def __init__(self, surface):
self.parent_screen = surface
self.block = pygame.image.load("resources/block.jpg").convert()
self.x = 100
self.y = 100
self.direction = 'down'
self.direction = "down"

def move_left(self):
self.direction = 'left'
self.direction = "left"

def move_right(self):
self.direction = 'right'
self.direction = "right"

def move_up(self):
self.direction = 'up'
self.direction = "up"

def move_down(self):
self.direction = 'down'
self.direction = "down"

def walk(self):
if self.direction == 'left':
if self.direction == "left":
self.x -= 10
if self.direction == 'right':
if self.direction == "right":
self.x += 10
if self.direction == 'up':
if self.direction == "up":
self.y -= 10
if self.direction == 'down':
if self.direction == "down":
self.y += 10

self.draw()


def draw(self):
self.parent_screen.fill((110, 110, 5))

Expand Down Expand Up @@ -77,10 +77,9 @@ def run(self):

self.snake.walk()

time.sleep(.2)
time.sleep(0.2)


if __name__ == '__main__':
if __name__ == "__main__":
game = Game()
game.run()