Skip to content

Commit

Permalink
feat: speed up music with difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
bektaskemal committed Jan 14, 2024
1 parent 1afc405 commit bc301bc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
7 changes: 6 additions & 1 deletion default_bus_layout.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://dubjs00j6lieu"]
[gd_resource type="AudioBusLayout" load_steps=2 format=3 uid="uid://dubjs00j6lieu"]

[sub_resource type="AudioEffectPitchShift" id="AudioEffectPitchShift_8sw6g"]
resource_name = "PitchShift"

[resource]
bus/1/name = &"SFX"
Expand All @@ -13,3 +16,5 @@ bus/2/mute = false
bus/2/bypass_fx = false
bus/2/volume_db = 0.0
bus/2/send = &"Master"
bus/2/effect/0/effect = SubResource("AudioEffectPitchShift_8sw6g")
bus/2/effect/0/enabled = true
2 changes: 1 addition & 1 deletion scenes/UI/main_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="TileSet" uid="uid://bpbvmmyxq3bs1" path="res://resources/tileset.tres" id="1_caept"]
[ext_resource type="Script" path="res://scenes/UI/main_menu.gd" id="1_l2ekq"]
[ext_resource type="Texture2D" uid="uid://dgcelw7cn0vmt" path="res://assets/piper.png" id="3_ceqdi"]
[ext_resource type="Texture2D" uid="uid://xi6dl78fblle" path="res://assets/piper.png" id="3_ceqdi"]

[node name="MainMenu" type="CanvasLayer"]
script = ExtResource("1_l2ekq")
Expand Down
5 changes: 5 additions & 0 deletions scenes/autoload/game_events.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends Node
signal exp_vial_collected(value: float)
signal heal_vial_collected(value: float)
signal ability_upgrade_added(upgrade: AbilityUpgrade, current_upgrades: Dictionary)
signal difficulty_changed(value: float)

func emit_exp_vial_collected(value: float):
exp_vial_collected.emit(value)
Expand All @@ -12,3 +13,7 @@ func emit_heal_vial_collected(value: float):

func emit_ability_upgrade_added(upgrade: AbilityUpgrade, current_upgrades: Dictionary):
ability_upgrade_added.emit(upgrade, current_upgrades)

func emit_difficulty_changed(value: float):
difficulty_changed.emit(value)

13 changes: 13 additions & 0 deletions scenes/autoload/music_player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends AudioStreamPlayer

const SPEED_UP_FACTOR = 0.04

func _ready():
GameEvents.difficulty_changed.connect(on_new_difficulty)


func on_new_difficulty(difficulty: float):
pitch_scale = min(1.0 + (difficulty * SPEED_UP_FACTOR), 3.0)
var bus_pitch_effect = AudioServer.get_bus_effect(AudioServer.get_bus_index("Music"), 0)
bus_pitch_effect.pitch_scale = 1.0 / pitch_scale

4 changes: 3 additions & 1 deletion scenes/autoload/music_player.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://f18mif5mqetj"]
[gd_scene load_steps=3 format=3 uid="uid://f18mif5mqetj"]

[ext_resource type="AudioStream" uid="uid://b58s30aknuxhm" path="res://assets/audio/a-little-bird-shows-the-way.wav" id="1_lbsty"]
[ext_resource type="Script" path="res://scenes/autoload/music_player.gd" id="2_35173"]

[node name="MusicPlayer" type="AudioStreamPlayer"]
process_mode = 3
stream = ExtResource("1_lbsty")
volume_db = -15.0
autoplay = true
bus = &"Music"
script = ExtResource("2_35173")
1 change: 0 additions & 1 deletion scenes/game_objects/wizard_enemy/wizard_enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ healt_component = NodePath("../HealthComponent")
sprite = NodePath("../Visuals/Sprite2D")

[node name="RandomStreamPlayer2D" parent="." instance=ExtResource("9_5aymh")]
max_distance = 300.0
streams = Array[AudioStream]([ExtResource("10_v76po"), ExtResource("11_n7y1l"), ExtResource("12_yc033"), ExtResource("13_um576"), ExtResource("14_fy4md")])

[node name="HurtboxComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("8_wdfri")]
Expand Down
3 changes: 1 addition & 2 deletions scenes/main/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ experience_manager = NodePath("../ExperienceManager")

[node name="ArenaTimeManager" parent="." instance=ExtResource("2_33cn8")]

[node name="EnemyManager" parent="." node_paths=PackedStringArray("arena_time_manager") instance=ExtResource("2_dolxq")]
arena_time_manager = NodePath("../ArenaTimeManager")
[node name="EnemyManager" parent="." instance=ExtResource("2_dolxq")]

[node name="ExperienceManager" parent="." instance=ExtResource("4_vthcc")]

Expand Down
8 changes: 3 additions & 5 deletions scenes/manager/arena_time_manager.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extends Node
class_name ArenaTimeManager

signal arena_difficulty_inreased(difficulty: int)

@export var end_screen_scene: PackedScene

@onready var timer = $Timer as Timer
Expand All @@ -14,14 +12,14 @@ var endless_mode: bool = false

func _ready():
timer.timeout.connect(on_victory)
#if OS.has_feature("web"):
#timer.start(timer.wait_time*5/6)
GameEvents.difficulty_changed.emit(arena_difficulty)


func _process(delta):
if (timer.wait_time - timer.time_left) >= next_time_target:
next_time_target += DIFFICULTY_INTERVAL
arena_difficulty += 1
arena_difficulty_inreased.emit(arena_difficulty)
GameEvents.difficulty_changed.emit(arena_difficulty)

func on_endless_mode():
endless_mode = true
Expand Down
3 changes: 1 addition & 2 deletions scenes/manager/enemy_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ extends Node

@export var basic_enemy_scene: PackedScene
@export var wizard_enemy_scene: PackedScene
@export var arena_time_manager: ArenaTimeManager

@onready var timer = $Timer

Expand All @@ -21,7 +20,7 @@ var enemy_table = WeightedTable.new()
func _ready():
enemy_table.add_item(basic_enemy_scene)
timer.timeout.connect(spawn_enemy)
arena_time_manager.arena_difficulty_inreased.connect(on_new_difficulty)
GameEvents.difficulty_changed.connect(on_new_difficulty)
base_spawn_rate = 1/timer.wait_time
spawn_rate = 1/timer.wait_time

Expand Down

0 comments on commit bc301bc

Please sign in to comment.