adaptative music
This commit is contained in:
parent
25664e36f5
commit
5a768af1f3
9 changed files with 171 additions and 125 deletions
|
@ -2,7 +2,8 @@
|
|||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_llioc"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_hgmxv"]
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_shtld"]
|
||||
size = Vector3(20, 20, 20)
|
||||
|
||||
[node name="Platform" type="RigidBody3D"]
|
||||
axis_lock_linear_x = true
|
||||
|
@ -15,6 +16,8 @@ physics_material_override = SubResource("PhysicsMaterial_llioc")
|
|||
gravity_scale = 0.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_hgmxv")
|
||||
shape = SubResource("BoxShape3D_shtld")
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="."]
|
||||
use_collision = true
|
||||
size = Vector3(20, 20, 20)
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
[gd_scene format=3 uid="uid://b13nd5ibr7xvn"]
|
||||
|
||||
[node name="Platform2" type="CSGBox3D"]
|
||||
use_collision = true
|
|
@ -1,8 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bgtoke5v8cbwu"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_gkjw1"]
|
||||
|
||||
[node name="Platform3" type="RigidBody3D"]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_gkjw1")
|
|
@ -1,13 +1,94 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://df5m716pd6mej"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://df5m716pd6mej"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_vumbr"]
|
||||
bounce = 0.8
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_rvq6k"]
|
||||
script/source = "extends RigidBody3D
|
||||
|
||||
var stream_players: Array[AudioStreamPlayer] = []
|
||||
|
||||
func makeAudioStreamPlayers(music_name: String):
|
||||
var path: String = \"res://music/\" + music_name
|
||||
var dir: DirAccess = DirAccess.open(path)
|
||||
var file_paths: Array[String] = []
|
||||
|
||||
assert(dir, path + \" is not a valid path!\")
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != \"\":
|
||||
if !dir.current_is_dir():
|
||||
if file_name.ends_with(\".ogg\"):
|
||||
file_paths.push_back(path + \"/\" + file_name)
|
||||
file_name = dir.get_next()
|
||||
assert(len(file_paths), path + \" had no .ogg files!\")
|
||||
|
||||
var players: Array[AudioStreamPlayer] = []
|
||||
for file_path in file_paths:
|
||||
var stream: AudioStreamOggVorbis = AudioStreamOggVorbis.load_from_file(file_path)
|
||||
stream.loop = true
|
||||
stream.bpm = 124
|
||||
|
||||
var player: AudioStreamPlayer = AudioStreamPlayer.new()
|
||||
player.name = file_path.substr(10)
|
||||
player.stream = stream
|
||||
player.volume_db = -50
|
||||
players.push_back(player)
|
||||
add_child(player)
|
||||
|
||||
stream_players = players
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
makeAudioStreamPlayers(\"base\")
|
||||
for player in stream_players:
|
||||
player.play()
|
||||
|
||||
func handleMusicWithVelocity(velocity: float, delta: float) -> void:
|
||||
var instruments_needed = floor(velocity / 10)
|
||||
var instruments_playing = stream_players.filter(func(p: AudioStreamPlayer): return p.volume_db > -50)
|
||||
|
||||
for index_p in len(instruments_playing):
|
||||
var playing = instruments_playing[index_p]
|
||||
if index_p + 1 > instruments_needed:
|
||||
playing.volume_db -= delta * 32
|
||||
elif playing.volume_db <= 0:
|
||||
playing.volume_db += delta * 8
|
||||
|
||||
if instruments_needed > len(instruments_playing):
|
||||
var instruments_not_playing = stream_players.filter(func(p: AudioStreamPlayer): return p.volume_db <= -50)
|
||||
if len(instruments_not_playing):
|
||||
var to_play = instruments_not_playing.pick_random()
|
||||
if is_instance_valid(to_play):
|
||||
to_play.volume_db += delta * 16
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
for player in stream_players:
|
||||
if player.volume_db > 0:
|
||||
player.volume_db = 0
|
||||
var velocity: float = abs(self.linear_velocity.x) + abs(self.linear_velocity.y)
|
||||
handleMusicWithVelocity(velocity, delta)
|
||||
"
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_xfgrm"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_ggbpc"]
|
||||
colors = PackedColorArray(0.979416, 0, 0.376508, 1, 0, 0.583757, 0.65245, 1)
|
||||
|
||||
[sub_resource type="GradientTexture2D" id="GradientTexture2D_vxsyc"]
|
||||
gradient = SubResource("Gradient_ggbpc")
|
||||
fill_from = Vector2(0.490476, 0)
|
||||
fill_to = Vector2(0.504762, 1)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_14eku"]
|
||||
albedo_texture = SubResource("GradientTexture2D_vxsyc")
|
||||
|
||||
[node name="Sphere" type="RigidBody3D"]
|
||||
axis_lock_linear_z = true
|
||||
physics_material_override = SubResource("PhysicsMaterial_vumbr")
|
||||
script = SubResource("GDScript_rvq6k")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_xfgrm")
|
||||
|
@ -15,3 +96,4 @@ shape = SubResource("SphereShape3D_xfgrm")
|
|||
[node name="CSGSphere3D" type="CSGSphere3D" parent="."]
|
||||
radial_segments = 20
|
||||
rings = 10
|
||||
material = SubResource("StandardMaterial3D_14eku")
|
||||
|
|
4
idea.txt
4
idea.txt
|
@ -1,7 +1,9 @@
|
|||
Theme: Gravity
|
||||
|
||||
3D, but played in 2D (think New Super Mario Bros)
|
||||
1 control: With the mouse, change a slider to affect how much gravity is applied
|
||||
2 controls:
|
||||
With the mouse, change a slider to affect how much gravity is applied
|
||||
With the arrow keys, change the direction of the gravity
|
||||
1 objective: Bring the ball to the opposite end of the level
|
||||
|
||||
Music should be proportional to either the gravity or the ball's speed, or maybe how close to the objective it is, probably not that
|
||||
|
|
105
index.tscn
105
index.tscn
|
@ -1,50 +1,85 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ccgnnif026wb4"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ccgnnif026wb4"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dujoplhd35kqg" path="res://level_base.tscn" id="1_ad0pp"]
|
||||
[ext_resource type="PackedScene" uid="uid://gis4s061n422" path="res://elements/platform.tscn" id="2_g4sgl"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_oxyvh"]
|
||||
script/source = "extends Node
|
||||
|
||||
func makeAudioStreamPlayers(music_name: String) -> Array[AudioStreamPlayer]:
|
||||
var path: String = \"res://music/\" + music_name
|
||||
var dir: DirAccess = DirAccess.open(path)
|
||||
var file_paths: Array[String] = []
|
||||
|
||||
assert(dir, path + \" is not a valid path!\")
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != \"\":
|
||||
if !dir.current_is_dir():
|
||||
if file_name.ends_with(\".ogg\"):
|
||||
file_paths.push_back(path + \"/\" + file_name)
|
||||
file_name = dir.get_next()
|
||||
assert(len(file_paths), path + \" had no .ogg files!\")
|
||||
|
||||
var players: Array[AudioStreamPlayer] = []
|
||||
for file_path in file_paths:
|
||||
var stream: AudioStreamOggVorbis = AudioStreamOggVorbis.load_from_file(file_path)
|
||||
stream.loop = true
|
||||
stream.bpm = 124
|
||||
|
||||
var player: AudioStreamPlayer = AudioStreamPlayer.new()
|
||||
player.stream = stream
|
||||
player.volume_db = -50
|
||||
players.push_back(player)
|
||||
|
||||
return players
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var players = makeAudioStreamPlayers(\"base\")
|
||||
for player in players:
|
||||
add_child(player)
|
||||
#player.volume_db = 0
|
||||
for player in players:
|
||||
player.play()
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
#print($LevelBase/Sphere.position)
|
||||
pass
|
||||
|
||||
|
||||
func _on_h_slider_value_changed(value: float) -> void:
|
||||
print(value)
|
||||
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, value)
|
||||
|
||||
func _unhandled_key_input(ev: InputEvent) -> void:
|
||||
if ev is InputEventKey:
|
||||
var k = ev.keycode
|
||||
if k == KEY_UP or k == KEY_RIGHT or k == KEY_LEFT or k == KEY_DOWN:
|
||||
var direction = Vector3()
|
||||
if k == KEY_UP:
|
||||
direction = Vector3.UP
|
||||
elif k == KEY_LEFT:
|
||||
direction = Vector3.LEFT
|
||||
elif k == KEY_RIGHT:
|
||||
direction = Vector3.RIGHT
|
||||
elif k == KEY_DOWN:
|
||||
direction = Vector3.DOWN
|
||||
PhysicsServer3D.area_set_param(
|
||||
get_viewport().find_world_3d().space,
|
||||
PhysicsServer3D.AREA_PARAM_GRAVITY_VECTOR,
|
||||
direction
|
||||
)
|
||||
print(\"direction is \", direction)
|
||||
|
||||
|
||||
func _on_h_slider_focus_entered() -> void:
|
||||
$HSlider.release_focus()
|
||||
pass # Replace with function body.
|
||||
"
|
||||
|
||||
[node name="World" type="Node"]
|
||||
[node name="Game" type="Node"]
|
||||
script = SubResource("GDScript_oxyvh")
|
||||
|
||||
[node name="LevelBase" parent="." instance=ExtResource("1_ad0pp")]
|
||||
|
||||
[node name="Platform" parent="LevelBase" instance=ExtResource("2_g4sgl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -13.7254, 0)
|
||||
|
||||
[node name="Platform2" parent="LevelBase" instance=ExtResource("2_g4sgl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -42.8526, -13.7254, 0)
|
||||
|
||||
[node name="Platform3" parent="LevelBase" instance=ExtResource("2_g4sgl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 44.7108, -13.7254, 0)
|
||||
|
||||
[node name="HSlider" type="HSlider" parent="."]
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.2
|
||||
anchor_top = 0.9
|
||||
anchor_right = 0.8
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -0.00012207
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 1
|
||||
min_value = 10.0
|
||||
max_value = 20.0
|
||||
step = 0.2
|
||||
value = 10.0
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[connection signal="focus_entered" from="HSlider" to="." method="_on_h_slider_focus_entered"]
|
||||
[connection signal="value_changed" from="HSlider" to="." method="_on_h_slider_value_changed"]
|
||||
|
||||
[editable path="LevelBase"]
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dujoplhd35kqg"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dujoplhd35kqg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://df5m716pd6mej" path="res://elements/sphere.tscn" id="1_8mffa"]
|
||||
[ext_resource type="PackedScene" uid="uid://gis4s061n422" path="res://elements/platform.tscn" id="2_bei4m"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_hbi5e"]
|
||||
script/source = "extends Node3D
|
||||
|
@ -14,8 +13,7 @@ func _ready() -> void:
|
|||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
print($Sphere.position)
|
||||
pass
|
||||
$Camera3D.position = $Sphere.position + Vector3(0, 0, 20)
|
||||
"
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_6pkua"]
|
||||
|
@ -32,10 +30,7 @@ sky = SubResource("Sky_4du2k")
|
|||
ambient_light_source = 3
|
||||
ambient_light_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_s5ay6"]
|
||||
size = Vector3(180, 1, 1)
|
||||
|
||||
[node name="TestLevel" type="Node3D"]
|
||||
[node name="LevelBase" type="Node3D"]
|
||||
script = SubResource("GDScript_hbi5e")
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
|
@ -43,17 +38,5 @@ environment = SubResource("Environment_jfl74")
|
|||
|
||||
[node name="Sphere" parent="." instance=ExtResource("1_8mffa")]
|
||||
|
||||
[node name="Platform" parent="." instance=ExtResource("2_bei4m")]
|
||||
transform = Transform3D(0.985642, 0.168851, 0, -0.145861, 0.851441, -0.503759, -0.08506, 0.496526, 0.863844, 0, -1.49811, 0)
|
||||
|
||||
[node name="CollisionShape3D" parent="Platform" index="0"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0270482, 0)
|
||||
shape = SubResource("BoxShape3D_s5ay6")
|
||||
|
||||
[node name="CSGBox3D" parent="Platform" index="1"]
|
||||
size = Vector3(180, 1, 1)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 15.1993)
|
||||
|
||||
[editable path="Platform"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.534398)
|
|
@ -14,7 +14,7 @@ config/name="AlakajamEntry"
|
|||
config/description="I'm Taevas, and this is my entry for the 21st edition of \"Alakajam!\", a gamejam that lasts for 48 hours that starts on 2025-02-21 19:00UTC
|
||||
https://alakajam.com/21st-alakajam"
|
||||
config/version="20250221.0"
|
||||
run/main_scene="res://test_level.tscn"
|
||||
run/main_scene="res://index.tscn"
|
||||
config/features=PackedStringArray("4.3", "GL Compatibility")
|
||||
boot_splash/show_image=false
|
||||
config/icon="res://icon.svg"
|
||||
|
@ -23,6 +23,10 @@ config/icon="res://icon.svg"
|
|||
|
||||
buses/default_bus_layout=""
|
||||
|
||||
[physics]
|
||||
|
||||
3d/default_gravity=10.0
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
|
|
51
test.tscn
51
test.tscn
|
@ -1,51 +0,0 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://dadwk81skcmby"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://gis4s061n422" path="res://elements/platform.tscn" id="1_gkiic"]
|
||||
[ext_resource type="PackedScene" uid="uid://df5m716pd6mej" path="res://elements/sphere.tscn" id="2_71dxp"]
|
||||
[ext_resource type="PackedScene" uid="uid://b13nd5ibr7xvn" path="res://elements/platform2.tscn" id="3_g25lt"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_eib6h"]
|
||||
script/source = "extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
print($Sphere.position)
|
||||
pass
|
||||
"
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4eek5"]
|
||||
size = Vector3(1, 4, 1)
|
||||
|
||||
[node name="Test" type="Node3D"]
|
||||
script = SubResource("GDScript_eib6h")
|
||||
|
||||
[node name="Platform" parent="." instance=ExtResource("1_gkiic")]
|
||||
transform = Transform3D(0.14385, -0.58711, 0.796624, 0.988674, 0.120067, -0.0900406, -0.0427843, 0.800554, 0.597732, 3.00454, -1.58701, 0)
|
||||
|
||||
[node name="CollisionShape3D" parent="Platform" index="0"]
|
||||
transform = Transform3D(1.00001, -1.03377e-07, 3.35276e-07, 2.14204e-07, 1, -7.45058e-07, -4.47035e-08, -5.96046e-08, 1.00001, 0, 0, 0)
|
||||
shape = SubResource("BoxShape3D_4eek5")
|
||||
|
||||
[node name="CSGBox3D" parent="Platform" index="1"]
|
||||
transform = Transform3D(1.00001, -1.03377e-07, 3.35276e-07, 2.32831e-07, 1, -7.7486e-07, -4.47035e-08, -5.96046e-08, 1.00001, 0, 0, 0)
|
||||
size = Vector3(1, 4, 1)
|
||||
|
||||
[node name="Sphere" parent="." instance=ExtResource("2_71dxp")]
|
||||
|
||||
[node name="SpotLight3D" type="SpotLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -0.0889117, 0.99604, 0, -0.99604, -0.0889117, 0, 0.904974, 0)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.58526)
|
||||
|
||||
[node name="Platform2" parent="." instance=ExtResource("3_g25lt")]
|
||||
transform = Transform3D(0.895688, 0.444682, 0, -0.444682, 0.895688, 0, 0, 0, 1, 0.113522, -0.705501, 0)
|
||||
size = Vector3(2.45691, 1, 1)
|
||||
|
||||
[editable path="Platform"]
|
Loading…
Add table
Add a link
Reference in a new issue