From 19210b0032b78e080e39dc545803f66555246397 Mon Sep 17 00:00:00 2001 From: Wobbl Date: Tue, 16 Jul 2024 13:06:27 +0200 Subject: [PATCH] Added some special settings. --- falling_sand.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/falling_sand.py b/falling_sand.py index 31557c5..8e047cb 100755 --- a/falling_sand.py +++ b/falling_sand.py @@ -15,6 +15,8 @@ def true_false_random(): class Settings: fps: int = 60 window_size: tuple = (1000, 600) + slipperiness_left: int = 1 + slipperiness_right: int = 1 class FallingSandParticle: @@ -32,7 +34,7 @@ class FallingSandParticle: old_pos = self.pos ox, oy = old_pos - if oy >= self.app.sand_surface.get_height() - 2: + if oy >= self.app.sand_surface.get_height() - self.app.max_height: self.app.falling_sand_particles.remove(self) return @@ -42,24 +44,24 @@ class FallingSandParticle: y += 1 elif ( - self.app.matrix[ox - 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray) - and self.app.matrix[ox + 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray) + self.app.matrix[ox - 1, oy + self.app.slipperiness_left] == self.app.sand_surface.map_rgb(self.app.gray) + and self.app.matrix[ox + 1, oy + self.app.slipperiness_right] == self.app.sand_surface.map_rgb(self.app.gray) ): # when the sand can slide in two directions if true_false_random(): x -= 1 - y += 2 + y += self.app.slipperiness_left else: x += 1 - y += 2 + y += self.app.slipperiness_right - elif self.app.matrix[ox - 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide left + elif self.app.matrix[ox - 1, oy + self.app.slipperiness_left] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide left x -= 1 - y += 2 + y += self.app.slipperiness_left - elif self.app.matrix[ox + 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide right + elif self.app.matrix[ox + 1, oy + self.app.slipperiness_right] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide right x += 1 - y += 2 + y += self.app.slipperiness_right else: if self.not_moving == 32: # counter that increases when the particle is inactive and if it is 32, @@ -105,6 +107,9 @@ class FallingSand: setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json")) self.fps = self.settings.fps + self.slipperiness_left = self.settings.slipperiness_left + self.slipperiness_right = self.settings.slipperiness_right + self.max_height = self.slipperiness_left if self.slipperiness_left > self.slipperiness_right else self.slipperiness_right self.falling_sand_particles = [] self.rainbow_data = [[255, 40, 40], 0] # color calculation stuff self.rainbow_steps = [(1, True), (0, False), (2, True), (1, False), (0, True), (2, False)]