Player als Player eingefügt
This commit is contained in:
parent
02622ce4b8
commit
3bc545d3c0
3 changed files with 16 additions and 6 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 824 B After Width: | Height: | Size: 1.1 KiB |
7
game.py
7
game.py
|
|
@ -25,17 +25,18 @@ class Game:
|
||||||
self.player_pos = pygame.Vector2(
|
self.player_pos = pygame.Vector2(
|
||||||
self.screen.get_width() / 2, self.screen.get_height() / 2
|
self.screen.get_width() / 2, self.screen.get_height() / 2
|
||||||
)
|
)
|
||||||
self.player = Player(self.player_pos, width=PLAYER_SIZE, height=PLAYER_SIZE)
|
|
||||||
|
|
||||||
# Flashlight
|
|
||||||
self.flashlight_player = Flashlight(self, self.player)
|
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
self.assets = {
|
self.assets = {
|
||||||
"floor_01": load_image("level/ground/floor_1.png"),
|
"floor_01": load_image("level/ground/floor_1.png"),
|
||||||
"plant_01": load_image("items/furniture/plants/plant.png"),
|
"plant_01": load_image("items/furniture/plants/plant.png"),
|
||||||
"wall": load_image("level/walls/wall_0.png"),
|
"wall": load_image("level/walls/wall_0.png"),
|
||||||
|
|
||||||
|
"player": load_image("entity/player/player.png"),
|
||||||
}
|
}
|
||||||
|
self.player = Player(self.player_pos, width=PLAYER_SIZE, height=PLAYER_SIZE, image=self.assets["player"])
|
||||||
|
self.flashlight_player = Flashlight(self, self.player)
|
||||||
|
|
||||||
self.level = Level(
|
self.level = Level(
|
||||||
game=self,
|
game=self,
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,17 @@ from scripts.constants import *
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, pos: pygame.Vector2, width, height):
|
def __init__(self, pos: pygame.Vector2, width, height, image=None):
|
||||||
self.pos: Vector2 = pos
|
self.pos: Vector2 = pos
|
||||||
self.width: float = width
|
self.width: float = width
|
||||||
self.height: float = height
|
self.height: float = height
|
||||||
self.speed = 150
|
self.speed = 150
|
||||||
|
self.image = image
|
||||||
self.rect = pygame.Rect(
|
self.rect = pygame.Rect(
|
||||||
self.pos[0] - self.width / 2, self.pos[1] - self.height / 2, width, height
|
self.pos[0] - self.width / 2, self.pos[1] - self.height / 2, width, height
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def update(self, walls, dt):
|
def update(self, walls, dt):
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
direction = pygame.Vector2(
|
direction = pygame.Vector2(
|
||||||
|
|
@ -59,5 +61,12 @@ class Player:
|
||||||
self.rect.top = wall.bottom
|
self.rect.top = wall.bottom
|
||||||
self.pos.y = self.rect.centery
|
self.pos.y = self.rect.centery
|
||||||
|
|
||||||
def render(self, surface):
|
|
||||||
pygame.draw.rect(surface, (255, 0, 0), self.rect)
|
def render(self, surface: pygame.Surface):
|
||||||
|
if not self.image:
|
||||||
|
pygame.draw.rect(surface, self.color, self.rect)
|
||||||
|
else:
|
||||||
|
surface.blit(
|
||||||
|
self.image,
|
||||||
|
(self.pos[0]-TILE_SIZE/2, self.pos[1]-TILE_SIZE/2-10, self.image.get_width(), self.image.get_height()),
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue