All audio stuff moved to audio autoload and removed game.tscn in favor of just game.gd

This commit is contained in:
pennyrigate 2023-02-25 23:44:13 -05:00
parent 30cfad6e7e
commit e1a30188a6
21 changed files with 134 additions and 97 deletions

38
autoloads/audio.gd Normal file
View file

@ -0,0 +1,38 @@
extends Node
#Audio Channels
onready var ac_jump = $JumpSound
onready var ac_collectible = $CollecitbleSound
onready var ac_climb = $ClimbSound
onready var ac_die = $DieSound
onready var ac_music = $Music
onready var ac_cheat = $CodeEntrySound
onready var ac_boss = $BossSound
#Sounds
const a_gold = preload("res://audio/sounds/gold.wav")
const a_arrow = preload("res://audio/sounds/a_egg_collect.ogg")
const a_jump = preload("res://audio/sounds/jump.ogg")
const a_star = preload("res://audio/sounds/a_jinjo.ogg")
const a_shard = preload("res://audio/sounds/shard.wav")
const a_climb_up = preload("res://audio/sounds/a_climb.ogg")
const a_climb_down = preload("res://audio/sounds/a_bmilc.ogg")
const a_sword = preload("res://audio/sounds/sword.ogg")
const a_doublejump = preload("res://audio/sounds/a_bree.wav")
const a_shoot = preload("res://audio/sounds/a_egg_shoot.ogg")
const a_die = preload("res://audio/sounds/die.wav")
const a_die_skeleton = preload("res://audio/sounds/die_skeleton.wav")
const a_scrump_die = preload("res://audio/sounds/scrump_die.wav")
const a_die_robot = preload("res://audio/sounds/die_robot.wav")
const a_gover = preload("res://audio/sounds/gover.wav")
const a_boss_hurt = preload("res://audio/sounds/boss_hurt.wav")
#Plays a sound
func play_sound(snd,player):
player.set_stream(snd)
player._set_playing(true)
#Play music, if same track is already playing do nothing
func play_music(song):
if Audio.ac_music.stream != song or Audio.ac_music.playing == false:
play_sound(song,ac_music)

View file

@ -1,9 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://autoloads/game.gd" type="Script" id=1]
[ext_resource path="res://autoloads/audio.gd" type="Script" id=1]
[node name="Game" type="Node"]
pause_mode = 2
[node name="Audio" type="Node"]
script = ExtResource( 1 )
[node name="Music" type="AudioStreamPlayer" parent="."]

View file

@ -98,7 +98,7 @@ func _input(event):
_on_entry()
func _on_entry():
Game.play_sound(Game.a_star, Game.ac_cheat)
Audio.play_sound(Audio.a_star, Audio.ac_cheat)
Game.can_pause = false
func _enter_code():

View file

@ -17,31 +17,6 @@ var high_score = 0
var lives = 2
var deaths = 0
var time = 0.0
#Audio Channels
onready var ac_jump = $JumpSound
onready var ac_collectible = $CollecitbleSound
onready var ac_climb = $ClimbSound
onready var ac_die = $DieSound
onready var ac_music = $Music
onready var ac_cheat = $CodeEntrySound
onready var ac_boss = $BossSound
#Sounds
const a_gold = preload("res://audio/sounds/gold.wav")
const a_arrow = preload("res://audio/sounds/a_egg_collect.ogg")
const a_jump = preload("res://audio/sounds/jump.ogg")
const a_star = preload("res://audio/sounds/a_jinjo.ogg")
const a_shard = preload("res://audio/sounds/shard.wav")
const a_climb_up = preload("res://audio/sounds/a_climb.ogg")
const a_climb_down = preload("res://audio/sounds/a_bmilc.ogg")
const a_sword = preload("res://audio/sounds/sword.ogg")
const a_doublejump = preload("res://audio/sounds/a_bree.wav")
const a_shoot = preload("res://audio/sounds/a_egg_shoot.ogg")
const a_die = preload("res://audio/sounds/die.wav")
const a_die_skeleton = preload("res://audio/sounds/die_skeleton.wav")
const a_scrump_die = preload("res://audio/sounds/scrump_die.wav")
const a_die_robot = preload("res://audio/sounds/die_robot.wav")
const a_gover = preload("res://audio/sounds/gover.wav")
const a_boss_hurt = preload("res://audio/sounds/boss_hurt.wav")
#Objects
const block_text = preload("res://objects/hud/blocktext.tscn")
const pause_screen = preload("res://objects/hud/pause_screen.tscn")
@ -64,11 +39,6 @@ func instance_node(node:PackedScene,x:float,y:float,parent):
Instance.global_position = Vector2(x,y)
parent.add_child(Instance)
#Plays a sound
func play_sound(snd,player):
player.set_stream(snd)
player._set_playing(true)
#Get position in sectors
func get_sector(pos):
return (pos / resolution).floor()
@ -92,14 +62,14 @@ func change_map(map):
#Clear data
func clear_collectibles():
Game.score = 0
Game.golds = 0
Game.stars = [false,false,false,false,false]
Game.shards = 0
Game.shards_collected = [false,false,false,false,false,false,false,false,false,false]
Game.arrows = 0
Game.lives = 2
Game.deaths = 0
score = 0
golds = 0
stars = [false,false,false,false,false]
shards = 0
shards_collected = [false,false,false,false,false,false,false,false,false,false]
arrows = 0
lives = 2
deaths = 0
#Save
func save():
@ -134,20 +104,20 @@ func timeify(input):
#Restart level
func restart_level():
if Game.score > Game.high_score: Game.high_score = Game.score
Game.score = 0
Game.golds = 0
Game.stars = [false,false,false,false,false]
Game.shards = 0
Game.arrows = 0
Game.lives = 2
Game.ac_climb.stop()
Game.ac_die.stop()
if score > high_score: high_score = score
score = 0
golds = 0
stars = [false,false,false,false,false]
shards = 0
arrows = 0
lives = 2
Audio.ac_climb.stop()
Audio.ac_die.stop()
Engine.time_scale = 1.0
for tween in get_tree().get_processed_tweens():
tween.kill()
Game.change_map(load(Game.get_map().filename))
ac_music.stream_paused = false
change_map(load(get_map().filename))
Audio.ac_music.stream_paused = false
#Freeze frame
func freeze_frame(time):
@ -158,12 +128,7 @@ func freeze_frame(time):
#Check if 100%ed
func has_collection_bonus():
return Game.shards == 5 && Game.golds == 50
#Play music, if same track is already playing do nothing
func play_music(song):
if Game.ac_music.stream != song or Game.ac_music.playing == false:
play_sound(song,ac_music)
return shards == 5 && golds == 50
func _physics_process(delta):
if Debug.entry == false:

