walking animation only when walking
This commit is contained in:
parent
ac46800849
commit
37583a4c5f
1 changed files with 25 additions and 7 deletions
32
creeper.py
32
creeper.py
|
|
@ -353,7 +353,7 @@ class Creeper(Game):
|
||||||
self.creepers = cycle(
|
self.creepers = cycle(
|
||||||
flatten(
|
flatten(
|
||||||
[
|
[
|
||||||
repeat(pygame.image.load(img), 10)
|
repeat(pygame.image.load(img), 5)
|
||||||
for img in Path("assets/stev/idle/").glob("*.png")
|
for img in Path("assets/stev/idle/").glob("*.png")
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
@ -361,7 +361,8 @@ class Creeper(Game):
|
||||||
self.tree_imgs = [
|
self.tree_imgs = [
|
||||||
pygame.image.load(img) for img in Path("assets/oak_trees/").glob("*.png")
|
pygame.image.load(img) for img in Path("assets/oak_trees/").glob("*.png")
|
||||||
]
|
]
|
||||||
self.creeper = pygame.image.load("assets/creeper/idle/1.png")
|
# self.creeper = pygame.image.load("assets/creeper/idle/1.png")
|
||||||
|
self.creeper = next(self.creepers)
|
||||||
self.bee = Bee()
|
self.bee = Bee()
|
||||||
x = 0
|
x = 0
|
||||||
self.hotbar = HotBar(game=self)
|
self.hotbar = HotBar(game=self)
|
||||||
|
|
@ -514,6 +515,11 @@ class Creeper(Game):
|
||||||
if hat[1] == 1:
|
if hat[1] == 1:
|
||||||
self.y -= 10
|
self.y -= 10
|
||||||
|
|
||||||
|
if abs(joystick.get_axis(0)) > 0.2:
|
||||||
|
self.x += joystick.get_axis(0) * 10
|
||||||
|
if abs(joystick.get_axis(1)) > 0.2:
|
||||||
|
self.y += joystick.get_axis(1) * 10
|
||||||
|
|
||||||
def inventory_keys(self):
|
def inventory_keys(self):
|
||||||
keys = self.keys
|
keys = self.keys
|
||||||
for joystick in self.joysticks.values():
|
for joystick in self.joysticks.values():
|
||||||
|
|
@ -539,17 +545,26 @@ class Creeper(Game):
|
||||||
def make_sound(self):
|
def make_sound(self):
|
||||||
if not hasattr(self, "last_x"):
|
if not hasattr(self, "last_x"):
|
||||||
self.last_x = self.x
|
self.last_x = self.x
|
||||||
if self.last_x == self.x and self.walking_sound_is_playing:
|
if not hasattr(self, "last_y"):
|
||||||
|
self.last_y = self.y
|
||||||
|
if (
|
||||||
|
self.last_x == self.x and self.last_y == self.y
|
||||||
|
) and self.walking_sound_is_playing:
|
||||||
self.walking_sound.stop()
|
self.walking_sound.stop()
|
||||||
self.walking_sound_is_playing = False
|
self.walking_sound_is_playing = False
|
||||||
|
|
||||||
if self.last_x != self.x and not self.walking_sound_is_playing:
|
if (
|
||||||
|
self.last_x != self.x or self.last_y != self.y
|
||||||
|
) and not self.walking_sound_is_playing:
|
||||||
self.walking_sound.play()
|
self.walking_sound.play()
|
||||||
self.walking_sound_is_playing = True
|
self.walking_sound_is_playing = True
|
||||||
|
if self.last_x != self.x or self.last_y != self.y:
|
||||||
|
|
||||||
|
self.creeper = next(self.creepers)
|
||||||
self.last_x = self.x
|
self.last_x = self.x
|
||||||
|
self.last_y = self.y
|
||||||
|
|
||||||
def game(self):
|
def game(self):
|
||||||
creeper = next(self.creepers)
|
|
||||||
self.screen.blit(self.background, (0, 0))
|
self.screen.blit(self.background, (0, 0))
|
||||||
self.background.fill((0, 255, 247))
|
self.background.fill((0, 255, 247))
|
||||||
self.process_deaths()
|
self.process_deaths()
|
||||||
|
|
@ -557,8 +572,11 @@ class Creeper(Game):
|
||||||
tree.draw()
|
tree.draw()
|
||||||
|
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
creeper,
|
self.creeper,
|
||||||
(self.x - creeper.get_size()[0] / 2, self.y - creeper.get_size()[1] / 2),
|
(
|
||||||
|
self.x - self.creeper.get_size()[0] / 2,
|
||||||
|
self.y - self.creeper.get_size()[1] / 2,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.bee.draw(self.screen, self.x, self.y)
|
self.bee.draw(self.screen, 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