added signal bus, quests basically working
This commit is contained in:
parent
a0f826525c
commit
d5db6e873b
@ -15,6 +15,10 @@ run/main_scene="res://scenes/testScrollScene.tscn"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://assets/icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
SignalBus="*res://scripts/SignalBus.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/scale=3.0
|
||||
|
@ -7,11 +7,11 @@ offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_o0k38")
|
||||
|
||||
[node name="ObjectiveLabel" type="Label" parent="."]
|
||||
[node name="GoalLabel" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Quest Objective: "
|
||||
|
||||
[node name="CompletedLabel" type="Label" parent="."]
|
||||
[node name="CompletedValLabel" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "0"
|
||||
|
||||
@ -19,6 +19,6 @@ text = "0"
|
||||
layout_mode = 2
|
||||
text = "/"
|
||||
|
||||
[node name="GoalLabel" type="Label" parent="."]
|
||||
[node name="GoalValLabel" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "1"
|
||||
|
@ -1,11 +1,14 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://0h3dpe6fuhe8"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://0h3dpe6fuhe8"]
|
||||
|
||||
[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://klcyjys703l5" path="res://scenes/quest.tscn" id="2_dodxo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvwo26vsk46tl" path="res://scenes/ability_ph.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"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_imvmd"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_6jnvr"]
|
||||
@ -19,16 +22,20 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_gc1kb")
|
||||
debug = true
|
||||
spawnTimerValue = 20.0
|
||||
spawnTimerValue = 0.5
|
||||
|
||||
[node name="SpawnTimer" type="Timer" parent="."]
|
||||
|
||||
[node name="SpawnArea" type="PanelContainer" parent="."]
|
||||
[node name="WorldArea" type="PanelContainer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_6qo1s")
|
||||
script = ExtResource("2_ccxbh")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
@ -53,6 +60,7 @@ size_flags_horizontal = 4
|
||||
|
||||
[node name="PHQuest" parent="MarginContainer/UITop/QuestsContainer" instance=ExtResource("2_dodxo")]
|
||||
layout_mode = 2
|
||||
goalTotal = 20
|
||||
|
||||
[node name="UIBottom" type="HBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
@ -109,6 +117,7 @@ alignment = 1
|
||||
[node name="AbilityA1" parent="MarginContainer/UIBottom/UIBottomCenter/AbilityBar" instance=ExtResource("2_heria")]
|
||||
custom_minimum_size = Vector2(64, 64)
|
||||
layout_mode = 2
|
||||
attack_damage = 1000
|
||||
|
||||
[node name="AbilityA2" parent="MarginContainer/UIBottom/UIBottomCenter/AbilityBar" instance=ExtResource("2_heria")]
|
||||
visible = false
|
||||
|
@ -36,7 +36,7 @@ func _get_angle_to_player(enemy: Node) -> float:
|
||||
|
||||
func _get_target(enemies) -> Node:
|
||||
# var numEnemies := _get_num_enemies()
|
||||
# TODO implement range, i.e. closest within range
|
||||
# TODO: implement range, i.e. closest within range
|
||||
var enemyDists
|
||||
var closestEnemy
|
||||
# get list of distances by mapping distance to each node in enemies
|
||||
|
@ -3,11 +3,7 @@ class_name NPCEnemy
|
||||
extends NPC
|
||||
|
||||
|
||||
enum questTypes {NONE, FEW_KILL, MANY_KILL, ONE_KILL}
|
||||
|
||||
signal enemy_died(npcDifficulty: NPCDifficulties, questType: questTypes)
|
||||
|
||||
@export var questType: questTypes = questTypes.NONE
|
||||
@export var killType: WorldArea.KillTypes = WorldArea.KillTypes.NATURAL
|
||||
|
||||
var target
|
||||
var speed := 300
|
||||
@ -30,18 +26,24 @@ func _ready() -> void:
|
||||
%Healthbar.max_value = maxHealth
|
||||
%Healthbar.value = maxHealth
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
%Healthbar.value = maxHealth - damageTaken
|
||||
if damageTaken >= maxHealth:
|
||||
# send signal that I died to be counted, etc.
|
||||
enemy_died.emit(self.npcDifficulty, self.questType)
|
||||
# save vars to emit
|
||||
var enemyDifficulty = self.npcDifficulty
|
||||
var enemyKillType = self.killType
|
||||
# delete node
|
||||
self.remove_from_group("enemies")
|
||||
self.queue_free()
|
||||
# send signal that I died to be counted, etc.
|
||||
SignalBus.enemy_died.emit(enemyDifficulty, enemyKillType)
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
velocity = position.direction_to(target) * speed
|
||||
# look_at(target)
|
||||
# FIXME want enemy to stop when touching something, to prevent vibrating
|
||||
# FIXME: want enemy to stop when touching something, to prevent vibrating
|
||||
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
||||
move_and_slide()
|
||||
prevCollisions = get_slide_collision_count()
|
||||
|
@ -1,20 +1,50 @@
|
||||
class_name Quest
|
||||
extends HBoxContainer
|
||||
|
||||
enum GoalTypes { KILLMANY, KILLFEW, KILLONE, GETMANY, GETFEW, GETONE }
|
||||
enum KillTypes { NATURAL, VOID }
|
||||
|
||||
@export var goalType := GoalTypes.KILLMANY
|
||||
@export var killType := KillTypes.NATURAL
|
||||
@export var goalType := WorldArea.GoalTypes.KILLMANY
|
||||
@export var killType := WorldArea.KillTypes.NATURAL
|
||||
|
||||
@export var goalTotal := 1
|
||||
@export var goalCurrent := 0
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
# goalType = GoalTypes.
|
||||
# match goalType:
|
||||
# GoalTypes.KILLMANY:
|
||||
# killType = KillTypes.NATURAL
|
||||
SignalBus.enemy_died.connect(_on_enemy_died)
|
||||
_generate_random_quest()
|
||||
_set_goal_text()
|
||||
_set_goal_val()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _set_goal_text() -> void:
|
||||
match self.goalType:
|
||||
WorldArea.GoalTypes.KILLMANY:
|
||||
$GoalLabel.text = "Kill Many"
|
||||
|
||||
|
||||
func _set_goal_val() -> void:
|
||||
$GoalValLabel.text = str(self.goalTotal)
|
||||
|
||||
|
||||
func _quest_goal_check(enemyKillType: WorldArea.KillTypes) -> void:
|
||||
if enemyKillType == self.killType:
|
||||
self.goalCurrent += 1
|
||||
$CompletedValLabel.text = str(self.goalCurrent)
|
||||
if self.goalCurrent == self.goalTotal:
|
||||
SignalBus.quest_completed.emit()
|
||||
|
||||
|
||||
func _generate_random_quest() -> void:
|
||||
pass
|
||||
# TODO: generate random quest
|
||||
# self.goalType = GoalTypes.
|
||||
# match self.goalType:
|
||||
# GoalTypes.KILLMANY:
|
||||
# self.killType = KillTypes.NATURAL
|
||||
|
||||
|
||||
func _on_enemy_died(_enemyDifficulty: NPC.NPCDifficulties, enemyKillType: WorldArea.KillTypes):
|
||||
_quest_goal_check(enemyKillType)
|
||||
|
5
scripts/SignalBus.gd
Normal file
5
scripts/SignalBus.gd
Normal file
@ -0,0 +1,5 @@
|
||||
# signal bus to relay signals
|
||||
extends Node
|
||||
|
||||
signal enemy_died(npcDifficulty: NPC.NPCDifficulties, killType: WorldArea.KillTypes)
|
||||
signal quest_completed
|
@ -1,5 +1,8 @@
|
||||
# defines the parameters for spawning enemies within an area and handles
|
||||
# enemy death signals
|
||||
class_name WorldArea
|
||||
extends Sprite2D
|
||||
extends PanelContainer
|
||||
|
||||
|
||||
# defines the parameters for spawning enemies within an area
|
||||
enum GoalTypes { KILLMANY, KILLFEW, KILLONE, GETMANY, GETFEW, GETONE }
|
||||
enum KillTypes { NATURAL, VOID }
|
||||
|
@ -6,29 +6,31 @@ extends Control
|
||||
|
||||
var deltaCount := 0
|
||||
var enemyMoveSpeed := 5.0
|
||||
var questsComplete := false
|
||||
var questComplete := false
|
||||
|
||||
var middleX
|
||||
var playerPos
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
middleX = get_viewport_rect().size.x / 2
|
||||
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
||||
if not debug:
|
||||
$MarginContainer/Menus/MenuButtons/DebugMenu.hide()
|
||||
|
||||
SignalBus.quest_completed.connect(_on_quest_completed)
|
||||
|
||||
middleX = get_viewport_rect().size.x / 2
|
||||
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
||||
|
||||
$SpawnTimer.start(spawnTimerValue)
|
||||
_spawn_enemies(1)
|
||||
# _spawn_enemies(5)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
||||
if questsComplete:
|
||||
$SpawnTimer.stop()
|
||||
if _get_enemies().is_empty():
|
||||
print("Area Complete!")
|
||||
get_tree().quit()
|
||||
if _get_enemies().is_empty() and questComplete:
|
||||
print("Area Complete!")
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _create_enemy():
|
||||
@ -55,13 +57,13 @@ func _spawn_enemies(numEnemies: int) -> void:
|
||||
# var numEnemies = randi_range(1, maxEnemies)
|
||||
for i in range(numEnemies):
|
||||
var enemy = _create_enemy()
|
||||
%SpawnArea.add_child(enemy)
|
||||
%WorldArea.add_child(enemy)
|
||||
# var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
|
||||
# create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
|
||||
|
||||
|
||||
func _on_button_test_pressed() -> void:
|
||||
questsComplete = true
|
||||
pass
|
||||
|
||||
|
||||
func _on_button_exit_pressed() -> void:
|
||||
@ -70,3 +72,13 @@ func _on_button_exit_pressed() -> void:
|
||||
|
||||
func _on_spawn_timer_timeout() -> void:
|
||||
_spawn_enemies(1)
|
||||
|
||||
|
||||
# TODO: move all quest stuff to quest class
|
||||
func _on_quest_completed() -> void:
|
||||
$SpawnTimer.stop()
|
||||
questComplete = true
|
||||
$MarginContainer/UITop/QuestsContainer/PHQuest.hide()
|
||||
var quest_complete_indicator = Label.new()
|
||||
quest_complete_indicator.text = "Quest Complete!"
|
||||
$"%QuestsContainer".add_child(quest_complete_indicator)
|
||||
|
Loading…
Reference in New Issue
Block a user