From d5caa29017b553a1cac0c31590c6a9a788a45fec Mon Sep 17 00:00:00 2001 From: Wobbl Date: Tue, 16 Jul 2024 10:31:34 +0200 Subject: [PATCH] Added some comments. --- falling_sand.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/falling_sand.py b/falling_sand.py index 67af7c9..31557c5 100755 --- a/falling_sand.py +++ b/falling_sand.py @@ -32,19 +32,19 @@ class FallingSandParticle: old_pos = self.pos ox, oy = old_pos - if oy >= self.app.sand_surface.get_height() - 4: + if oy >= self.app.sand_surface.get_height() - 2: self.app.falling_sand_particles.remove(self) return x, y = self.pos - if self.app.matrix[ox, oy + 1] == self.app.sand_surface.map_rgb(self.app.gray): + if self.app.matrix[ox, oy + 1] == self.app.sand_surface.map_rgb(self.app.gray): # fall down 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) - ): + ): # when the sand can slide in two directions if true_false_random(): x -= 1 y += 2 @@ -53,17 +53,17 @@ class FallingSandParticle: x += 1 y += 2 - elif self.app.matrix[ox - 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): + elif self.app.matrix[ox - 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide left x -= 1 y += 2 - elif self.app.matrix[ox + 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): + elif self.app.matrix[ox + 1, oy + 2] == self.app.sand_surface.map_rgb(self.app.gray): # can only slide right x += 1 y += 2 else: - if self.not_moving == 32: - if self.app.mouse_pressed[0]: + if self.not_moving == 32: # counter that increases when the particle is inactive and if it is 32, + if self.app.mouse_pressed[0]: # the particle's physics get deactivated for better performance. self.not_moving = 0 else: @@ -80,7 +80,7 @@ class FallingSandParticle: return - if not x > self.app.sand_surface.get_width() - 2:# and not x < 0: + if not x > self.app.sand_surface.get_width() - 2: # game would crash when the particle goes outside the border. self.not_moving = 0 self.pos = (x, y) @@ -93,20 +93,20 @@ class FallingSand: def __init__(self): pygame.init() - self.screen = pygame.display.set_mode((1000, 600), pygame.RESIZABLE) + self.screen = pygame.display.set_mode((1000, 600), pygame.RESIZABLE) # pygame init default shit pygame.display.set_caption("Wobbl Sand") self.window = Window.from_display_module() - self.loading_surface = self.generate_loading_surface() + self.loading_surface = self.generate_loading_surface() # just the loading screen self.screen.blit(self.loading_surface, (0, 0)) pygame.display.update() - self.settings = load_dataclass_json(Settings, "settings.json") + self.settings = load_dataclass_json(Settings, "settings.json") # load settings setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json")) self.fps = self.settings.fps self.falling_sand_particles = [] - self.rainbow_data = [[255, 40, 40], 0] + 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)] # colors @@ -142,7 +142,7 @@ class FallingSand: def loop(self): self.screen.fill(self.gray) - self.matrix = pygame.PixelArray(self.sand_surface) + self.matrix = pygame.PixelArray(self.sand_surface) # matrix to draw the sand particles on self.mouse_pressed = self.mouse.get_pressed() self.mouse_pos = self.mouse.get_pos()