add tree shake

This commit is contained in:
Waylon Walker 2023-01-01 09:55:00 -06:00
parent a0d655b274
commit a5b9d062e2
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4

View file

@ -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),
)