5 Minuten Pause vpm 19.09.2026
This commit is contained in:
parent
6c535d3073
commit
f71dae0af4
1 changed files with 23 additions and 25 deletions
48
game.py
48
game.py
|
|
@ -136,7 +136,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
def calculate_collsions(self) -> None:
|
def calculate_collsions(self) -> None:
|
||||||
if self.item_rect.colliderect(self.flashlight_rect):
|
if self.item_rect.colliderect(self.flashlight_rect):
|
||||||
|
|
@ -151,17 +151,15 @@ class Player:
|
||||||
self.game = game
|
self.game = game
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
|
|
||||||
self.player_width = width
|
self.width = width
|
||||||
self.player_height = height
|
self.height = height
|
||||||
|
|
||||||
self.speed = 150
|
self.speed = 150
|
||||||
|
|
||||||
self.rect = pygame.Rect(self.pos[0]-self.player_width/2, self.pos[1]-self.player_height/2, width, height)
|
self.rect = pygame.Rect(self.pos[0]-self.width/2, self.pos[1]-self.height/2, width, height)
|
||||||
|
|
||||||
def update(self, walls, dt):
|
def update(self, walls, dt):
|
||||||
|
|
||||||
self.player_rect = pygame.Rect(self.pos[0]-10, self.pos[1]-10, self.player_width, self.player_height)
|
|
||||||
|
|
||||||
|
|
||||||
# Smooth Movement
|
# Smooth Movement
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
@ -184,50 +182,50 @@ class Player:
|
||||||
|
|
||||||
|
|
||||||
# player_rect.center = round(player_pos)
|
# player_rect.center = round(player_pos)
|
||||||
self.player_rect.centerx = round(self.pos.x)
|
self.rect.centerx = round(self.pos.x)
|
||||||
|
|
||||||
for wall in walls:
|
for wall in walls:
|
||||||
if self.player_rect.colliderect(wall):
|
if self.rect.colliderect(wall):
|
||||||
if movement.x > 0:
|
if movement.x > 0:
|
||||||
self.player_rect.right = wall.left
|
self.rect.right = wall.left
|
||||||
|
|
||||||
elif movement.x < 0:
|
elif movement.x < 0:
|
||||||
self.player_rect.left = wall.right
|
self.rect.left = wall.right
|
||||||
|
|
||||||
self.pos.x = self.player_rect.centerx
|
self.pos.x = self.rect.centerx
|
||||||
|
|
||||||
# if self.pos.x < self.player_rect.width/2 or self.pos.x + self.player_rect.width > SCREEN_WIDTH:
|
# if self.pos.x < self.player_rect.width/2 or self.pos.x + self.player_rect.width > SCREEN_WIDTH:
|
||||||
# self.pos.x = old_position_x
|
# self.pos.x = old_position_x
|
||||||
if self.pos.x - self.player_rect.width/2 < 0:
|
if self.pos.x - self.rect.width/2 < 0:
|
||||||
self.pos.x = self.player_rect.width/2
|
self.pos.x = self.rect.width/2
|
||||||
|
|
||||||
if self.pos.x + self.player_rect.width/2 > SCREEN_WIDTH:
|
if self.pos.x + self.width/2 > SCREEN_WIDTH/2:
|
||||||
self.pos.x = SCREEN_WIDTH - self.player_rect.width/2
|
self.pos.x = SCREEN_WIDTH/2 - self.width/2
|
||||||
|
|
||||||
self.pos.y += movement.y
|
self.pos.y += movement.y
|
||||||
|
|
||||||
self.player_rect.centery = round(self.pos.y)
|
self.rect.centery = round(self.pos.y)
|
||||||
|
|
||||||
for wall in walls:
|
for wall in walls:
|
||||||
if self.player_rect.colliderect(wall):
|
if self.rect.colliderect(wall):
|
||||||
if movement.y > 0:
|
if movement.y > 0:
|
||||||
self.player_rect.bottom = wall.top
|
self.rect.bottom = wall.top
|
||||||
|
|
||||||
elif movement.y < 0:
|
elif movement.y < 0:
|
||||||
self.player_rect.top = wall.bottom
|
self.rect.top = wall.bottom
|
||||||
|
|
||||||
self.pos.y = self.player_rect.centery
|
self.pos.y = self.rect.centery
|
||||||
|
|
||||||
if self.pos.y - self.player_rect.height/2 < 0:
|
if self.pos.y - self.rect.height/2 < 0:
|
||||||
self.pos.y = self.player_rect.height/2
|
self.pos.y = self.rect.height/2
|
||||||
|
|
||||||
if self.pos.y + self.player_rect.height/2 > SCREEN_HEIGHT:
|
if self.pos.y + self.rect.height/2 > SCREEN_HEIGHT/2:
|
||||||
self.pos.y = SCREEN_HEIGHT - self.player_rect.height/2
|
self.pos.y = SCREEN_HEIGHT/2 - self.rect.height/2
|
||||||
|
|
||||||
|
|
||||||
def render(self, surface):
|
def render(self, surface):
|
||||||
|
|
||||||
pygame.draw.rect(surface, (255, 0, 0), self.player_rect)
|
pygame.draw.rect(surface, (255, 0, 0), self.rect)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue