Sanftes Schweben der Blätter über Sinuswelle

This commit is contained in:
Benjamin 2026-05-20 18:28:03 +02:00
parent 261cc92897
commit e1b5a42137

47
game.py
View file

@ -1,6 +1,7 @@
import pygame # ty: ignore[unresolved-import] import pygame # ty: ignore[unresolved-import]
import sys import sys
import random import random
import math
from scripts.entities import Player from scripts.entities import 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
@ -66,15 +67,12 @@ class Game:
self.leaf_spawners: list[pygame.Rect] = [] self.leaf_spawners: list[pygame.Rect] = []
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(
pygame.Rect( pygame.Rect(4 + tree["pos"][0], 4 + tree["pos"][1], 23, 13)
4 + tree["pos"][0], 4 + tree["pos"][1], 23, 13
)
) )
self.particles = [] self.particles: list[Particle] = []
self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16) self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16)
self.isJumping: bool = False self.isJumping: bool = False
@ -97,20 +95,20 @@ class Game:
render_scroll: tuple[int, int] = (int(self.scroll[0]), int(self.scroll[1])) render_scroll: tuple[int, int] = (int(self.scroll[0]), int(self.scroll[1]))
for rect in self.leaf_spawners: for rect in self.leaf_spawners:
if random.random() * 49999 < rect.width * rect.height: if random.random() * 49999 < rect.width * rect.height:
pos = ( pos = (
rect.x + random.random() * rect.width, rect.x + random.random() * rect.width,
rect.y + random.random() * rect.height, rect.y + random.random() * rect.height,
) )
self.particles.append( self.particles.append(
Particle( Particle(
self, self,
"leaf", "leaf",
pos, pos,
velocity=[-0.1, 0.3], velocity=[-0.1, 0.3],
frame=random.randint(0, 20), frame=random.randint(0, 20),
) )
) )
self.clouds.update() self.clouds.update()
self.clouds.render(surface=self.display, offset=render_scroll) self.clouds.render(surface=self.display, offset=render_scroll)
@ -122,6 +120,15 @@ class Game:
# print(int(self.player.pos[0])) # print(int(self.player.pos[0]))
# 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 particle in self.particles.copy():
kill: bool = particle.update()
particle.render(self.display, offset=render_scroll)
if particle.type == 'leaf':
particle.pos[0] += math.sin(particle.animation.frame * 0.035) * 0.3
if kill:
self.particles.remove(particle)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT: