Gegner-Logik hinzugefügt und Tilemap aktualisiert
This commit is contained in:
parent
62c6ae19d8
commit
8e465ba27b
2 changed files with 25 additions and 2 deletions
12
game.py
12
game.py
|
|
@ -2,7 +2,7 @@ import pygame # ty: ignore[unresolved-import]
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
from scripts.entities import Player
|
from scripts.entities import Enemy, Player
|
||||||
from scripts.utils import load_image
|
from scripts.utils import load_image
|
||||||
from scripts.utils import load_images
|
from scripts.utils import load_images
|
||||||
from scripts.tilemap import Tilemap
|
from scripts.tilemap import Tilemap
|
||||||
|
|
@ -52,6 +52,10 @@ class Game:
|
||||||
"player/wall_slide": Animation(
|
"player/wall_slide": Animation(
|
||||||
load_images(path="entities/player/wall_slide")
|
load_images(path="entities/player/wall_slide")
|
||||||
),
|
),
|
||||||
|
|
||||||
|
"enemy/idle": Animation(load_images(path="entities/enemy/idle"), image_duration=6),
|
||||||
|
"enemy/run": Animation(load_images(path="entities/enemy/run"), image_duration=4),
|
||||||
|
|
||||||
"particles/leaf": Animation(
|
"particles/leaf": Animation(
|
||||||
load_images(path="particles/leaf"), image_duration=20, loop=False
|
load_images(path="particles/leaf"), image_duration=20, loop=False
|
||||||
),
|
),
|
||||||
|
|
@ -72,6 +76,7 @@ class Game:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.leaf_spawners: list[pygame.Rect] = []
|
self.leaf_spawners: list[pygame.Rect] = []
|
||||||
|
self.enemys: list[Enemy] = []
|
||||||
|
|
||||||
for tree in self.tilemap.extract([("large_decor", 2)], keep=True):
|
for tree in self.tilemap.extract([("large_decor", 2)], keep=True):
|
||||||
self.leaf_spawners.append(
|
self.leaf_spawners.append(
|
||||||
|
|
@ -82,7 +87,7 @@ class Game:
|
||||||
if spawner["variant"] == 0:
|
if spawner["variant"] == 0:
|
||||||
self.player.pos = spawner["pos"]
|
self.player.pos = spawner["pos"]
|
||||||
else:
|
else:
|
||||||
print(spawner["pos"], "enemy")
|
self.enemys.append(Enemy(self, spawner["pos"], (8, 15)))
|
||||||
|
|
||||||
self.particles: list[Particle] = []
|
self.particles: list[Particle] = []
|
||||||
|
|
||||||
|
|
@ -128,6 +133,9 @@ class Game:
|
||||||
self.clouds.update()
|
self.clouds.update()
|
||||||
self.clouds.render(surface=self.display, offset=render_scroll)
|
self.clouds.render(surface=self.display, offset=render_scroll)
|
||||||
self.tilemap.render(surface=self.display, offset=render_scroll)
|
self.tilemap.render(surface=self.display, offset=render_scroll)
|
||||||
|
for enemy in self.enemys.copy():
|
||||||
|
enemy.update(self.tilemap, (0, 0))
|
||||||
|
enemy.render(self.display, offset=render_scroll)
|
||||||
self.player.update(
|
self.player.update(
|
||||||
self.tilemap, movement=((self.movement[1] - self.movement[0]), 0)
|
self.tilemap, movement=((self.movement[1] - self.movement[0]), 0)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,21 @@ class PhysicsEntity:
|
||||||
image = self.e_type + "/" + self.action
|
image = self.e_type + "/" + self.action
|
||||||
self.animation = self.game.assets[image].copy()
|
self.animation = self.game.assets[image].copy()
|
||||||
|
|
||||||
|
class Enemy(PhysicsEntity):
|
||||||
|
def __init__(self, game, pos: tuple[float, float], size: tuple[int, int]):
|
||||||
|
super().__init__(game, "enemy", pos, size)
|
||||||
|
|
||||||
|
self.walking = 0
|
||||||
|
|
||||||
|
def update(self, tilemap, movement: tuple[float, float] = (0, 0)):
|
||||||
|
if self.walking:
|
||||||
|
movement = (movement[0] - 0.5 if self.flip else 0.5, movement[1])
|
||||||
|
self.walking = max(0, self.walking - 1)
|
||||||
|
elif random.random() < 0.01:
|
||||||
|
self.walking = random.randint(30, 120)
|
||||||
|
|
||||||
|
super().update(tilemap, movement)
|
||||||
|
|
||||||
|
|
||||||
class Player(PhysicsEntity):
|
class Player(PhysicsEntity):
|
||||||
def __init__(self, game, pos: tuple[float, float], size: tuple[int, int]):
|
def __init__(self, game, pos: tuple[float, float], size: tuple[int, int]):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue