Compare commits
2 Commits
413cefb933
...
366b2b2a9a
| Author | SHA1 | Date | |
|---|---|---|---|
| 366b2b2a9a | |||
| 4b1c6e15cf |
@ -46,6 +46,7 @@ class FightingCharacter(GameObject):
|
|||||||
self.jump_sound: SoundComponent = None # type: ignore[assignment]
|
self.jump_sound: SoundComponent = None # type: ignore[assignment]
|
||||||
self.hit_sound: SoundComponent = None # type: ignore[assignment]
|
self.hit_sound: SoundComponent = None # type: ignore[assignment]
|
||||||
self.die_sound: SoundComponent = None # type: ignore[assignment]
|
self.die_sound: SoundComponent = None # type: ignore[assignment]
|
||||||
|
self.guitar_hero_components: None
|
||||||
self.fall_through = False
|
self.fall_through = False
|
||||||
self.fall_through_timer = 0.0
|
self.fall_through_timer = 0.0
|
||||||
self.fall_through_duration = 0.2
|
self.fall_through_duration = 0.2
|
||||||
@ -95,6 +96,17 @@ class FightingCharacter(GameObject):
|
|||||||
self.hit_sound = self.sounds.add_component("hit", SoundComponent, "assets/sounds/hit.wav")
|
self.hit_sound = self.sounds.add_component("hit", SoundComponent, "assets/sounds/hit.wav")
|
||||||
self.die_sound = self.sounds.add_component("die", SoundComponent, "assets/sounds/die.wav")
|
self.die_sound = self.sounds.add_component("die", SoundComponent, "assets/sounds/die.wav")
|
||||||
|
|
||||||
|
# TODO, james add more buttons
|
||||||
|
guitar_hero_key_bindings = {
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_UP: "assets/sounds/nes_harp/nes_harp_A4.wav",
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN: "assets/sounds/nes_harp/nes_harp_C4.wav",
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_LEFT: "assets/sounds/nes_harp/nes_harp_D4.wav",
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT: "assets/sounds/nes_harp/nes_harp_G4.wav",
|
||||||
|
}
|
||||||
|
self.guitar_hero_components = {}
|
||||||
|
for key_press, wav_file in guitar_hero_key_bindings.items():
|
||||||
|
self.guitar_hero_components[key_press] = self.sounds.add_component(key_press, SoundComponent, wav_file)
|
||||||
|
|
||||||
self.animation = self.add_component(AnimationController(self.body))
|
self.animation = self.add_component(AnimationController(self.body))
|
||||||
if self.player_number == 1:
|
if self.player_number == 1:
|
||||||
self.animation.add_animation_from_files("run",
|
self.animation.add_animation_from_files("run",
|
||||||
@ -188,6 +200,20 @@ class FightingCharacter(GameObject):
|
|||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Add more buttons here
|
||||||
|
gamepad_buttons = [
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_UP,
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN,
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_LEFT,
|
||||||
|
rl.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT,
|
||||||
|
]
|
||||||
|
for button in gamepad_buttons:
|
||||||
|
if rl.is_gamepad_button_pressed(self.gamepad, button):
|
||||||
|
self.guitar_hero_components[button].play()
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
deadzone = 0.1
|
deadzone = 0.1
|
||||||
jump_pressed = rl.is_key_pressed(rl.KEY_W) or rl.is_gamepad_button_pressed(self.gamepad, rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
jump_pressed = rl.is_key_pressed(rl.KEY_W) or rl.is_gamepad_button_pressed(self.gamepad, rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
||||||
jump_held = rl.is_key_down(rl.KEY_W) or rl.is_gamepad_button_down(self.gamepad, rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
jump_held = rl.is_key_down(rl.KEY_W) or rl.is_gamepad_button_down(self.gamepad, rl.GAMEPAD_BUTTON_RIGHT_FACE_DOWN)
|
||||||
@ -276,6 +302,7 @@ class FightingCharacter(GameObject):
|
|||||||
Returns:
|
Returns:
|
||||||
True to enable contact, False to disable it.
|
True to enable contact, False to disable it.
|
||||||
"""
|
"""
|
||||||
|
return True
|
||||||
normal = contact.worldManifold.normal
|
normal = contact.worldManifold.normal
|
||||||
other = None
|
other = None
|
||||||
sign = 0.0
|
sign = 0.0
|
||||||
@ -375,7 +402,7 @@ class FightingScene(Scene):
|
|||||||
self.physics.world.contactListener = FightingContactListener(self)
|
self.physics.world.contactListener = FightingContactListener(self)
|
||||||
|
|
||||||
player_entities = self.level.get_entities_by_name("Start")
|
player_entities = self.level.get_entities_by_name("Start")
|
||||||
for i, player_entity in enumerate(player_entities[:4]):
|
for i, player_entity in enumerate(player_entities[:1]):
|
||||||
params = CharacterParams()
|
params = CharacterParams()
|
||||||
params.position = self.level.convert_to_pixels(player_entity.getPosition())
|
params.position = self.level.convert_to_pixels(player_entity.getPosition())
|
||||||
params.width = 16
|
params.width = 16
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user