From a5b9d062e226c37916077fe078a5f21008c6bbff Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sun, 1 Jan 2023 09:55:00 -0600 Subject: [PATCH] add tree shake --- creeper.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/creeper.py b/creeper.py index dd98361..83d3c20 100755 --- a/creeper.py +++ b/creeper.py @@ -35,8 +35,11 @@ class TreeSprite: self.flip = flip self.surf = surf self.leafs = [Leaf(self, self.surf, (x + 25, y + 25)) for i in range(2)] + self.shaking = 0 def shake(self): + if self.shaking == 0: + self.shaking = 10 self.leafs.extend( [ Leaf( @@ -52,6 +55,13 @@ class TreeSprite: ] ) + @property + def rotate(self): + if self.shaking == 0: + return 0 + self.shaking -= 1 + return random.randint(-15, 15) + @property def rect(self): return pygame.Rect( @@ -64,10 +74,13 @@ class TreeSprite: def draw(self): if self.health > 0: self.surf.blit( - pygame.transform.flip( - pygame.transform.scale(self.image, (self.scale, self.scale)), - self.flip, - False, + pygame.transform.rotate( + pygame.transform.flip( + pygame.transform.scale(self.image, (self.scale, self.scale)), + self.flip, + False, + ), + self.rotate, ), (self.x, self.y), )