Add first version of snake.
This commit is contained in:
parent
dc9ff0582f
commit
01e4afd552
3
snake/game_object.py
Normal file
3
snake/game_object.py
Normal file
@ -0,0 +1,3 @@
|
||||
class GameObject:
|
||||
def draw(self, surface):
|
||||
pass
|
||||
@ -1,11 +1,21 @@
|
||||
import pygame
|
||||
from window import Window
|
||||
from input_manager import InputManager
|
||||
from snake import Snake
|
||||
|
||||
def draw(window, game_objs):
|
||||
window.reset()
|
||||
|
||||
for obj in game_objs:
|
||||
window.draw_object(obj)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
window = Window(title='Snake', size=(800, 600), background_color=(0, 128, 0))
|
||||
input_manager = InputManager()
|
||||
game_objs = [Snake(start_position=(400, 300),
|
||||
radius=10,
|
||||
color=(255, 0, 255))]
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
framerate = 25
|
||||
@ -15,7 +25,7 @@ if __name__ == '__main__':
|
||||
while last_input != InputManager.QUIT:
|
||||
last_input = input_manager.process_input()
|
||||
|
||||
window.reset()
|
||||
draw(window, game_objs)
|
||||
|
||||
clock.tick(framerate)
|
||||
pygame.display.flip()
|
||||
|
||||
15
snake/snake.py
Normal file
15
snake/snake.py
Normal file
@ -0,0 +1,15 @@
|
||||
import pygame
|
||||
from game_object import GameObject
|
||||
|
||||
|
||||
class Snake(GameObject):
|
||||
def __init__(self, start_position, radius, color):
|
||||
self.__pos = start_position
|
||||
self.__radius = radius
|
||||
self.__color = color
|
||||
|
||||
def draw(self, surface):
|
||||
pygame.draw.circle(surface=surface,
|
||||
color=self.__color,
|
||||
center=self.__pos,
|
||||
radius=self.__radius)
|
||||
Loading…
x
Reference in New Issue
Block a user