Skip to content

Commit

Permalink
Remove unused dentist hitbox code
Browse files Browse the repository at this point in the history
  • Loading branch information
ccntrq committed Feb 16, 2023
1 parent 07319e5 commit d9cc8e3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 72 deletions.
6 changes: 4 additions & 2 deletions delirious-dentist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import config

from sound import Sound
from view.game import GameView
from view.instruction import InstructionView

Expand All @@ -21,9 +22,10 @@ def main():
config.SCREEN_WIDTH, config.SCREEN_HEIGHT, config.SCREEN_TITLE
)

game_view = GameView()
sound = Sound()
game_view = GameView(sound)
game_view.setup()
start_view = InstructionView(game_view)
start_view = InstructionView(game_view, sound)
start_view.setup()
window.show_view(start_view)
arcade.run()
Expand Down
44 changes: 44 additions & 0 deletions src/sound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import arcade

import config


class Sound:
def __init__(self):
# Load sounds
self.game_opening_sound = arcade.load_sound(config.GAME_OPENING_SOUND_RESOURCE)
self.enemy_hit_sound = arcade.load_sound(config.ENEMY_HIT_SOUND_RESOURCE)
self.enemy_hit_miss_sound = arcade.load_sound(
config.ENEMY_HIT_MISS_SOUND_RESOURCE
)
self.enemy_hit_punch_sound = arcade.load_sound(
config.ENEMY_HIT_PUNCH_SOUND_RESOURCE
)
self.enemy_hit_gold_punch_sound = arcade.load_sound(
config.ENEMY_HIT_GOLD_PUNCH_SOUND_RESOURCE
)
self.enemy_collision_sound = arcade.load_sound(
config.ENEMY_COLLISION_SOUND_RESOURCE
)
self.game_over_sound = arcade.load_sound(config.GAME_OVER_SOUND_RESOURCE)
self.game_opening_sound = arcade.load_sound(config.GAME_OPENING_SOUND_RESOURCE)
self.space_spam_sound = arcade.load_sound(config.SPACE_SPAM_SOUND_RESOURCE)
self.tooth_collect_sound = arcade.load_sound(
config.TOOTH_COLLECT_SOUND_RESOURCE
)
self.tooth_gold_collect_sound = arcade.load_sound(
config.TOOTH_GOLD_COLLECT_SOUND_RESOURCE
)
self.tooth_drop_sound = arcade.load_sound(config.TOOTH_DROP_SOUND_RESOURCE)
self.tooth_gold_drop_sound = arcade.load_sound(
config.TOOTH_GOLD_DROP_SOUND_RESOURCE
)
self.item_collect_pliers_sound = arcade.load_sound(
config.ITEM_COLLECT_PLIERS_SOUND_RESOURCE
)
self.item_collect_bolt_sound = arcade.load_sound(
config.ITEM_COLLECT_BOLT_SOUND_RESOURCE
)
self.item_collect_generic_sound = arcade.load_sound(
config.ITEM_COLLECT_GENERIC_SOUND_RESOURCE
)
11 changes: 0 additions & 11 deletions src/sprite/dentist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def __init__(self):

self.movement_speed = config.CHARACTER_MOVEMENT_SPEED

# XXX auto set hitbox or adjust coordinates to our sprite
# self.points = [[-22, -64], [22, -64], [22, 28], [-22, 28]]

# Set up the player, specifically placing it at these coordinates.
main_image_source = config.CHARACTER_DENTIST_IMAGE_SOURCE
hit_image_source = config.CHARACTER_DENTIST_ATTACK_IMAGE_SOURCE
Expand All @@ -24,12 +21,6 @@ def __init__(self):
self.hit_texture = arcade.load_texture(hit_image_source)
self.pliers_hit_texture = arcade.load_texture(pliers_hit_image_source)
self.texture = self.main_texture
self.main_hit_box = self.get_hit_box()
self.hit_hit_box = self.main_hit_box
# XXX Unused. Changing to a larger hit box pushes us away from borders
# XXX when hitting close while close to one
# self.hit_hit_box = list(map(
# lambda x: [x[0] * 1.5, x[1] * 1.5], list(self.main_hit_box)))
self.hit_active = 0
self.flask_active = False

Expand All @@ -38,11 +29,9 @@ def update_animation(self, delta_time: float = 1 / 60):
self.texture = (
self.pliers_hit_texture if self.pliers_equipped else self.hit_texture
)
self.hit_box = self.hit_hit_box
return

self.texture = self.main_texture
self.hit_box = self.main_hit_box

