add tree shake
This commit is contained in:
parent
a0d655b274
commit
a5b9d062e2
1 changed files with 17 additions and 4 deletions
13
creeper.py
13
creeper.py
|
|
@ -35,8 +35,11 @@ class TreeSprite:
|
||||||
self.flip = flip
|
self.flip = flip
|
||||||
self.surf = surf
|
self.surf = surf
|
||||||
self.leafs = [Leaf(self, self.surf, (x + 25, y + 25)) for i in range(2)]
|
self.leafs = [Leaf(self, self.surf, (x + 25, y + 25)) for i in range(2)]
|
||||||
|
self.shaking = 0
|
||||||
|
|
||||||
def shake(self):
|
def shake(self):
|
||||||
|
if self.shaking == 0:
|
||||||
|
self.shaking = 10
|
||||||
self.leafs.extend(
|
self.leafs.extend(
|
||||||
[
|
[
|
||||||
Leaf(
|
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
|
@property
|
||||||
def rect(self):
|
def rect(self):
|
||||||
return pygame.Rect(
|
return pygame.Rect(
|
||||||
|
|
@ -64,11 +74,14 @@ class TreeSprite:
|
||||||
def draw(self):
|
def draw(self):
|
||||||
if self.health > 0:
|
if self.health > 0:
|
||||||
self.surf.blit(
|
self.surf.blit(
|
||||||
|
pygame.transform.rotate(
|
||||||
pygame.transform.flip(
|
pygame.transform.flip(
|
||||||
pygame.transform.scale(self.image, (self.scale, self.scale)),
|
pygame.transform.scale(self.image, (self.scale, self.scale)),
|
||||||
self.flip,
|
self.flip,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
|
self.rotate,
|
||||||
|
),
|
||||||
(self.x, self.y),
|
(self.x, self.y),
|
||||||
)
|
)
|
||||||
for leaf in self.leafs:
|
for leaf in self.leafs:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue