diff --git a/project.godot b/project.godot index 35c6919..60547f9 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,7 @@ config/icon="res://assets/icon.svg" Globals="*res://scripts/Globals.gd" WorldState="*res://scripts/WorldState.gd" +PlayerState="*res://scripts/PlayerState.gd" SignalBus="*res://scripts/SignalBus.gd" Styling="*res://scripts/Styling.gd" diff --git a/scenes/ability_ph.tscn b/scenes/ability_player.tscn similarity index 91% rename from scenes/ability_ph.tscn rename to scenes/ability_player.tscn index 49955ca..256bf1e 100644 --- a/scenes/ability_ph.tscn +++ b/scenes/ability_player.tscn @@ -3,7 +3,7 @@ [ext_resource type="Texture2D" uid="uid://dvvtnenxps3yu" path="res://assets/high-shot.svg" id="1_djmgc"] [ext_resource type="Script" path="res://scripts/AbilityPlayer.gd" id="2_l8ort"] -[node name="AbilityPH" type="TextureRect"] +[node name="AbilityPlayer" type="TextureRect"] offset_right = 512.0 offset_bottom = 512.0 texture = ExtResource("1_djmgc") diff --git a/scenes/enemy.tscn b/scenes/enemy.tscn index 4665be5..c625874 100644 --- a/scenes/enemy.tscn +++ b/scenes/enemy.tscn @@ -53,3 +53,9 @@ layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 0 text = "Enemy" + +[node name="AttackTimer" type="Timer" parent="."] +wait_time = 4.0 +autostart = true + +[connection signal="timeout" from="AttackTimer" to="." method="_on_attack_timer_timeout"] diff --git a/scenes/testScrollScene.tscn b/scenes/testScrollScene.tscn index fb2272f..ac6d18b 100644 --- a/scenes/testScrollScene.tscn +++ b/scenes/testScrollScene.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://scripts/test_scroll_scene.gd" id="1_gc1kb"] [ext_resource type="Theme" uid="uid://clhh3c3gxotjg" path="res://assets/healthbar.tres" id="2_2v2l0"] [ext_resource type="Script" path="res://scripts/WorldArea.gd" id="2_ccxbh"] -[ext_resource type="PackedScene" uid="uid://dvwo26vsk46tl" path="res://scenes/ability_ph.tscn" id="2_heria"] +[ext_resource type="PackedScene" uid="uid://dvwo26vsk46tl" path="res://scenes/ability_player.tscn" id="2_heria"] [ext_resource type="Theme" uid="uid://cp82s71sduhcv" path="res://assets/expbar.tres" id="3_n8q4b"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_6qo1s"] @@ -40,6 +40,8 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 script = ExtResource("1_gc1kb") debug = true @@ -87,6 +89,7 @@ size_flags_horizontal = 3 theme_override_styles/panel = SubResource("StyleBoxEmpty_imvmd") [node name="PlayerInfo" type="VBoxContainer" parent="MarginContainer/UIBottom/PlayerContainer"] +unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 @@ -101,7 +104,7 @@ text = "1" layout_mode = 2 text = "Player" -[node name="PlayerHealthBar" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] +[node name="PlayerHealthBarBasic" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] visible = false custom_minimum_size = Vector2(0, 32) layout_mode = 2 @@ -110,7 +113,7 @@ theme = ExtResource("2_2v2l0") step = 1.0 value = 100.0 -[node name="PlayerHealthTextureBar" type="TextureProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] +[node name="PlayerHealthBar" type="TextureProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] custom_minimum_size = Vector2(0, 32) layout_mode = 2 size_flags_vertical = 2 @@ -120,7 +123,7 @@ nine_patch_stretch = true texture_under = SubResource("CurveTexture_mtsg5") texture_progress = SubResource("CurveXYZTexture_m13yr") -[node name="PlayerHealthCurrent" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthTextureBar"] +[node name="PlayerHealthCurrent" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthBar"] layout_mode = 1 anchors_preset = -1 anchor_left = 0.0216216 @@ -132,7 +135,33 @@ text = "0" vertical_alignment = 1 metadata/_edit_use_anchors_ = true -[node name="PlayerHealthTotal" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthTextureBar"] +[node name="PlayerHealthPercent" type="HBoxContainer" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthBar"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PlayerHealthPercentVal" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthBar/PlayerHealthPercent"] +layout_mode = 2 +text = "0" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="PlayerHealthPercentSym" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthBar/PlayerHealthPercent"] +layout_mode = 2 +text = "%" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="PlayerHealthMax" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthBar"] layout_mode = 1 anchors_preset = -1 anchor_left = 0.708108 @@ -146,23 +175,6 @@ horizontal_alignment = 2 vertical_alignment = 1 metadata/_edit_use_anchors_ = true -[node name="PlayerHealthPercent" type="Label" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo/PlayerHealthTextureBar"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -3.0 -offset_top = -7.0 -offset_right = 3.0 -offset_bottom = 7.0 -grow_horizontal = 2 -grow_vertical = 2 -text = "0" -horizontal_alignment = 1 -vertical_alignment = 1 - [node name="PlayerExpBar" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] layout_mode = 2 size_flags_vertical = 10 @@ -171,7 +183,7 @@ step = 1.0 value = 43.0 [node name="UIBottomCenter" type="VBoxContainer" parent="MarginContainer/UIBottom"] -custom_minimum_size = Vector2(384, 0) +custom_minimum_size = Vector2(512, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 @@ -251,6 +263,7 @@ layout_mode = 2 text = "Crafting" [node name="DebugMenu" type="HBoxContainer" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons"] +unique_name_in_owner = true visible = false layout_mode = 2 size_flags_horizontal = 4 @@ -260,7 +273,7 @@ size_flags_vertical = 8 layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 8 -text = "Complete Quest" +text = "Test" [node name="TouchScreenButton" type="TouchScreenButton" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu/ButtonTest"] diff --git a/scripts/NPCEnemy.gd b/scripts/NPCEnemy.gd index cbbd003..061fa12 100644 --- a/scripts/NPCEnemy.gd +++ b/scripts/NPCEnemy.gd @@ -48,3 +48,11 @@ func _physics_process(_delta): if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions: move_and_slide() prevCollisions = get_slide_collision_count() + + +func _deal_damage() -> void: + PlayerState.player_currenthealth -= 1 + SignalBus.enemy_damaged_player.emit() + +func _on_attack_timer_timeout() -> void: + _deal_damage() diff --git a/scripts/PlayerState.gd b/scripts/PlayerState.gd new file mode 100644 index 0000000..8c6ae88 --- /dev/null +++ b/scripts/PlayerState.gd @@ -0,0 +1,9 @@ +# singleton to store player state/values +extends Node + + +@export var player_constitution := 1 +@export var player_exp := 0 +@export var player_level := 1 +@export var player_maxhealth := player_constitution * player_level * 100 +@export var player_currenthealth := player_maxhealth \ No newline at end of file diff --git a/scripts/SignalBus.gd b/scripts/SignalBus.gd index f4706d9..3fb72f6 100644 --- a/scripts/SignalBus.gd +++ b/scripts/SignalBus.gd @@ -3,4 +3,5 @@ extends Node signal enemy_died(npcDifficulty: NPC.NPCDifficulty, faction: WorldArea.Faction) +signal enemy_damaged_player signal quest_completed \ No newline at end of file diff --git a/scripts/WorldState.gd b/scripts/WorldState.gd index 1353c77..16a8a56 100644 --- a/scripts/WorldState.gd +++ b/scripts/WorldState.gd @@ -3,6 +3,4 @@ extends Node @export var current_zone: Globals.World.Zones -@export var player_level: int -@export var player_exp: int @export var last_played: Dictionary \ No newline at end of file diff --git a/scripts/test_scroll_scene.gd b/scripts/test_scroll_scene.gd index 02a7814..a432edc 100644 --- a/scripts/test_scroll_scene.gd +++ b/scripts/test_scroll_scene.gd @@ -1,4 +1,4 @@ -# TODO: convert to just combat UI, instancing appropriate zone +# TODO: convert to just combat UI, instancing appropriate zone/area extends Control @@ -16,15 +16,18 @@ var playerPos func _ready() -> void: if debug: - $MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu.show() + %DebugMenu.show() Engine.time_scale = 3.0 SignalBus.quest_completed.connect(_on_quest_completed) + SignalBus.enemy_damaged_player.connect(_on_enemy_damaged_player) _generate_quest() middleX = get_viewport_rect().size.x / 2 playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75)) + + _set_player_display() $SpawnTimer.start(spawnTimerValue) _spawn_enemies(1) @@ -71,6 +74,7 @@ func _spawn_enemies(numEnemies: int) -> void: func _on_button_test_pressed() -> void: + %DebugMenu/ButtonTest.text = "pass" pass @@ -80,13 +84,33 @@ func _on_button_exit_pressed() -> void: func _on_spawn_timer_timeout() -> void: _spawn_enemies(1) + + +func _get_player_current_health() -> void: + var playerCurrHeath = PlayerState.player_currenthealth + %PlayerInfo/PlayerHealthBar/PlayerHealthCurrent.text = str(playerCurrHeath) + %PlayerInfo/PlayerHealthBar.value = playerCurrHeath + if playerCurrHeath <= 0: + get_tree().paused = true + + +func _set_player_display() -> void: + var playerMaxHeath = PlayerState.player_maxhealth + var playerCurrHeath = PlayerState.player_currenthealth + %PlayerInfo/PlayerHealthBar/PlayerHealthMax.text = str(playerMaxHeath) + %PlayerInfo/PlayerHealthBar/PlayerHealthCurrent.text = str(playerCurrHeath) + %PlayerInfo/PlayerHealthBar.value = playerCurrHeath # TODO: move all quest stuff to quest class? func _on_quest_completed() -> void: - $SpawnTimer.stop() + # $SpawnTimer.stop() # questComplete = true if _get_enemies().is_empty(): # and questComplete: canContinue = true # print("Area Complete!") # get_tree().quit() + + +func _on_enemy_damaged_player() -> void: + _get_player_current_health()