code-check-jay #1
1 changed files with 0 additions and 43 deletions
43
game.py
43
game.py
|
|
@ -35,26 +35,20 @@ class Game:
|
|||
|
||||
self.update()
|
||||
self.calculate_collsions()
|
||||
|
||||
self.render()
|
||||
|
||||
self.screen.blit(pygame.transform.scale(self.display, self.screen.get_size()))
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
def update(self) -> None:
|
||||
# Event-Keys
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
self.running = False
|
||||
|
||||
if event.key == pygame.K_LSHIFT:
|
||||
self.player.speed = 300
|
||||
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_LSHIFT:
|
||||
self.player.speed = 150
|
||||
|
||||
|
|
@ -77,19 +71,14 @@ class Game:
|
|||
# Überschneidung mit den Wänden prüfen
|
||||
for wall in self.walls:
|
||||
überschneidung = wall.clipline(self.player_pos, ray_end)
|
||||
|
||||
if überschneidung:
|
||||
schnittpunkt = pygame.Vector2(überschneidung[0])
|
||||
|
||||
ray_end = schnittpunkt
|
||||
|
||||
self.light_points.append(ray_end)
|
||||
|
||||
self.flashlight_rect = pygame.draw.polygon(self.display, (243, 255, 74), self.light_points)
|
||||
pygame.draw.rect(self.display, (255, 0, 0), self.flashlight_rect, 1)
|
||||
|
||||
self.player.render(surface=self.display)
|
||||
|
||||
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
||||
|
||||
for wall in self.walls:
|
||||
|
|
@ -124,19 +113,15 @@ class Player:
|
|||
def __init__(self, game, pos: pygame.Vector2, width, height):
|
||||
self.game = game
|
||||
self.pos = pos
|
||||
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
self.speed = 150
|
||||
|
||||
self.rect = pygame.Rect(self.pos[0] - self.width / 2, self.pos[1] - self.height / 2, width, height)
|
||||
|
||||
def update(self, walls, dt):
|
||||
|
||||
# Smooth Movement
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
direction = pygame.Vector2(keys[pygame.K_d] - keys[pygame.K_a], keys[pygame.K_s] - keys[pygame.K_w])
|
||||
|
||||
if direction.length_squared() > 0:
|
||||
|
|
@ -148,65 +133,37 @@ class Player:
|
|||
|
||||
if self.pos.x - self.width / 2 < 0:
|
||||
self.pos.x = self.width / 2
|
||||
|
||||
if self.pos.x + self.width / 2 > SCREEN_WIDTH / 2:
|
||||
self.pos.x = SCREEN_WIDTH / 2 - self.width / 2
|
||||
# self.pos += movement
|
||||
|
||||
# player_rect.center = round(player_pos)
|
||||
self.rect.centerx = round(self.pos.x)
|
||||
|
||||
for wall in walls:
|
||||
if self.rect.colliderect(wall):
|
||||
if movement.x > 0:
|
||||
self.rect.right = wall.left
|
||||
|
||||
elif movement.x < 0:
|
||||
self.rect.left = wall.right
|
||||
|
||||
self.pos.x = self.rect.centerx
|
||||
|
||||
self.pos.y += movement.y
|
||||
|
||||
if self.pos.y - self.height / 2 < 0:
|
||||
self.pos.y = self.height / 2
|
||||
|
||||
if self.pos.y + self.height / 2 > SCREEN_HEIGHT / 2:
|
||||
self.pos.y = SCREEN_HEIGHT / 2 - self.height / 2
|
||||
|
||||
self.rect.centery = round(self.pos.y)
|
||||
|
||||
for wall in walls:
|
||||
if self.rect.colliderect(wall):
|
||||
if movement.y > 0:
|
||||
self.rect.bottom = wall.top
|
||||
|
||||
elif movement.y < 0:
|
||||
self.rect.top = wall.bottom
|
||||
|
||||
self.pos.y = self.rect.centery
|
||||
|
||||
def render(self, surface):
|
||||
|
||||
pygame.draw.rect(surface, (255, 0, 0), self.rect)
|
||||
|
||||
|
||||
game = Game()
|
||||
game.run()
|
||||
|
||||
|
||||
"""
|
||||
------------------------------------- HAUSAUFGABE -------------------------------------
|
||||
|
||||
------------------------------------- MACHE, DASS -------------------------------------
|
||||
|
||||
------------------------------------- DU NICHT W- -------------------------------------
|
||||
|
||||
------------------------------------- EITERLÄUFST -------------------------------------
|
||||
|
||||
------------------------------------- WENN DU AUS -------------------------------------
|
||||
|
||||
------------------------------------- DEM SCREEN -------------------------------------
|
||||
|
||||
------------------------------------- GEHST. -------------------------------------
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue