Stand Ende 17.04.2026
This commit is contained in:
parent
4e8227aead
commit
4d8ef1f040
2 changed files with 57 additions and 28 deletions
46
game.py
46
game.py
|
|
@ -1,22 +1,21 @@
|
||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
from scripts.entities import PhysicsEntity, Player
|
from scripts.entities import Player
|
||||||
from scripts.utils import *
|
from scripts.utils import load_image
|
||||||
from scripts.tilemap import *
|
from scripts.utils import load_images
|
||||||
|
from scripts.tilemap import Tilemap
|
||||||
from scripts.clouds import Clouds
|
from scripts.clouds import Clouds
|
||||||
from scripts.animation import Animation
|
from scripts.animation import Animation
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
|
|
||||||
pygame.display.set_caption("Jump and run spiel")
|
pygame.display.set_caption("Jump and run spiel")
|
||||||
self.screen = pygame.display.set_mode((640, 480))
|
self.screen = pygame.display.set_mode((640, 480))
|
||||||
self.display = pygame.Surface((320, 240))
|
self.display = pygame.Surface((320, 240))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
|
|
@ -31,10 +30,13 @@ class Game:
|
||||||
"large_decor": load_images("tiles/large_decor"),
|
"large_decor": load_images("tiles/large_decor"),
|
||||||
"stone": load_images("tiles/stone"),
|
"stone": load_images("tiles/stone"),
|
||||||
"clouds": load_images("clouds"),
|
"clouds": load_images("clouds"),
|
||||||
|
|
||||||
# Spieler
|
# Spieler
|
||||||
"player/idle":Animation(load_images("entities/player/idle"), image_duration=6),
|
"player/idle": Animation(
|
||||||
"player/run":Animation(load_images("entities/player/run"), image_duration=4),
|
load_images("entities/player/idle"), image_duration=6
|
||||||
|
),
|
||||||
|
"player/run": Animation(
|
||||||
|
load_images("entities/player/run"), image_duration=4
|
||||||
|
),
|
||||||
"player/jump": Animation(load_images("entities/player/jump")),
|
"player/jump": Animation(load_images("entities/player/jump")),
|
||||||
"player/slide": Animation(load_images("entities/player/slide")),
|
"player/slide": Animation(load_images("entities/player/slide")),
|
||||||
"player/wall_slide": Animation(load_images("entities/player/wall_slide")),
|
"player/wall_slide": Animation(load_images("entities/player/wall_slide")),
|
||||||
|
|
@ -43,7 +45,7 @@ class Game:
|
||||||
|
|
||||||
self.tilemap = Tilemap(self, 16)
|
self.tilemap = Tilemap(self, 16)
|
||||||
self.tilemap.load("map.json")
|
self.tilemap.load("map.json")
|
||||||
self.clouds = Clouds(self.assets['clouds'], count=16)
|
self.clouds = Clouds(self.assets["clouds"], count=16)
|
||||||
self.isJumping = False
|
self.isJumping = False
|
||||||
self.scroll = [0, 0]
|
self.scroll = [0, 0]
|
||||||
self.test: dict = {"dsa"}
|
self.test: dict = {"dsa"}
|
||||||
|
|
@ -52,17 +54,22 @@ class Game:
|
||||||
print(self.test)
|
print(self.test)
|
||||||
print(type(self.test))
|
print(type(self.test))
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
|
self.display.blit(self.assets["background"], (0, 0))
|
||||||
|
|
||||||
self.display.blit(self.assets['background'], (0,0))
|
self.scroll[0] += (
|
||||||
|
self.player.rect().centerx
|
||||||
self.scroll[0] += (self.player.rect().centerx - self.display.get_width() / 2 - self.scroll[0]) / 30
|
- self.display.get_width() / 2
|
||||||
self.scroll[1] += (self.player.rect().centery - self.display.get_height() / 2 - self.scroll[1]) / 30
|
- self.scroll[0]
|
||||||
|
) / 30
|
||||||
|
self.scroll[1] += (
|
||||||
|
self.player.rect().centery
|
||||||
|
- self.display.get_height() / 2
|
||||||
|
- self.scroll[1]
|
||||||
|
) / 30
|
||||||
render_scroll = (int(self.scroll[0]), int(self.scroll[1]))
|
render_scroll = (int(self.scroll[0]), int(self.scroll[1]))
|
||||||
|
|
||||||
|
|
||||||
self.clouds.update()
|
self.clouds.update()
|
||||||
self.clouds.render(self.display, offset=render_scroll)
|
self.clouds.render(self.display, offset=render_scroll)
|
||||||
self.tilemap.render(self.display, offset=render_scroll)
|
self.tilemap.render(self.display, offset=render_scroll)
|
||||||
|
|
@ -72,7 +79,6 @@ class Game:
|
||||||
# print(int(self.player.pos[1]))
|
# print(int(self.player.pos[1]))
|
||||||
# print(self.tilemap.tiles_around(self.player.pos))
|
# print(self.tilemap.tiles_around(self.player.pos))
|
||||||
|
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
@ -92,12 +98,12 @@ class Game:
|
||||||
if event.key == pygame.K_d:
|
if event.key == pygame.K_d:
|
||||||
self.movement[1] = False
|
self.movement[1] = False
|
||||||
|
|
||||||
|
self.screen.blit(
|
||||||
self.screen.blit(pygame.transform.scale(self.display, self.screen.get_size()), (0,0))
|
pygame.transform.scale(self.display, self.screen.get_size()), (0, 0)
|
||||||
|
)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(60)
|
self.clock.tick(60)
|
||||||
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
|
||||||
23
scripts/models.py
Normal file
23
scripts/models.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Tile:
|
||||||
|
type: str
|
||||||
|
variant: int
|
||||||
|
pos: list[int]
|
||||||
|
|
||||||
|
def grid_key(self) -> str:
|
||||||
|
"""Erzeugt den String-Key für die Tilemap."""
|
||||||
|
return f"{self.pos[0]};{self.pos[1]}"
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
"""Konvertiert zurück in ein Dict (für JSON-Speicherung)."""
|
||||||
|
|
||||||
|
return {"type": self.type, "variant": self.variant, "pos": list(self.pos)}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_dict(data: dict) -> "Tile":
|
||||||
|
"""Erstellt ein Tile aus einem Dictionary."""
|
||||||
|
|
||||||
|
return Tile(type=data["type"], variant=data["variant"], pos=data["pos"])
|
||||||
Loading…
Reference in a new issue