Item Klasse erstellt und getestet
This commit is contained in:
parent
6e8a94f37f
commit
2be51cb32e
1 changed files with 19 additions and 0 deletions
19
game.py
19
game.py
|
|
@ -8,6 +8,22 @@ PLAYER_SIZE = 20
|
||||||
LIGHT_RADIUS = 75
|
LIGHT_RADIUS = 75
|
||||||
|
|
||||||
|
|
||||||
|
class Item:
|
||||||
|
def __init__(self, x: float, y: float, width: float, height: float, color):
|
||||||
|
self.x: float = x
|
||||||
|
self.y: float = y
|
||||||
|
self.vector = pygame.Vector2(self.x, self.y)
|
||||||
|
self.width: float = width
|
||||||
|
self.height: float = height
|
||||||
|
self.color = color
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rect(self)-> pygame.Rect:
|
||||||
|
return pygame.Rect(self.x, self.y, self.width, self.height)
|
||||||
|
|
||||||
|
def render(self, surface) :
|
||||||
|
pygame.draw.rect(surface, self.color, self.rect)
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Pygame setup
|
# Pygame setup
|
||||||
|
|
@ -27,6 +43,7 @@ class Game:
|
||||||
self.item_rect = pygame.Rect(70, 150, 10, 10)
|
self.item_rect = pygame.Rect(70, 150, 10, 10)
|
||||||
self.flashlight_rect = pygame.Rect(0, 0, 0, 0)
|
self.flashlight_rect = pygame.Rect(0, 0, 0, 0)
|
||||||
self.color_item = (0, 0, 0)
|
self.color_item = (0, 0, 0)
|
||||||
|
self.test_item = Item(0 ,0, 100, 100, "green")
|
||||||
# Level
|
# Level
|
||||||
self.walls = [pygame.Rect(100, 100, 20, 50), pygame.Rect(300, 300, 200, 20), pygame.Rect(550, 80, 20, 200)]
|
self.walls = [pygame.Rect(100, 100, 20, 50), pygame.Rect(300, 300, 200, 20), pygame.Rect(550, 80, 20, 200)]
|
||||||
# Licht
|
# Licht
|
||||||
|
|
@ -82,6 +99,8 @@ class Game:
|
||||||
for wall in self.walls:
|
for wall in self.walls:
|
||||||
pygame.draw.rect(self.display, "grey", wall)
|
pygame.draw.rect(self.display, "grey", wall)
|
||||||
|
|
||||||
|
self.test_item.render(self.display)
|
||||||
|
|
||||||
self.screen.blit(pygame.transform.scale(self.display, self.screen.get_size()))
|
self.screen.blit(pygame.transform.scale(self.display, self.screen.get_size()))
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue