Implement music playing for slow and normal

This commit is contained in:
Matteo Tietz 2024-04-20 19:05:32 +02:00
parent 3988fc3ff0
commit af92ebff4b
5 changed files with 61 additions and 10 deletions

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=22 format=2]
[gd_scene load_steps=24 format=2]
[ext_resource path="res://3d_platforma/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Music/slow track.wav" type="AudioStream" id=2]
[ext_resource path="res://scripts/Library/Actions/Snare Admiral 2.wav" type="AudioStream" id=3]
[ext_resource path="res://3d_platforma/sqare_norm.png" type="Texture" id=4]
[ext_resource path="res://3d_platforma/texture_08.png" type="Texture" id=5]
@ -13,6 +14,7 @@
[ext_resource path="res://scripts/RegisterAudioStreamPlayerSlow.gd" type="Script" id=12]
[ext_resource path="res://scripts/RegisterAudioStreamPlayerFast.gd" type="Script" id=13]
[ext_resource path="res://scripts/RegisterAudioStreamPlayerNormal.gd" type="Script" id=14]
[ext_resource path="res://Music/godot-project-hiphop.wav" type="AudioStream" id=15]
[sub_resource type="SpatialMaterial" id=36]
resource_name = "CheckerGrid"
@ -215,7 +217,7 @@ autoplay = "move"
anims/move = SubResource( 37 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 5, 0 )
transform = Transform( 0.707107, -0.5, 0.5, 0.00134521, 0.708057, 0.706154, -0.707106, -0.498654, 0.501344, 0, 5, 0 )
light_energy = 0.65
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
@ -241,18 +243,20 @@ script = ExtResource( 1 )
script = ExtResource( 1 )
[node name="TapeFast" parent="." instance=ExtResource( 9 )]
transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, -1.34058, 6, -1.25926 )
transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, -1.34058, 0.785612, -1.25926 )
[node name="TapeNormal" parent="." instance=ExtResource( 10 )]
transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0.518271, 6, -1.35086 )
transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0.518271, 0.785612, -1.35086 )
[node name="TapeSlow" parent="." instance=ExtResource( 11 )]
transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, -0.06, 0.7, -6.3138 )
[node name="AudioStreamPlayer3DSlow" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource( 2 )
script = ExtResource( 12 )
[node name="AudioStreamPlayer3DNormal" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource( 15 )
script = ExtResource( 14 )
[node name="AudioStreamPlayer3DFast" type="AudioStreamPlayer3D" parent="."]

BIN
Music/slow track.wav Normal file

Binary file not shown.

View File

@ -19,6 +19,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://scripts/Library/Actions/ActionList.gd"
}, {
"base": "Node",
"class": "MusicChangedSlowAction",
"language": "GDScript",
"path": "res://scripts/Library/Actions/MusicChangedSlowAction.gd"
}, {
"base": "Action",
"class": "PlaySound",
"language": "GDScript",
@ -45,6 +50,11 @@ _global_script_classes=[ {
"path": "res://scripts/Library/Actions/TriggerBase.gd"
}, {
"base": "TriggerBase",
"class": "TriggerOnCollision",
"language": "GDScript",
"path": "res://scripts/Library/Actions/TriggerOnCollision.gd"
}, {
"base": "TriggerBase",
"class": "TriggerOnReady",
"language": "GDScript",
"path": "res://scripts/Library/Actions/TriggerOnReady.gd"
@ -52,11 +62,13 @@ _global_script_classes=[ {
_global_script_class_icons={
"Action": "",
"ActionList": "",
"MusicChangedSlowAction": "",
"PlaySound": "",
"SetFastMusic": "",
"SetNormalMusic": "",
"SetSlowMusic": "",
"TriggerBase": "",
"TriggerOnCollision": "",
"TriggerOnReady": ""
}

View File

@ -0,0 +1,10 @@
class_name MusicChangedSlowAction extends Node
func _ready():
MusicSingleton.register_change_action(self)
func _exit_tree():
MusicSingleton.unregister_change_action(self)
func execute() -> void:
print("Executed OnMusicChangedSlowAction")

View File

@ -21,24 +21,49 @@ func setNormalMusic():
setMusicType( 0 )
func setMusicType( type:int ):
print("Set Music type")
musicType = type;
if type == 0:
gameSpeed = 0
# current_playback_position : float = 0.0
# if current_audio_player:
# current_audio_player.stop()
# current_playback_position = current_audio_player.get_playback_position()
# current_playback_position = current_audio_player.get_playback_position()
# current_playback_position = current_audio_player.get_playback_position()
var current_playback_position : float = 0.0
print("Set Music type normal")
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_normal
current_audio_player.play(current_playback_position)
if type == 1:
gameSpeed = 2
var current_playback_position : float = 0.0
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_fast
current_audio_player.play(current_playback_position)
if type == -1:
print("Set Music type slow")
gameSpeed = 0.5
var current_playback_position : float = 0.0
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_slow
current_audio_player.play(current_playback_position)
func register_change_action(change_action : Node) -> void:
print("Registered change action")