Sanftes Schweben der Blätter über Sinuswelle
This commit is contained in:
parent
261cc92897
commit
e1b5a42137
1 changed files with 27 additions and 20 deletions
47
game.py
47
game.py
|
|
@ -1,6 +1,7 @@
|
|||
import pygame # ty: ignore[unresolved-import]
|
||||
import pygame # ty: ignore[unresolved-import]
|
||||
import sys
|
||||
import random
|
||||
import math
|
||||
from scripts.entities import Player
|
||||
from scripts.utils import load_image
|
||||
from scripts.utils import load_images
|
||||
|
|
@ -66,15 +67,12 @@ class Game:
|
|||
|
||||
self.leaf_spawners: list[pygame.Rect] = []
|
||||
|
||||
|
||||
for tree in self.tilemap.extract([("large_decor", 2)], keep=True):
|
||||
self.leaf_spawners.append(
|
||||
pygame.Rect(
|
||||
4 + tree["pos"][0], 4 + tree["pos"][1], 23, 13
|
||||
)
|
||||
pygame.Rect(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.isJumping: bool = False
|
||||
|
|
@ -97,20 +95,20 @@ class Game:
|
|||
render_scroll: tuple[int, int] = (int(self.scroll[0]), int(self.scroll[1]))
|
||||
|
||||
for rect in self.leaf_spawners:
|
||||
if random.random() * 49999 < rect.width * rect.height:
|
||||
pos = (
|
||||
rect.x + random.random() * rect.width,
|
||||
rect.y + random.random() * rect.height,
|
||||
)
|
||||
self.particles.append(
|
||||
Particle(
|
||||
self,
|
||||
"leaf",
|
||||
pos,
|
||||
velocity=[-0.1, 0.3],
|
||||
frame=random.randint(0, 20),
|
||||
)
|
||||
)
|
||||
if random.random() * 49999 < rect.width * rect.height:
|
||||
pos = (
|
||||
rect.x + random.random() * rect.width,
|
||||
rect.y + random.random() * rect.height,
|
||||
)
|
||||
self.particles.append(
|
||||
Particle(
|
||||
self,
|
||||
"leaf",
|
||||
pos,
|
||||
velocity=[-0.1, 0.3],
|
||||
frame=random.randint(0, 20),
|
||||
)
|
||||
)
|
||||
|
||||
self.clouds.update()
|
||||
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[1]))
|
||||
# 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():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
|
|||
Loading…
Reference in a new issue