Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created subclass player, added simple footstep sound to player class #21

Merged
merged 1 commit into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/sounds/footstep_concrete_000.ogg
Binary file not shown.
1 change: 1 addition & 0 deletions rpg/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
arcade.resources.add_resource_handle("characters", "resources/characters")
arcade.resources.add_resource_handle("maps", "resources/maps")
arcade.resources.add_resource_handle("data", "resources/data")
arcade.resources.add_resource_handle("sounds", "resources/sounds")


def main():
Expand Down
49 changes: 49 additions & 0 deletions rpg/player_sprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import arcade
from rpg.character_sprite import CharacterSprite
from rpg.constants import SPRITE_SIZE

class PlayerSprite(CharacterSprite):
def __init__(self, sheet_name):
super().__init__(sheet_name)
self.sound_update = 0
self.footstep_sound = arcade.load_sound(":sounds:footstep_concrete_000.ogg")

def on_update(self, delta_time):
if not self.change_x and not self.change_y:
return

# self.center_x += self.change_x
# self.center_y += self.change_y

if self.should_update <= 3:
self.should_update += 1
else:
self.should_update = 0
self.cur_texture_index += 1
self.sound_update += 1
if self.sound_update >= 7:
arcade.play_sound(self.footstep_sound)
self.sound_update = 0

if self.change_x > 0:
if self.cur_texture_index < 6:
self.cur_texture_index = 6
elif self.cur_texture_index > 8:
self.cur_texture_index = 6
elif self.change_x < 0:
if self.cur_texture_index < 3:
self.cur_texture_index = 3
elif self.cur_texture_index > 5:
self.cur_texture_index = 3
elif self.change_y > 0:
if self.cur_texture_index < 9:
self.cur_texture_index = 9
elif self.cur_texture_index > 11:
self.cur_texture_index = 9
else:
if self.cur_texture_index < 0:
self.cur_texture_index = 0
elif self.cur_texture_index > 2:
self.cur_texture_index = 0

self.texture = self.textures[self.cur_texture_index]
3 changes: 2 additions & 1 deletion rpg/views/game_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import rpg.constants as constants
from arcade.experimental.lights import Light
from rpg.character_sprite import CharacterSprite
from rpg.player_sprite import PlayerSprite
from rpg.message_box import MessageBox


Expand Down Expand Up @@ -100,7 +101,7 @@ def setup(self):
"""Set up the game variables. Call to re-start the game."""

# Create the player character
self.player_sprite = CharacterSprite(":characters:Female/Female 18-4.png")
self.player_sprite = PlayerSprite(":characters:Female/Female 18-4.png")

# Spawn the player
start_x = constants.STARTING_X
Expand Down