Compare commits
5 commits
d7f2b54f3b
...
c8494dcab1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8494dcab1 | ||
|
|
3bc545d3c0 | ||
|
|
02622ce4b8 | ||
|
|
64cb1fa862 | ||
|
|
d80e8391cb |
4 changed files with 40 additions and 33 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 824 B After Width: | Height: | Size: 1.1 KiB |
21
game.py
21
game.py
|
|
@ -25,29 +25,30 @@ 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,
|
||||||
items=[],
|
items=[],
|
||||||
walls=[
|
walls=[
|
||||||
Wall(self, 0, 0, SCREEN_WIDTH, TILE_SIZE),
|
Wall(self, 0, 0, SCREEN_WIDTH//TILE_SIZE, 1),
|
||||||
Wall(self, 0, TILE_SIZE, TILE_SIZE, SCREEN_HEIGHT),
|
Wall(self, 0, TILE_SIZE, 1, SCREEN_HEIGHT//TILE_SIZE),
|
||||||
Wall(
|
Wall(
|
||||||
self, TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH, TILE_SIZE
|
self, TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH//TILE_SIZE, 1
|
||||||
),
|
),
|
||||||
Wall(self, SCREEN_WIDTH - TILE_SIZE, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
|
Wall(self, SCREEN_WIDTH - TILE_SIZE, 0, 1, SCREEN_HEIGHT//TILE_SIZE),
|
||||||
Wall(self, 500, 500, 128, 128)
|
Wall(self, 500, 500, 2, 2)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -125,6 +126,6 @@ game.run()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Fertigen Raum machen.
|
Wie funktioniert Kollision mit Bildern?????????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
Immer alles strukturieren
|
(Günter hat ein Tutorial)
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -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()),
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,35 +4,32 @@ from scripts.constants import *
|
||||||
|
|
||||||
|
|
||||||
class Wall:
|
class Wall:
|
||||||
def __init__(self, game, x: float, y: float, width: float, height: float):
|
def __init__(self, game, x: float, y: float, cols: int, rows: int):
|
||||||
self.game = game
|
self.game = game
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.width = width
|
self.cols = cols
|
||||||
self.height = height
|
self.rows = rows
|
||||||
self.rect = pygame.Rect(x, y, width, height)
|
self.rect = pygame.Rect(x, y, cols*TILE_SIZE, rows*TILE_SIZE)
|
||||||
|
self.drawed_rect = None
|
||||||
|
self.grid: list[list[pygame.Rect]] = []
|
||||||
|
|
||||||
for i in range(self.width):
|
|
||||||
if i % 64 == 0:
|
|
||||||
end_ergebnis_width = i
|
|
||||||
|
|
||||||
for i in range(self.height):
|
for row in range(self.rows): # rows
|
||||||
if i % 64 == 0:
|
current_row = []
|
||||||
end_ergebnis_height = i
|
for col in range(self.cols): # cols
|
||||||
|
current_row.append(pygame.Rect(self.x+col*TILE_SIZE, self.y+row*TILE_SIZE, col*TILE_SIZE, row*TILE_SIZE))
|
||||||
|
|
||||||
self.length: dict = {
|
self.grid.append(current_row)
|
||||||
"width": end_ergebnis_width+TILE_SIZE,
|
|
||||||
"height": end_ergebnis_height+TILE_SIZE,
|
|
||||||
}
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def render(self, surface: pygame.Surface):
|
def render(self, surface: pygame.Surface):
|
||||||
for x in range(self.length["width"]):
|
for row in self.grid:
|
||||||
for y in range(self.length["height"]):
|
for wall_rect in row:
|
||||||
if y % TILE_SIZE == 0 and x % TILE_SIZE == 0:
|
surface.blit(self.game.assets["wall"], wall_rect)
|
||||||
surface.blit(self.game.assets["wall"], pygame.Rect(self.x+x, self.y+y, self.width, self.height))
|
|
||||||
|
|
||||||
def get_rect(self) -> pygame.Rect:
|
def get_rect(self) -> pygame.Rect:
|
||||||
return self.rect
|
return self.rect
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue