initial enemy damage implementation
This commit is contained in:
parent
df0a0cffaa
commit
3ddee847e2
@ -19,6 +19,7 @@ config/icon="res://assets/icon.svg"
|
|||||||
|
|
||||||
Globals="*res://scripts/Globals.gd"
|
Globals="*res://scripts/Globals.gd"
|
||||||
WorldState="*res://scripts/WorldState.gd"
|
WorldState="*res://scripts/WorldState.gd"
|
||||||
|
PlayerState="*res://scripts/PlayerState.gd"
|
||||||
SignalBus="*res://scripts/SignalBus.gd"
|
SignalBus="*res://scripts/SignalBus.gd"
|
||||||
Styling="*res://scripts/Styling.gd"
|
Styling="*res://scripts/Styling.gd"
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://dvvtnenxps3yu" path="res://assets/high-shot.svg" id="1_djmgc"]
|
[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"]
|
[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_right = 512.0
|
||||||
offset_bottom = 512.0
|
offset_bottom = 512.0
|
||||||
texture = ExtResource("1_djmgc")
|
texture = ExtResource("1_djmgc")
|
@ -53,3 +53,9 @@ layout_mode = 2
|
|||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
text = "Enemy"
|
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"]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
[ext_resource type="Script" path="res://scripts/test_scroll_scene.gd" id="1_gc1kb"]
|
[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="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="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"]
|
[ext_resource type="Theme" uid="uid://cp82s71sduhcv" path="res://assets/expbar.tres" id="3_n8q4b"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_6qo1s"]
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_6qo1s"]
|
||||||
@ -40,6 +40,8 @@ anchor_right = 1.0
|
|||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
script = ExtResource("1_gc1kb")
|
script = ExtResource("1_gc1kb")
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
@ -87,6 +89,7 @@ size_flags_horizontal = 3
|
|||||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_imvmd")
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_imvmd")
|
||||||
|
|
||||||
[node name="PlayerInfo" type="VBoxContainer" parent="MarginContainer/UIBottom/PlayerContainer"]
|
[node name="PlayerInfo" type="VBoxContainer" parent="MarginContainer/UIBottom/PlayerContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
@ -101,7 +104,7 @@ text = "1"
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Player"
|
text = "Player"
|
||||||
|
|
||||||
[node name="PlayerHealthBar" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"]
|
[node name="PlayerHealthBarBasic" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"]
|
||||||
visible = false
|
visible = false
|
||||||
custom_minimum_size = Vector2(0, 32)
|
custom_minimum_size = Vector2(0, 32)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@ -110,7 +113,7 @@ theme = ExtResource("2_2v2l0")
|
|||||||
step = 1.0
|
step = 1.0
|
||||||
value = 100.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)
|
custom_minimum_size = Vector2(0, 32)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 2
|
size_flags_vertical = 2
|
||||||
@ -120,7 +123,7 @@ nine_patch_stretch = true
|
|||||||
texture_under = SubResource("CurveTexture_mtsg5")
|
texture_under = SubResource("CurveTexture_mtsg5")
|
||||||
texture_progress = SubResource("CurveXYZTexture_m13yr")
|
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
|
layout_mode = 1
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.0216216
|
anchor_left = 0.0216216
|
||||||
@ -132,7 +135,33 @@ text = "0"
|
|||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
metadata/_edit_use_anchors_ = true
|
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
|
layout_mode = 1
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.708108
|
anchor_left = 0.708108
|
||||||
@ -146,23 +175,6 @@ horizontal_alignment = 2
|
|||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
metadata/_edit_use_anchors_ = true
|
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"]
|
[node name="PlayerExpBar" type="ProgressBar" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 10
|
size_flags_vertical = 10
|
||||||
@ -171,7 +183,7 @@ step = 1.0
|
|||||||
value = 43.0
|
value = 43.0
|
||||||
|
|
||||||
[node name="UIBottomCenter" type="VBoxContainer" parent="MarginContainer/UIBottom"]
|
[node name="UIBottomCenter" type="VBoxContainer" parent="MarginContainer/UIBottom"]
|
||||||
custom_minimum_size = Vector2(384, 0)
|
custom_minimum_size = Vector2(512, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
@ -251,6 +263,7 @@ layout_mode = 2
|
|||||||
text = "Crafting"
|
text = "Crafting"
|
||||||
|
|
||||||
[node name="DebugMenu" type="HBoxContainer" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons"]
|
[node name="DebugMenu" type="HBoxContainer" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons"]
|
||||||
|
unique_name_in_owner = true
|
||||||
visible = false
|
visible = false
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
@ -260,7 +273,7 @@ size_flags_vertical = 8
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
text = "Complete Quest"
|
text = "Test"
|
||||||
|
|
||||||
[node name="TouchScreenButton" type="TouchScreenButton" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu/ButtonTest"]
|
[node name="TouchScreenButton" type="TouchScreenButton" parent="MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu/ButtonTest"]
|
||||||
|
|
||||||
|
@ -48,3 +48,11 @@ func _physics_process(_delta):
|
|||||||
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
prevCollisions = get_slide_collision_count()
|
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()
|
||||||
|
9
scripts/PlayerState.gd
Normal file
9
scripts/PlayerState.gd
Normal file
@ -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
|
@ -3,4 +3,5 @@ extends Node
|
|||||||
|
|
||||||
|
|
||||||
signal enemy_died(npcDifficulty: NPC.NPCDifficulty, faction: WorldArea.Faction)
|
signal enemy_died(npcDifficulty: NPC.NPCDifficulty, faction: WorldArea.Faction)
|
||||||
|
signal enemy_damaged_player
|
||||||
signal quest_completed
|
signal quest_completed
|
@ -3,6 +3,4 @@ extends Node
|
|||||||
|
|
||||||
|
|
||||||
@export var current_zone: Globals.World.Zones
|
@export var current_zone: Globals.World.Zones
|
||||||
@export var player_level: int
|
|
||||||
@export var player_exp: int
|
|
||||||
@export var last_played: Dictionary
|
@export var last_played: Dictionary
|
@ -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
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
@ -16,15 +16,18 @@ var playerPos
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if debug:
|
if debug:
|
||||||
$MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu.show()
|
%DebugMenu.show()
|
||||||
Engine.time_scale = 3.0
|
Engine.time_scale = 3.0
|
||||||
|
|
||||||
SignalBus.quest_completed.connect(_on_quest_completed)
|
SignalBus.quest_completed.connect(_on_quest_completed)
|
||||||
|
SignalBus.enemy_damaged_player.connect(_on_enemy_damaged_player)
|
||||||
|
|
||||||
_generate_quest()
|
_generate_quest()
|
||||||
|
|
||||||
middleX = get_viewport_rect().size.x / 2
|
middleX = get_viewport_rect().size.x / 2
|
||||||
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
||||||
|
|
||||||
|
_set_player_display()
|
||||||
|
|
||||||
$SpawnTimer.start(spawnTimerValue)
|
$SpawnTimer.start(spawnTimerValue)
|
||||||
_spawn_enemies(1)
|
_spawn_enemies(1)
|
||||||
@ -71,6 +74,7 @@ func _spawn_enemies(numEnemies: int) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_button_test_pressed() -> void:
|
func _on_button_test_pressed() -> void:
|
||||||
|
%DebugMenu/ButtonTest.text = "pass"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -80,13 +84,33 @@ func _on_button_exit_pressed() -> void:
|
|||||||
|
|
||||||
func _on_spawn_timer_timeout() -> void:
|
func _on_spawn_timer_timeout() -> void:
|
||||||
_spawn_enemies(1)
|
_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?
|
# TODO: move all quest stuff to quest class?
|
||||||
func _on_quest_completed() -> void:
|
func _on_quest_completed() -> void:
|
||||||
$SpawnTimer.stop()
|
# $SpawnTimer.stop()
|
||||||
# questComplete = true
|
# questComplete = true
|
||||||
if _get_enemies().is_empty(): # and questComplete:
|
if _get_enemies().is_empty(): # and questComplete:
|
||||||
canContinue = true
|
canContinue = true
|
||||||
# print("Area Complete!")
|
# print("Area Complete!")
|
||||||
# get_tree().quit()
|
# get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_enemy_damaged_player() -> void:
|
||||||
|
_get_player_current_health()
|
||||||
|
Loading…
Reference in New Issue
Block a user