BIN
graphics/enemy/big_saw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/big_saw.png-a44e3977b56835f580fa101393440339.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/enemy/big_saw.png"
dest_files=[ "res://.import/big_saw.png-a44e3977b56835f580fa101393440339.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -33,7 +33,7 @@ export var target_time_any = 0
func _ready():
Game.fade.fade_in(0.000000000000001)
change_current_level(Game.current_level)
Game.ac_music.stop()
Audio.ac_music.stop()
func _physics_process(delta):
if Input.is_action_just_pressed("ui_up"): change_current_level(-1)

View file

@ -14,7 +14,7 @@ func _ready():
Game.fade.fade_in(0.4)
Game.fade.connect("fade_finished", get_tree(), "set_pause", [false], CONNECT_ONESHOT)
Game.fade.connect("fade_finished", Game, "set", ["can_pause", true], CONNECT_ONESHOT)
Game.play_music(music)
Audio.play_music(music)
func _physics_process(delta):
if Game.golds == 50 && Game.shards == 5:

View file

@ -169,7 +169,6 @@ material = SubResource( 4 )
position = Vector2( 120, 168 )
z_index = -3
frames = SubResource( 5 )
frame = 1
playing = true
[node name="SawTest4" type="AnimatedSprite" parent="."]
@ -177,6 +176,7 @@ material = SubResource( 4 )
position = Vector2( 160, 168 )
z_index = -3
frames = SubResource( 5 )
frame = 1
playing = true
[node name="SawTest5" type="AnimatedSprite" parent="."]
@ -184,6 +184,7 @@ material = SubResource( 4 )
position = Vector2( 56, 176 )
z_index = -3
frames = SubResource( 5 )
frame = 1
playing = true
[node name="RollingFiend" parent="." instance=ExtResource( 22 )]
@ -191,14 +192,12 @@ position = Vector2( 48, 120 )
[node name="AnimatedSprite" parent="RollingFiend" index="0"]
visible = false
frame = 0
[node name="SawTest2" type="AnimatedSprite" parent="RollingFiend"]
material = SubResource( 4 )
position = Vector2( 4, 4 )
z_index = -3
frames = SubResource( 5 )
frame = 1
playing = true
[editable path="RollingFiend"]

View file

@ -7,5 +7,5 @@ func _on_Area2D_area_entered(area):
if area.is_in_group("player"):
Game.arrows += value
Game.score += 25
Game.play_sound(Game.a_arrow,Game.ac_collectible)
Audio.play_sound(Audio.a_arrow,Audio.ac_collectible)
queue_free()

View file

@ -11,5 +11,5 @@ func _on_Area2D_area_entered(area):
if area.is_in_group("player"):
Game.golds += value
Game.score += 5
Game.play_sound(Game.a_gold,Game.ac_collectible)
Audio.play_sound(Audio.a_gold,Audio.ac_collectible)
queue_free()

View file

@ -9,9 +9,9 @@ func _ready():
func _on_Area2D_area_entered(area):
#Collect
if area.is_in_group("player"):
Game.ac_music.stream_paused = true
Game.play_sound(Game.a_shard,Game.ac_collectible)
Game.ac_collectible.connect("finished", Game.ac_music, "set_stream_paused", [false])
Audio.ac_music.stream_paused = true
Audio.play_sound(Audio.a_shard,Audio.ac_collectible)
Audio.ac_collectible.connect("finished", Audio.ac_music, "set_stream_paused", [false])
Game.score += 500
Game.shards += value
Game.shards_collected[number] = true

View file

@ -23,12 +23,12 @@ func _ready():
func _on_Area2D_area_entered(area):
#Collect
if area.is_in_group("player"):
Game.play_sound(Game.a_star,Game.ac_collectible)
Audio.play_sound(Audio.a_star,Audio.ac_collectible)
Game.score += 100
Game.stars[color] = true
#5 Star reward
if Game.stars[0] && Game.stars[1] && Game.stars[2] && Game.stars[3] && Game.stars[4]:
Game.play_sound(Game.a_shard,Game.ac_collectible)
Audio.play_sound(Audio.a_shard,Audio.ac_collectible)
Game.shards += 1
Game.shards_collected[4] = true
Game.score += 500

View file

@ -29,7 +29,7 @@ func _on_ShootTimer_timeout():
func die():
hp -= 1
Game.play_sound(Game.a_boss_hurt,Game.ac_boss)
Audio.play_sound(Audio.a_boss_hurt,Audio.ac_boss)
match hp:
2:
emit_signal("entered_phase", 2)
@ -41,7 +41,7 @@ func die():
shoot_time = Vector2(0.3,0.5)
0:
Game.instance_node(Gore,position.x,position.y,map)
Game.play_sound(Game.a_scrump_die,Game.ac_boss)
Audio.play_sound(Audio.a_scrump_die,Audio.ac_boss)
emit_signal("entered_phase",4)
queue_free()

View file

@ -21,7 +21,7 @@ signal died()
export var score_for_killing = 0
export var blood = true
var death_sound = Game.a_die
var death_sound = Audio.a_die
var death_blood_offset = Vector2.ZERO
func _on_Hitbox_area_entered(area):
@ -36,7 +36,7 @@ func die():
death_particles.emitting = true
get_parent().add_child(death_particles)
Game.play_sound(death_sound, Game.ac_die)
Audio.play_sound(death_sound, Audio.ac_die)
Game.score += score_for_killing
emit_signal("died")
queue_free()

View file

@ -12,7 +12,7 @@ export(int, "Left To Right", "Right To Left") var move_direction
onready var startpos = position
func _ready():
death_sound = Game.a_die_robot
death_sound = Audio.a_die_robot
up_boundary *= 8
down_boundary *= 8
#Move in direction selected

View file

@ -2,7 +2,7 @@ extends "res://objects/enemy/enemy.gd"
func _ready():
$AnimatedSprite.play("explode")
Game.play_sound(Game.a_die_robot,Game.ac_die)
Audio.play_sound(Audio.a_die_robot,Audio.ac_die)
func _on_animation_finished():
queue_free()

View file

@ -17,7 +17,7 @@ onready var arrow_spawn_l = $ArrowSpawnL
onready var arrow_spawn_r = $ArrowSpawnR
func _ready():
death_sound = Game.a_die_skeleton
death_sound = Audio.a_die_skeleton
timer.start(shoot_time)
func _on_Timer_timeout():

View file

@ -35,4 +35,4 @@ func _physics_process(delta):
bullet.direction = bullet.direction.rotated(rand_range(-bullet_spread, bullet_spread))
bullet.speed = bullet_speed
get_parent().call_deferred("add_child", bullet)
Game.play_sound(Game.a_arrow, Game.ac_climb)
Audio.play_sound(Audio.a_arrow, Audio.ac_climb)

View file

@ -125,7 +125,7 @@ func _process_idle_walk():
check_jump()
#Goto Sword
if Debug.allow_sword && Input.is_action_just_pressed("sword"):
Game.play_sound(Game.a_sword,Game.ac_jump)
Audio.play_sound(Audio.a_sword,Audio.ac_jump)
current_state = State.SWORD
return
#Goto Shoot
@ -164,25 +164,25 @@ func _process_climb():
position.y += axis.y * 0.65
#Sound
if axis.y == -1:
if Game.ac_climb.get_stream() != Game.a_climb_up: Game.play_sound(Game.a_climb_up,Game.ac_climb)
if Audio.ac_climb.get_stream() != Audio.a_climb_up: Audio.play_sound(Audio.a_climb_up,Audio.ac_climb)
if axis.y == 1:
if Game.ac_climb.get_stream() != Game.a_climb_down: Game.play_sound(Game.a_climb_down,Game.ac_climb)
if axis.y == 0: Game.ac_climb.set_stream(null)
if Audio.ac_climb.get_stream() != Audio.a_climb_down: Audio.play_sound(Audio.a_climb_down,Audio.ac_climb)
if axis.y == 0: Audio.ac_climb.set_stream(null)
#Manual Jump,, only works when holding neutral or away from ladder
if axis.x != sprite.scale.x && Input.is_action_just_pressed("jump"):
position.x -= sprite.scale.x * 3
velocity.y = -jump_force
anims.set_speed_scale(1)
current_state = State.FALL
Game.ac_climb.set_stream(null)
Audio.ac_climb.set_stream(null)
return
if climb_ray.get_collider() == null:
if axis.y == -1:
#Auto Jump
velocity.y = -jump_force
Game.play_sound(Game.a_jump,Game.ac_jump)
Audio.play_sound(Audio.a_jump,Audio.ac_jump)
#Auto dismount
Game.ac_climb.set_stream(null)
Audio.ac_climb.set_stream(null)
current_state = State.FALL
return
#Side dismount
@ -190,7 +190,7 @@ func _process_climb():
position.x -= sprite.scale.x * 3
current_state = State.FALL
anims.set_speed_scale(1)
Game.ac_climb.set_stream(null)
Audio.ac_climb.set_stream(null)
return
@ -217,7 +217,7 @@ func _process_transport(delta):
position += transport_direction * transport_speed * delta
func spawn_arrow():
Game.play_sound(Game.a_shoot,Game.ac_jump)
Audio.play_sound(Audio.a_shoot,Audio.ac_jump)
var arrow = ArrowProjectile.instance()
arrow.global_position = Vector2(
global_position.x + arrowpos.x * sprite.scale.x,
@ -231,7 +231,7 @@ func check_jump():
if Input.is_action_just_pressed("jump"):
#Detach ladder
if current_state == State.CLIMB:
Game.ac_climb.set_stream(null) # stop climb sound
Audio.ac_climb.set_stream(null) # stop climb sound
position.x -= sprite.scale.x * 3
else:
dust_particles.restart()
@ -242,7 +242,7 @@ func check_jump():
velocity.y = 0
jump_pressure = 0
current_state = State.JUMP
Game.play_sound(Game.a_jump,Game.ac_jump)
Audio.play_sound(Audio.a_jump,Audio.ac_jump)
anims.play("jump")
velocity.y = -jump_force
move(walk_speed,0,true)
@ -251,7 +251,7 @@ func check_double_jump():
if is_on_floor():
check_jump()
if Input.is_action_just_pressed("jump") && can_doublejump:
Game.play_sound(Game.a_doublejump,Game.ac_jump)
Audio.play_sound(Audio.a_doublejump,Audio.ac_jump)
can_doublejump = false
velocity.y = -doublejump_force
anims.play("doublejump")
@ -300,7 +300,7 @@ func exit_transport():
func die():
if can_die:
Game.ac_climb.set_stream(null) # stop climbing sound\
Audio.ac_climb.set_stream(null) # stop climbing sound\
#If the player is already dead, don't kill them again
if current_state == State.INACTIVE:
return
@ -319,11 +319,11 @@ func die():
new_particles.lifetime = 0.45
new_particles.speed_scale = 1.5
current_state = State.INACTIVE # Set to state where player is not controllable
Game.play_sound(Game.a_gover, Game.ac_die)
Audio.play_sound(Audio.a_gover, Audio.ac_die)
#Slow down time
var time_tween = get_tree().create_tween()
time_tween.tween_property(Engine, "time_scale", 0.1, 0.3)
Game.ac_music.stream_paused = true
Audio.ac_music.stream_paused = true
yield(time_tween, "finished") #Resume from freeze frame
yield(get_tree().create_timer(1.0 * 0.1), "timeout")
Game.call_deferred("restart_level")
@ -331,7 +331,7 @@ func die():
#Die
Game.lives -= 1
Game.deaths += 1
Game.play_sound(Game.a_die, Game.ac_die)
Audio.play_sound(Audio.a_die, Audio.ac_die)
yield(Game.freeze_frame(0.3), "timeout")
#Reduce points if playing in infinite lives mode
if Game.use_lives == false && Game.lives < 0:

View file

@ -26,10 +26,11 @@ config/icon="res://icon.png"
[autoload]
Game="*res://autoloads/game.tscn"
Debug="*res://autoloads/debug.tscn"
Game="*res://autoloads/game.gd"
Audio="*res://autoloads/audio.tscn"
LevelData="*res://autoloads/level_data.tscn"
Save="*res://autoloads/save.gd"
Debug="*res://autoloads/debug.tscn"
[display]