self.display entfernt
This commit is contained in:
parent
2be51cb32e
commit
bfe8427392
1 changed files with 18 additions and 20 deletions
38
game.py
38
game.py
|
|
@ -1,11 +1,10 @@
|
|||
import pygame
|
||||
from pygame.math import Vector2
|
||||
from pygame.rect import Rect
|
||||
|
||||
SCREEN_WIDTH = 1280
|
||||
SCREEN_HEIGHT = 720
|
||||
PLAYER_SIZE = 20
|
||||
LIGHT_RADIUS = 75
|
||||
PLAYER_SIZE = 40
|
||||
LIGHT_RADIUS = 150
|
||||
|
||||
|
||||
class Item:
|
||||
|
|
@ -32,20 +31,17 @@ class Game:
|
|||
self.clock = pygame.Clock()
|
||||
# Surfaces
|
||||
self.screen: pygame.Surface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
self.display: pygame.Surface = pygame.Surface((self.screen.get_width() // 2, self.screen.get_height() // 2))
|
||||
# Pygame-Variablen
|
||||
self.running: bool = True
|
||||
self.dt: int = 0
|
||||
# Spieler
|
||||
self.player_pos = pygame.Vector2(self.display.get_width() / 2, self.display.get_height() / 2)
|
||||
self.player_pos = pygame.Vector2(self.screen.get_width() / 2, self.screen.get_height() / 2)
|
||||
self.player = Player(self, self.player_pos, width=PLAYER_SIZE, height=PLAYER_SIZE)
|
||||
# Items
|
||||
self.item_rect = pygame.Rect(70, 150, 10, 10)
|
||||
self.flashlight_rect = pygame.Rect(0, 0, 0, 0)
|
||||
self.color_item = (0, 0, 0)
|
||||
self.item_rect = pygame.Rect(70*2, 150*2, 20, 20)
|
||||
self.test_item = Item(0 ,0, 100, 100, "green")
|
||||
# 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*2, 100*2, 20*2, 50*2), pygame.Rect(300*2, 300*2, 200*2, 20*2), pygame.Rect(550*2, 80*2, 20*2, 200*2)]
|
||||
# Licht
|
||||
self.light_points: list[pygame.Vector2]
|
||||
|
||||
|
|
@ -90,18 +86,20 @@ class Game:
|
|||
|
||||
|
||||
def render(self) -> None:
|
||||
self.display.fill((0, 0, 0, 0))
|
||||
self.screen.fill((0, 0, 0, 0))
|
||||
|
||||
self.flashlight_rect: Rect = pygame.draw.polygon(self.display, (243, 255, 74), self.light_points)
|
||||
self.player.render(surface=self.display)
|
||||
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
||||
# Licht
|
||||
pygame.draw.polygon(self.screen, (243, 255, 74), self.light_points)
|
||||
# Item
|
||||
pygame.draw.rect(self.screen, "blue", self.item_rect)
|
||||
# Player
|
||||
self.player.render(surface=self.screen)
|
||||
|
||||
for wall in self.walls:
|
||||
pygame.draw.rect(self.display, "grey", wall)
|
||||
pygame.draw.rect(self.screen, "grey", wall)
|
||||
|
||||
self.test_item.render(self.display)
|
||||
self.test_item.render(self.screen)
|
||||
|
||||
self.screen.blit(pygame.transform.scale(self.display, self.screen.get_size()))
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
|
|
@ -135,8 +133,8 @@ 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
|
||||
if self.pos.x + self.width / 2 > SCREEN_WIDTH:
|
||||
self.pos.x = SCREEN_WIDTH - self.width / 2
|
||||
self.rect.centerx = round(self.pos.x)
|
||||
|
||||
for wall in walls:
|
||||
|
|
@ -151,8 +149,8 @@ class Player:
|
|||
|
||||
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
|
||||
if self.pos.y + self.height / 2 > SCREEN_HEIGHT:
|
||||
self.pos.y = SCREEN_HEIGHT - self.height / 2
|
||||
self.rect.centery = round(self.pos.y)
|
||||
|
||||
for wall in walls:
|
||||
|
|
|
|||
Loading…
Reference in a new issue