Skip to content

Commit

Permalink
Added dynamic music.
Browse files Browse the repository at this point in the history
  • Loading branch information
V-ktor committed Jun 18, 2018
1 parent 0ac3647 commit 9ca2d8c
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

A card game made for Godot Community Game Jam - June 2018.
In this card game the key attribute is the temperature of the cards. Every creature has a temperature and can only attack and destroy weaker creatures of the opposite element. Therefore the temperature attribute serves as combined attack and defense value.

Binary file added music/ambience.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/ambience.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/ambience.ogg-b69266e913304b8509686f2249e54cb2.oggstr"

[deps]

source_file="res://music/ambience.ogg"
dest_files=[ "res://.import/ambience.ogg-b69266e913304b8509686f2249e54cb2.oggstr" ]

[params]

loop=true
loop_offset=0
Binary file added music/chill.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/chill.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/chill.ogg-c478e675a0c659f00017d7674c3fa62e.oggstr"

[deps]

source_file="res://music/chill.ogg"
dest_files=[ "res://.import/chill.ogg-c478e675a0c659f00017d7674c3fa62e.oggstr" ]

[params]

loop=true
loop_offset=0
Binary file added music/cold.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/cold.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/cold.ogg-cfdeb3e15cfae43e1be177d704c50586.oggstr"

[deps]

source_file="res://music/cold.ogg"
dest_files=[ "res://.import/cold.ogg-cfdeb3e15cfae43e1be177d704c50586.oggstr" ]

[params]

loop=true
loop_offset=0
Binary file added music/hot.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/hot.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/hot.ogg-780472b23c6f761c757327fb331463f7.oggstr"

[deps]

source_file="res://music/hot.ogg"
dest_files=[ "res://.import/hot.ogg-780472b23c6f761c757327fb331463f7.oggstr" ]

[params]

loop=true
loop_offset=0
2 changes: 2 additions & 0 deletions music/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright: Viktor Hahn
License: CC0
Binary file added music/warm.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/warm.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/warm.ogg-df9740a16819930c87dcd66e4a2fbbfc.oggstr"

[deps]

source_file="res://music/warm.ogg"
dest_files=[ "res://.import/warm.ogg-df9740a16819930c87dcd66e4a2fbbfc.oggstr" ]

[params]

loop=true
loop_offset=0
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Cards="*res://scripts/autoload/cards.gd"
Main="*res://scenes/autoload/main.tscn"
UI="*res://scenes/autoload/ui.tscn"
AI="*res://scripts/autoload/ai.gd"
Music="*res://scenes/autoload/music.tscn"

[importer_defaults]

Expand Down
59 changes: 59 additions & 0 deletions scenes/autoload/music.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[gd_scene load_steps=7 format=2]

[ext_resource path="res://scripts/main/music.gd" type="Script" id=1]
[ext_resource path="res://music/ambience.ogg" type="AudioStream" id=2]
[ext_resource path="res://music/cold.ogg" type="AudioStream" id=3]
[ext_resource path="res://music/chill.ogg" type="AudioStream" id=4]
[ext_resource path="res://music/warm.ogg" type="AudioStream" id=5]
[ext_resource path="res://music/hot.ogg" type="AudioStream" id=6]

[node name="Music" type="Node" index="0"]

script = ExtResource( 1 )

[node name="Ambience" type="AudioStreamPlayer" parent="." index="0"]

stream = ExtResource( 2 )
volume_db = 0.0
pitch_scale = 1.0
autoplay = true
mix_target = 0
bus = "Master"

[node name="Cold1" type="AudioStreamPlayer" parent="." index="1"]

stream = ExtResource( 3 )
volume_db = -80.0
pitch_scale = 1.0
autoplay = true
mix_target = 0
bus = "Master"

[node name="Cold2" type="AudioStreamPlayer" parent="." index="2"]

stream = ExtResource( 4 )
volume_db = -80.0
pitch_scale = 1.0
autoplay = true
mix_target = 0
bus = "Master"

[node name="Warm1" type="AudioStreamPlayer" parent="." index="3"]

stream = ExtResource( 5 )
volume_db = -80.0
pitch_scale = 1.0
autoplay = true
mix_target = 0
bus = "Master"

[node name="Warm2" type="AudioStreamPlayer" parent="." index="4"]

stream = ExtResource( 6 )
volume_db = -80.0
pitch_scale = 1.0
autoplay = true
mix_target = 0
bus = "Master"


2 changes: 2 additions & 0 deletions scripts/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func reset():
UI.get_node("Player2/VBoxContainer/Health/Bar").set_max(20)
UI.get_node("Player1/VBoxContainer/ButtonC").show()
UI.get_node("Player1/VBoxContainer/ButtonE").show()
Music.temperature = 0
deselect()

func start():
Expand Down Expand Up @@ -613,6 +614,7 @@ func update_stats():
UI.get_node("Player"+str(p+1)+"/VBoxContainer/Temp/Bar").set_value(temp)
UI.get_node("Player"+str(p+1)+"/VBoxContainer/Temp/Bar").set_modulate(Cards.COLOR_COLD.linear_interpolate(Cards.COLOR_HOT,temp/10.0+0.5))
UI.get_node("Player"+str(p+1)+"/VBoxContainer/Deck").set_text(tr("DECK")+": "+str(deck[p].size()))
Music.temperature = get_player_temperature(player)+0.5*get_player_temperature((player+1)%2)



Expand Down
20 changes: 20 additions & 0 deletions scripts/main/music.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends Node

var temperature = 0


func _process(delta):
var target_volume_db = clamp(-10*temperature-40,-80,0)
var scale = 0.5-0.4*int(get_node("Cold1").get_volume_db()>target_volume_db)
get_node("Cold1").set_volume_db(clamp(get_node("Cold1").get_volume_db()+delta*scale*(target_volume_db-get_node("Cold1").get_volume_db()),-80,0))
target_volume_db = clamp(-5*temperature-60,-80,0)
scale = 0.5-0.4*int(get_node("Cold2").get_volume_db()>target_volume_db)
get_node("Cold2").set_volume_db(clamp(get_node("Cold2").get_volume_db()+delta*scale*(target_volume_db-get_node("Cold2").get_volume_db()),-80,0))

target_volume_db = clamp(10*temperature-40,-80,0)
scale = 0.5-0.4*int(get_node("Warm1").get_volume_db()>target_volume_db)
get_node("Warm1").set_volume_db(clamp(get_node("Warm1").get_volume_db()+delta*scale*(target_volume_db-get_node("Warm1").get_volume_db()),-80,0))
target_volume_db = clamp(5*temperature-60,-80,0)
scale = 0.5-0.4*int(get_node("Warm2").get_volume_db()>target_volume_db)
get_node("Warm2").set_volume_db(clamp(get_node("Warm2").get_volume_db()+delta*scale*(target_volume_db-get_node("Warm2").get_volume_db()),-80,0))

1 change: 1 addition & 0 deletions scripts/menu/menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func game_over(victory):
get_node("GameOver").set_title(tr("GAME_OVER"))
get_node("GameOver/Text").set_text(tr("YOU_LOST"))
get_node("GameOver").popup_centered()
Music.temperature = 0


func _hide():
Expand Down

0 comments on commit 9ca2d8c

Please sign in to comment.