diff --git a/snake/main.py b/snake/main.py index d2a5c9f..6395d01 100644 --- a/snake/main.py +++ b/snake/main.py @@ -3,6 +3,8 @@ from window import Window from input_manager import InputManager from snake import Snake from game_object import GameObject +from wall import Wall + def draw_all(window: Window, game_objs: list[GameObject]) -> None: window.reset() @@ -16,13 +18,20 @@ def update_all(game_objs: list[GameObject], user_input: int) -> None: obj.update(user_input) +def create_game_objects(window): + return [Snake(start_position=(400, 300), + length=5, + radius=10, + color=(255, 0, 255)), + Wall(window_size=window.get_size(), + width=5, + color=(255, 0, 0))] + + 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), - length=5, - radius=10, - color=(255, 0, 255))] + game_objs = create_game_objects(window) clock = pygame.time.Clock() framerate = 25 diff --git a/snake/wall.py b/snake/wall.py new file mode 100644 index 0000000..9424e76 --- /dev/null +++ b/snake/wall.py @@ -0,0 +1,21 @@ +import pygame + +from game_object import GameObject + + +class Wall(GameObject): + def __init__(self, window_size, width, color): + top_wall = pygame.rect.Rect(0, 0, window_size[0], width) + left_wall = pygame.rect.Rect(0, 0, width, window_size[1]) + bottom_wall = pygame.rect.Rect(0, window_size[1]-width, window_size[0], width) + right_wall = pygame.rect.Rect(window_size[0]-width, 0, width, window_size[1]) + + self.__walls = [top_wall, left_wall, bottom_wall, right_wall] + + self.__color = color + + + def draw(self, surface): + for wall in self.__walls: + pygame.draw.rect(surface, self.__color, wall) + \ No newline at end of file diff --git a/snake/window.py b/snake/window.py index 3852705..1cfa8bf 100644 --- a/snake/window.py +++ b/snake/window.py @@ -16,4 +16,8 @@ class Window: def draw_object(self, game_object: GameObject) -> None: game_object.draw(self.__surface) + + + def get_size(self): + return self.__surface.get_size() \ No newline at end of file