forked from team-sg/hero-mark-2
All audio stuff moved to audio autoload and removed game.tscn in favor of just game.gd
This commit is contained in:
parent
30cfad6e7e
commit
e1a30188a6
21 changed files with 134 additions and 97 deletions
38
autoloads/audio.gd
Normal file
38
autoloads/audio.gd
Normal 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)
|
|
@ -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="."]
|
|
@ -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():
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue