diff --git a/project.godot b/project.godot index 0ef2aea..64075a8 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://levels/sandbox/sandbox.tscn" config/features=PackedStringArray("4.4", "Forward Plus") run/max_fps=60 +[autoload] + +GameManager="*res://src/game/game_manager.tscn" + [debug] gdscript/warnings/untyped_declaration=2 diff --git a/src/game/game.gd b/src/game/game.gd new file mode 100644 index 0000000..f1ceb58 --- /dev/null +++ b/src/game/game.gd @@ -0,0 +1,7 @@ +class_name Game extends Node +## Interface to the game as an application. + +## Handy typed singleton access. +static var manager: GameManagerType: + get(): + return GameManager diff --git a/src/game/game.gd.uid b/src/game/game.gd.uid new file mode 100644 index 0000000..7c7af87 --- /dev/null +++ b/src/game/game.gd.uid @@ -0,0 +1 @@ +uid://dxl25lkyped4 diff --git a/src/game/game.tscn b/src/game/game.tscn new file mode 100644 index 0000000..a36050e --- /dev/null +++ b/src/game/game.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://qpq2cm1hgeha"] + +[ext_resource type="Script" uid="uid://dxl25lkyped4" path="res://src/game/game.gd" id="1_qnjlk"] + +[node name="Game" type="Node"] +script = ExtResource("1_qnjlk") diff --git a/src/game/game_manager.gd b/src/game/game_manager.gd new file mode 100644 index 0000000..f8c84bb --- /dev/null +++ b/src/game/game_manager.gd @@ -0,0 +1,13 @@ +class_name GameManagerType extends Node +## Autoloaded singleton encapsulating game state. + +signal grunk_collected(delta: float) + +var grunk_tank := 0.0 + +var alert_level := 0 + + +func collect_grunk(delta: float) -> void: + grunk_tank += delta + grunk_collected.emit(delta) diff --git a/src/game/game_manager.gd.uid b/src/game/game_manager.gd.uid new file mode 100644 index 0000000..6ce4481 --- /dev/null +++ b/src/game/game_manager.gd.uid @@ -0,0 +1 @@ +uid://c1i5gnht15x0e diff --git a/src/game/game_manager.tscn b/src/game/game_manager.tscn new file mode 100644 index 0000000..af01b15 --- /dev/null +++ b/src/game/game_manager.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://cnrtgmanw40ei"] + +[ext_resource type="Script" uid="uid://c1i5gnht15x0e" path="res://src/game/game_manager.gd" id="1_08e4a"] + +[node name="GameManager" type="Node"] +script = ExtResource("1_08e4a") diff --git a/src/ui/hud/grunk_counter/grunk_counter.gd b/src/ui/hud/grunk_counter/grunk_counter.gd new file mode 100644 index 0000000..7d1fd31 --- /dev/null +++ b/src/ui/hud/grunk_counter/grunk_counter.gd @@ -0,0 +1,20 @@ +extends HBoxContainer +## Does a funky lil bump when you collect tha grunk + +const COUNTER_BUMP_RATE := 0.3 + +@onready var counter: Label = %Counter + + +func _ready() -> void: + Game.manager.grunk_collected.connect(on_grunk_collected) + counter.pivot_offset = Vector2(0, counter.size.y) + + +func on_grunk_collected(delta: float) -> void: + counter.text = str(int(Game.manager.grunk_tank)) + counter.scale = Vector2.ONE + Vector2.ONE * clampf(delta / 128.0, 0.1, 1.0) + + +func _process(_delta: float) -> void: + counter.scale = counter.scale.lerp(Vector2.ONE, COUNTER_BUMP_RATE) diff --git a/src/ui/hud/grunk_counter/grunk_counter.gd.uid b/src/ui/hud/grunk_counter/grunk_counter.gd.uid new file mode 100644 index 0000000..ed9c2d7 --- /dev/null +++ b/src/ui/hud/grunk_counter/grunk_counter.gd.uid @@ -0,0 +1 @@ +uid://dspsijt4ysg4x diff --git a/src/ui/hud/grunk_counter/grunk_counter.tscn b/src/ui/hud/grunk_counter/grunk_counter.tscn new file mode 100644 index 0000000..3f35997 --- /dev/null +++ b/src/ui/hud/grunk_counter/grunk_counter.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=3 format=3 uid="uid://cq8qcp5xg41e0"] + +[ext_resource type="Theme" uid="uid://b07fevr214mmr" path="res://src/ui/hud/hud_theme.tres" id="1_fwos1"] +[ext_resource type="Script" uid="uid://dspsijt4ysg4x" path="res://src/ui/hud/grunk_counter/grunk_counter.gd" id="2_jfqlp"] + +[node name="GrunkCounter" type="HBoxContainer"] +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -45.0 +offset_right = 134.0 +grow_vertical = 0 +theme = ExtResource("1_fwos1") +alignment = 2 +script = ExtResource("2_jfqlp") + +[node name="Label" type="Label" parent="."] +texture_filter = 6 +layout_mode = 2 +size_flags_horizontal = 0 +text = "GRUNK: " + +[node name="Counter" type="Label" parent="."] +unique_name_in_owner = true +texture_filter = 6 +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +text = " 0" +horizontal_alignment = 2 diff --git a/src/ui/hud/player_hud.tscn b/src/ui/hud/player_hud.tscn index 4a39f23..86fd9be 100644 --- a/src/ui/hud/player_hud.tscn +++ b/src/ui/hud/player_hud.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://dq1x21tq06dud"] +[gd_scene load_steps=4 format=3 uid="uid://dq1x21tq06dud"] [ext_resource type="Theme" uid="uid://b07fevr214mmr" path="res://src/ui/hud/hud_theme.tres" id="1_lirk3"] [ext_resource type="Script" uid="uid://lrsv0185bfu" path="res://src/ui/hud/player_hud.gd" id="2_j6lpx"] +[ext_resource type="PackedScene" uid="uid://cq8qcp5xg41e0" path="res://src/ui/hud/grunk_counter/grunk_counter.tscn" id="3_5be8f"] [node name="PlayerHUD" type="Control"] layout_mode = 3 @@ -45,3 +46,21 @@ offset_right = 20.0 grow_horizontal = 2 grow_vertical = 0 text = "Press [E] to use" + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -77.0 +offset_right = 123.0 +grow_vertical = 0 +theme_override_constants/margin_left = 32 +theme_override_constants/margin_top = 32 +theme_override_constants/margin_right = 32 +theme_override_constants/margin_bottom = 32 + +[node name="GrunkCounter" parent="MarginContainer" instance=ExtResource("3_5be8f")] +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 8 diff --git a/src/world/gunk_body/gunk_body.gd b/src/world/gunk_body/gunk_body.gd index dba6680..1fe3ca2 100644 --- a/src/world/gunk_body/gunk_body.gd +++ b/src/world/gunk_body/gunk_body.gd @@ -218,8 +218,12 @@ func _process(_delta: float) -> void: _mutex.lock() var new_total := _clear_total _mutex.unlock() - if abs(new_total - _prev_clear_total) > CLEAR_TOTAL_EPSILON: + var delta := new_total - _prev_clear_total + if abs(delta) > CLEAR_TOTAL_EPSILON: clear_total_updated.emit(new_total) + # XXX due to fp error, this will drift from the "true count" over time + # but it probably won't matter :shrug: + Game.manager.collect_grunk(delta) _prev_clear_total = new_total # If paint_continuous wasn't called last frame, stop the current polyline.