Add prey.
This commit is contained in:
parent
d19c45abbc
commit
5d33259119
@ -4,6 +4,7 @@ from input_manager import InputManager
|
|||||||
from snake import Snake
|
from snake import Snake
|
||||||
from game_object import GameObject
|
from game_object import GameObject
|
||||||
from wall import Wall
|
from wall import Wall
|
||||||
|
from prey import Prey
|
||||||
|
|
||||||
|
|
||||||
def draw_all(window: Window, game_objs: list[GameObject]) -> None:
|
def draw_all(window: Window, game_objs: list[GameObject]) -> None:
|
||||||
@ -18,14 +19,17 @@ def update_all(game_objs: list[GameObject], user_input: int) -> None:
|
|||||||
obj.update(user_input, game_objs)
|
obj.update(user_input, game_objs)
|
||||||
|
|
||||||
|
|
||||||
def create_game_objects(window):
|
def create_game_objects(window: Window):
|
||||||
return [Snake(start_position=(400, 300),
|
return [Snake(start_position=(400, 300),
|
||||||
length=5,
|
length=5,
|
||||||
radius=10,
|
radius=10,
|
||||||
color=(255, 0, 255)),
|
color=(255, 0, 255)),
|
||||||
Wall(window_size=window.get_size(),
|
Wall(window_size=window.get_size(),
|
||||||
width=5,
|
width=5,
|
||||||
color=(255, 0, 0))]
|
color=(255, 0, 0)),
|
||||||
|
Prey(size=10,
|
||||||
|
color=(255, 255, 0),
|
||||||
|
window_size=window.get_size())]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
21
snake/prey.py
Normal file
21
snake/prey.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
from game_object import GameObject
|
||||||
|
|
||||||
|
|
||||||
|
class Prey(GameObject):
|
||||||
|
def __init__(self, size: int, color: tuple, window_size: tuple):
|
||||||
|
self.__bounding_box = pygame.rect.Rect(0, 0, size, size)
|
||||||
|
self.__color = color
|
||||||
|
self.__window_size = window_size
|
||||||
|
self.__place_randomly()
|
||||||
|
|
||||||
|
def __place_randomly(self) -> None:
|
||||||
|
self.__bounding_box.center = [random.randint(0, max_val)
|
||||||
|
for max_val in self.__window_size]
|
||||||
|
|
||||||
|
|
||||||
|
def draw(self, surface: pygame.surface.Surface) -> None:
|
||||||
|
pygame.draw.rect(surface, color=self.__color, rect=self.__bounding_box)
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user