Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypickler committed May 7, 2024
1 parent 5424365 commit 5c25ece
Show file tree
Hide file tree
Showing 44 changed files with 1,045 additions and 159 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ export_presets.cfg
.mono/
data_*/
mono_crash.*.json

Builds/
options.ini
31 changes: 31 additions & 0 deletions GlobalOptions.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extends Node

var options = {
"music_volume_db": 0,
"sound_effects_volume_db": -5,
}
var _config : ConfigFile

const PATH_TO_OPTIONS = "res://options.ini"

func _ready():
_config = ConfigFile.new()
var err = _config.load(PATH_TO_OPTIONS)
if err != OK:
_dict_to_config()
else:
_config_to_options()
sync_option_file()

func _config_to_options():
for option in options:
options[option] = _config.get_value("options", option, options[option])
print("Loading option ", option, " with value ", options[option])

func _dict_to_config():
for option in options:
_config.set_value("options", option, options[option])

func sync_option_file():
_dict_to_config()
_config.save(PATH_TO_OPTIONS)
Binary file added Images/enter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Images/enter.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://buvrjkn0uraqt"
path="res://.godot/imported/enter.png-1d63ed36bd49cda324225afbe464a200.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Images/enter.png"
dest_files=["res://.godot/imported/enter.png-1d63ed36bd49cda324225afbe464a200.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=1
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
Binary file added Images/x_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Images/x_button.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dx4iy20x4pnms"
path="res://.godot/imported/x_button.png-8a6de01c5969a9d8b4209776db1466e4.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Images/x_button.png"
dest_files=["res://.godot/imported/x_button.png-8a6de01c5969a9d8b4209776db1466e4.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=1
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
23 changes: 23 additions & 0 deletions MusicPlayer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends AudioStreamPlayer

@export var volume_offset = 0.0 : set = set_volume_offset

func _ready():
volume_db = GlobalOptionsAutoload.options["music_volume_db"]
print(volume_db)

func set_volume_offset(value):
volume_db = volume_db + value - volume_offset
volume_offset = value

func start():
$AnimationPlayer.queue("start")

func stop_music():
$AnimationPlayer.queue("stop")

func pause():
$AnimationPlayer.queue("pause")

func unpause():
$AnimationPlayer.queue("unpause")
165 changes: 165 additions & 0 deletions MusicPlayer.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
[gd_scene load_steps=9 format=3 uid="uid://ck4yo34l3dp8g"]

[ext_resource type="AudioStream" uid="uid://cngwy8i7fm4xg" path="res://Sounds/music.wav" id="1_73w3h"]
[ext_resource type="Script" path="res://MusicPlayer.gd" id="2_qi36m"]

[sub_resource type="Animation" id="Animation_1ukmn"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:volume_offset")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}

[sub_resource type="Animation" id="Animation_y7qsq"]
resource_name = "pause"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:pitch_scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [1.0, 0.9]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:volume_offset")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0, -10]
}

[sub_resource type="Animation" id="Animation_ru1mt"]
resource_name = "start"
length = 0.1
tracks/0/type = "method"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [0.0],
"method": &"play"
}]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:pitch_scale")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [1.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".:volume_offset")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}

[sub_resource type="Animation" id="Animation_qjlw7"]
resource_name = "stop"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:volume_offset")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [-10.0, -50.0]
}
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(1),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"stop"
}]
}

[sub_resource type="Animation" id="Animation_dougp"]
resource_name = "unpause"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:pitch_scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0.9, 1.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:volume_offset")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [-10, 0]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_tix6t"]
_data = {
"RESET": SubResource("Animation_1ukmn"),
"pause": SubResource("Animation_y7qsq"),
"start": SubResource("Animation_ru1mt"),
"stop": SubResource("Animation_qjlw7"),
"unpause": SubResource("Animation_dougp")
}

[node name="MusicPlayer" type="AudioStreamPlayer"]
stream = ExtResource("1_73w3h")
volume_db = -10.0
script = ExtResource("2_qi36m")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_tix6t")
}

[connection signal="finished" from="." to="." method="play"]
3 changes: 1 addition & 2 deletions Scenes/Menu/MainMenu/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ func _ready():

func _on_play_pressed():
LevelManagerAutoload.transition_to("res://Scenes/Menu/SelectPlayer/SelectPlayer.tscn")
GameManagerAutoload.reset_score()


func _on_options_pressed():
pass
LevelManagerAutoload.transition_to("res://Scenes/Menu/Options/Options.tscn")


func _on_exit_pressed():
Expand Down
45 changes: 45 additions & 0 deletions Scenes/Menu/Options/Options.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends VBoxContainer

var sound_effect_volume = 0 : set = set_sound_effect_volume
var music_volume = 0 : set = set_music_volume


func _ready():
sound_effect_volume = GlobalOptionsAutoload.options["sound_effects_volume_db"]
music_volume = GlobalOptionsAutoload.options["music_volume_db"]
%SoundEffectVolumeSlider.connect("value_changed", _sound_effect_volume_changed)
%MusicVolumeSlider.connect("value_changed", _on_music_volume_changed)
%BackButton.grab_focus()


func set_sound_effect_volume(volume):
%SoundEffectVolumeSlider.value = volume
sound_effect_volume = volume


func set_music_volume(volume):
%MusicVolumeSlider.value = volume
MusicPlayerAutoload.volume_db = volume
MusicPlayerAutoload.volume_offset = 0
music_volume = volume

func _sound_effect_volume_changed(value_changed):
sound_effect_volume = %SoundEffectVolumeSlider.value
%SoundEffectPlayer.volume_db = sound_effect_volume
%SoundEffectPlayer.play()


func _on_music_volume_changed(value_changed):
music_volume = %MusicVolumeSlider.value
%SoundEffectPlayer.volume_db = music_volume
%SoundEffectPlayer.play()

func back():
GlobalOptionsAutoload.options["sound_effects_volume_db"] = sound_effect_volume
GlobalOptionsAutoload.options["music_volume_db"] = music_volume
GlobalOptionsAutoload.sync_option_file()
LevelManagerAutoload.transition_to("res://Scenes/Menu/MainMenu/MainMenu.tscn")

func _input(event):
if event.is_action_pressed("ui_cancel"):
LevelManagerAutoload.transition_to("res://Scenes/Menu/MainMenu/MainMenu.tscn")
Loading

0 comments on commit 5c25ece

Please sign in to comment.