def is_hitting(self):
return self.hit_active > 0 or self.flask_active
74 changes: 19 additions & 55 deletions src/view/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from animation.grow import GrowAnimation
from room import Room
from sound import Sound
from sprite.dentist import DentistSprite
from sprite.enemy import EnemySprite
from sprite.bolt import BoltSprite
Expand All @@ -25,7 +26,7 @@ class GameView(arcade.View):
Main application class.
"""

def __init__(self):
def __init__(self, sound):
# Call the parent class and set up the window
super().__init__()

Expand All @@ -47,43 +48,7 @@ def __init__(self):

self.key_history = []

# Load sounds
self.enemy_hit_sound = arcade.load_sound(config.ENEMY_HIT_SOUND_RESOURCE)
self.enemy_hit_miss_sound = arcade.load_sound(
config.ENEMY_HIT_MISS_SOUND_RESOURCE
)
self.enemy_hit_punch_sound = arcade.load_sound(
config.ENEMY_HIT_PUNCH_SOUND_RESOURCE
)
self.enemy_hit_gold_punch_sound = arcade.load_sound(
config.ENEMY_HIT_GOLD_PUNCH_SOUND_RESOURCE
)
self.enemy_collision_sound = arcade.load_sound(
config.ENEMY_COLLISION_SOUND_RESOURCE
)
self.game_over_sound = arcade.load_sound(config.GAME_OVER_SOUND_RESOURCE)
self.game_opening_sound = arcade.load_sound(config.GAME_OPENING_SOUND_RESOURCE)
self.space_spam_sound = arcade.load_sound(config.SPACE_SPAM_SOUND_RESOURCE)
self.tooth_collect_sound = arcade.load_sound(
config.TOOTH_COLLECT_SOUND_RESOURCE
)
self.tooth_gold_collect_sound = arcade.load_sound(
config.TOOTH_GOLD_COLLECT_SOUND_RESOURCE
)
self.tooth_drop_sound = arcade.load_sound(config.TOOTH_DROP_SOUND_RESOURCE)
self.tooth_gold_drop_sound = arcade.load_sound(
config.TOOTH_GOLD_DROP_SOUND_RESOURCE
)
self.item_collect_pliers_sound = arcade.load_sound(
config.ITEM_COLLECT_PLIERS_SOUND_RESOURCE
)
self.item_collect_bolt_sound = arcade.load_sound(
config.ITEM_COLLECT_BOLT_SOUND_RESOURCE
)
self.item_collect_generic_sound = arcade.load_sound(
config.ITEM_COLLECT_GENERIC_SOUND_RESOURCE
)
# self.music_sound = arcade.load_sound(MUSIC_SOUND_SOURCE)
self.sound = sound

# Our physics engine
self.physics_engine = None
Expand All @@ -93,7 +58,6 @@ def __init__(self):

def setup(self):
"""Set up the game here. Call this function to restart the game."""
# arcade.play_sound(self.music_sound, 0.1, 0.0, True, 1.0)
self.room.setup()
self.score = 0
self.hit_cooldown = 0
Expand Down Expand Up @@ -177,13 +141,13 @@ def on_update(self, delta_time):
for power_up in power_up_hit_list:
if isinstance(power_up, HeartSprite):
self.add_life()
arcade.play_sound(self.item_collect_generic_sound)
arcade.play_sound(self.sound.item_collect_generic_sound)
elif isinstance(power_up, ToothSprite):
self.on_score(power_up.points)
arcade.play_sound(self.tooth_collect_sound)
arcade.play_sound(self.sound.tooth_collect_sound)
elif isinstance(power_up, GoldenToothSprite):
self.on_score(power_up.points)
arcade.play_sound(self.tooth_gold_collect_sound)
arcade.play_sound(self.sound.tooth_gold_collect_sound)
animation_sprite = GoldenToothSprite()
animation_sprite.scale = 1
GrowAnimation.animate(animation_sprite)
Expand All @@ -194,19 +158,19 @@ def on_update(self, delta_time):
elif isinstance(power_up, PliersSprite):
self.add_pliers_to_ui()
self.player_sprite.pliers_equipped = True
arcade.play_sound(self.item_collect_pliers_sound)
arcade.play_sound(self.sound.item_collect_pliers_sound)
elif isinstance(power_up, FlaskSprite):
self.add_flask_to_ui()
self.flask_active += 500
self.player_sprite.flask_active = True
arcade.play_sound(self.item_collect_generic_sound)
arcade.play_sound(self.sound.item_collect_generic_sound)
elif isinstance(power_up, BoltSprite):
self.add_bolt_to_ui()
self.bolt_active += 500
self.player_sprite.movement_speed = (
config.CHARACTER_MOVEMENT_SPEED * 1.5
)
arcade.play_sound(self.item_collect_bolt_sound)
arcade.play_sound(self.sound.item_collect_bolt_sound)
else:
raise Exception("Unknown power up type.")
power_up.remove_from_sprite_lists()
Expand All @@ -233,15 +197,15 @@ def on_update(self, delta_time):
self.hit_active -= 1
if self.hit_active == 0:
if not enemy_hit_list and not self.has_hit:
arcade.play_sound(self.enemy_hit_miss_sound)
arcade.play_sound(self.sound.enemy_hit_miss_sound)
self.has_hit = False
for enemy in enemy_hit_list:
self.on_enemy_hit(enemy)
self.has_hit = True
else:
for enemy in enemy_hit_list:
enemy.remove_from_sprite_lists()
arcade.play_sound(self.enemy_collision_sound)
arcade.play_sound(self.sound.enemy_collision_sound)
self.remove_life()

if self.hit_cooldown > 0:
Expand Down Expand Up @@ -291,9 +255,9 @@ def on_key_press(self, key, modifiers):
self.key_history.append("right")
elif key == arcade.key.SPACE:
if self.hit_cooldown > 0:
arcade.play_sound(self.space_spam_sound)
arcade.play_sound(self.sound.space_spam_sound)
else:
arcade.play_sound(self.enemy_hit_miss_sound)
arcade.play_sound(self.sound.enemy_hit_miss_sound)
self.hit_active = config.CHARACTER_HIT_TIMEOUT + (
15 if self.player_sprite.pliers_equipped else 0
)
Expand Down Expand Up @@ -324,7 +288,7 @@ def on_enemy_hit(self, enemy):
):
self.drop_tooth(enemy)

arcade.play_sound(self.enemy_hit_sound)
arcade.play_sound(self.sound.enemy_hit_sound)

enemy.remove_from_sprite_lists()

Expand Down Expand Up @@ -377,12 +341,12 @@ def drop_tooth(self, enemy):
):
tooth = GoldenToothSprite()
self.camera.shake(pyglet.math.Vec2(5, 5))
arcade.play_sound(self.enemy_hit_gold_punch_sound)
arcade.play_sound(self.tooth_gold_drop_sound)
arcade.play_sound(self.sound.enemy_hit_gold_punch_sound)
arcade.play_sound(self.sound.tooth_gold_drop_sound)
else:
tooth = ToothSprite()
arcade.play_sound(self.enemy_hit_punch_sound)
arcade.play_sound(self.tooth_drop_sound)
arcade.play_sound(self.sound.enemy_hit_punch_sound)
arcade.play_sound(self.sound.tooth_drop_sound)

self.power_up_list.append(tooth)
self.position_after_hit(self.player_sprite, enemy, tooth)
Expand Down Expand Up @@ -495,7 +459,7 @@ def remove_life(self):

def check_game_over(self):
if not self.life_list.sprite_list:
arcade.play_sound(self.game_over_sound)
arcade.play_sound(self.sound.game_over_sound)
gameover_view = GameOverView(self)
gameover_view.setup()
self.window.show_view(gameover_view)
Expand Down
11 changes: 7 additions & 4 deletions src/view/instruction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import arcade

import config
from sound import Sound


class InstructionView(arcade.View):
"""View to show instructions before the game"""

def __init__(self, game_view):
def __init__(self, game_view, sound):
"""This is run once when we switch to this view"""
super().__init__()

Expand All @@ -14,14 +16,15 @@ def __init__(self, game_view):
# Reset the viewport, necessary if we have a scrolling game and we need
# to reset the viewport back to the start so we can see what we draw.
arcade.set_viewport(0, config.SCREEN_WIDTH - 1, 0, config.SCREEN_HEIGHT - 1)
self.game_opening_sound = arcade.load_sound(config.GAME_OPENING_SOUND_RESOURCE)
arcade.play_sound(self.game_opening_sound)

self.cover_art_list = None
self.sound = sound

self.setup()

def setup(self):
arcade.play_sound(self.sound.game_opening_sound)

self.cover_art_list = arcade.SpriteList()

# Create main title
Expand Down Expand Up @@ -64,4 +67,4 @@ def on_draw(self):
def on_key_release(self, key, _modifiers):
"""If the user releases the space key, start the game."""
if key == arcade.key.SPACE:
self.window.show_view(self.game_view)
self.window.show_view(self.game_view)

0 comments on commit d9cc8e3

Please sign in to comment.