transition to physics-based movement to enable collisions, customize health bar appearance
This commit is contained in:
parent
9de2a0e75a
commit
347abe64bf
@ -1,24 +1,32 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://55qfhbliodhn"]
|
[gd_scene load_steps=6 format=3 uid="uid://55qfhbliodhn"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/NPCEnemy.gd" id="1_ec4cy"]
|
[ext_resource type="Script" path="res://scripts/NPCEnemy.gd" id="1_ec4cy"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b10c1776j6j60" path="res://assets/icon.svg" id="2_twdr5"]
|
[ext_resource type="Texture2D" uid="uid://b10c1776j6j60" path="res://assets/icon.svg" id="2_twdr5"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tv6kf"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yg7tn"]
|
||||||
size = Vector2(196, 175)
|
bg_color = Color(0.623529, 0, 0, 1)
|
||||||
|
border_color = Color(0.491583, 0.491583, 0.491583, 1)
|
||||||
|
|
||||||
[node name="NPCEnemy" type="Node2D"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_enag8"]
|
||||||
|
bg_color = Color(0.207843, 0, 0, 1)
|
||||||
|
border_color = Color(0.491583, 0.491583, 0.491583, 1)
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id="Theme_fx206"]
|
||||||
|
ProgressBar/styles/background = SubResource("StyleBoxFlat_yg7tn")
|
||||||
|
ProgressBar/styles/fill = SubResource("StyleBoxFlat_enag8")
|
||||||
|
|
||||||
|
[node name="NPCEnemy" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_ec4cy")
|
script = ExtResource("1_ec4cy")
|
||||||
|
|
||||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionPolygon2D" parent="."]
|
||||||
|
position = Vector2(-100, -86)
|
||||||
|
polygon = PackedVector2Array(0, 0, 100, -43, 200, 0, 100, 43)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
position = Vector2(0, -11.5)
|
|
||||||
shape = SubResource("RectangleShape2D_tv6kf")
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
|
||||||
texture = ExtResource("2_twdr5")
|
texture = ExtResource("2_twdr5")
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="CharacterBody2D/Sprite2D"]
|
[node name="MarginContainer" type="MarginContainer" parent="Sprite2D"]
|
||||||
|
z_index = 2
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
@ -29,29 +37,30 @@ offset_bottom = -57.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="Nameplate" type="VBoxContainer" parent="CharacterBody2D/Sprite2D/MarginContainer"]
|
[node name="Nameplate" type="VBoxContainer" parent="Sprite2D/MarginContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Healthbar" type="ProgressBar" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate"]
|
[node name="Healthbar" type="ProgressBar" parent="Sprite2D/MarginContainer/Nameplate"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(0, 16)
|
custom_minimum_size = Vector2(0, 16)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
theme = SubResource("Theme_fx206")
|
||||||
max_value = 10.0
|
max_value = 10.0
|
||||||
step = 1.0
|
step = 1.0
|
||||||
value = 10.0
|
value = 10.0
|
||||||
show_percentage = false
|
show_percentage = false
|
||||||
|
|
||||||
[node name="TitleBox" type="HBoxContainer" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate"]
|
[node name="TitleBox" type="HBoxContainer" parent="Sprite2D/MarginContainer/Nameplate"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="TierLabel" type="Label" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
[node name="TierLabel" type="Label" parent="Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
text = "Tier
|
text = "Tier
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="NPCNameLabel" type="Label" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
[node name="NPCNameLabel" type="Label" parent="Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
|
@ -6,19 +6,17 @@
|
|||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tv6kf"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tv6kf"]
|
||||||
size = Vector2(196, 175)
|
size = Vector2(196, 175)
|
||||||
|
|
||||||
[node name="NPC" type="Node2D"]
|
[node name="NPC" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_m6htj")
|
script = ExtResource("1_m6htj")
|
||||||
|
|
||||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
|
||||||
position = Vector2(0, -11.5)
|
position = Vector2(0, -11.5)
|
||||||
shape = SubResource("RectangleShape2D_tv6kf")
|
shape = SubResource("RectangleShape2D_tv6kf")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("2_yarwk")
|
texture = ExtResource("2_yarwk")
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="CharacterBody2D/Sprite2D"]
|
[node name="MarginContainer" type="MarginContainer" parent="Sprite2D"]
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
@ -29,10 +27,10 @@ offset_bottom = -57.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="Nameplate" type="VBoxContainer" parent="CharacterBody2D/Sprite2D/MarginContainer"]
|
[node name="Nameplate" type="VBoxContainer" parent="Sprite2D/MarginContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Healthbar" type="ProgressBar" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate"]
|
[node name="Healthbar" type="ProgressBar" parent="Sprite2D/MarginContainer/Nameplate"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(0, 16)
|
custom_minimum_size = Vector2(0, 16)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@ -41,17 +39,17 @@ step = 1.0
|
|||||||
value = 10.0
|
value = 10.0
|
||||||
show_percentage = false
|
show_percentage = false
|
||||||
|
|
||||||
[node name="TitleBox" type="HBoxContainer" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate"]
|
[node name="TitleBox" type="HBoxContainer" parent="Sprite2D/MarginContainer/Nameplate"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="TierLabel" type="Label" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
[node name="TierLabel" type="Label" parent="Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
text = "Tier
|
text = "Tier
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="NPCNameLabel" type="Label" parent="CharacterBody2D/Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
[node name="NPCNameLabel" type="Label" parent="Sprite2D/MarginContainer/Nameplate/TitleBox"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class_name NPC
|
class_name NPC
|
||||||
extends Node2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
enum npcDifficulties { MINION, NORMAL, ELITE, BOSS, ELITEBOSS, BBEG }
|
enum npcDifficulties { MINION, NORMAL, ELITE, BOSS, ELITEBOSS, BBEG }
|
||||||
|
@ -2,12 +2,16 @@ class_name NPCEnemy
|
|||||||
extends NPC
|
extends NPC
|
||||||
|
|
||||||
|
|
||||||
enum questTypes { NONE, FEW_KILL, MANY_KILL, ONE_KILL }
|
enum questTypes {NONE, FEW_KILL, MANY_KILL, ONE_KILL}
|
||||||
|
|
||||||
signal enemy_died(npcDifficulty: npcDifficulties, questType: questTypes)
|
signal enemy_died(npcDifficulty: npcDifficulties, questType: questTypes)
|
||||||
|
|
||||||
@export var questType: questTypes = questTypes.NONE
|
@export var questType: questTypes = questTypes.NONE
|
||||||
|
|
||||||
|
var target
|
||||||
|
var speed := 300
|
||||||
|
var prevCollisions := 0
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
self.npcDifficulty = npcDifficulties.NORMAL
|
self.npcDifficulty = npcDifficulties.NORMAL
|
||||||
@ -32,3 +36,11 @@ func _process(_delta: float) -> void:
|
|||||||
enemy_died.emit(self.npcDifficulty, self.questType)
|
enemy_died.emit(self.npcDifficulty, self.questType)
|
||||||
# delete node
|
# delete node
|
||||||
self.queue_free()
|
self.queue_free()
|
||||||
|
|
||||||
|
func _physics_process(_delta):
|
||||||
|
velocity = position.direction_to(target) * speed
|
||||||
|
# look_at(target)
|
||||||
|
# FIXME want enemy to stop only when touching something, to stop vibrating
|
||||||
|
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
||||||
|
move_and_slide()
|
||||||
|
prevCollisions = get_slide_collision_count()
|
||||||
|
@ -19,12 +19,24 @@ func _ready() -> void:
|
|||||||
$MarginContainer/Menus/MenuButtons/DebugMenu.hide()
|
$MarginContainer/Menus/MenuButtons/DebugMenu.hide()
|
||||||
$SpawnTimer.start(spawnTimerValue)
|
$SpawnTimer.start(spawnTimerValue)
|
||||||
_spawn_enemies(5)
|
_spawn_enemies(5)
|
||||||
|
_spawn_enemies(5)
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
func _create_enemy():
|
func _create_enemy():
|
||||||
var enemy = load("res://scenes/enemy.tscn").instantiate()
|
var enemy = load("res://scenes/enemy.tscn").instantiate()
|
||||||
enemy.scale = Vector2.ONE*0.5
|
enemy.scale = Vector2.ONE*0.5
|
||||||
enemy.position = Vector2(randi_range(0, get_viewport_rect().size.x), -50)
|
enemy.position = Vector2(randi_range(0, get_viewport_rect().size.x), -50)
|
||||||
#enemy.get_node("%NPCNameLabel").text = "Test"
|
enemy.speed *= randf_range(0.5, 2.0)
|
||||||
|
enemy.target = playerPos
|
||||||
|
|
||||||
return enemy
|
return enemy
|
||||||
|
|
||||||
@ -44,32 +56,11 @@ func _spawn_enemies(maxEnemies: int) -> void:
|
|||||||
for i in range(numEnemies):
|
for i in range(numEnemies):
|
||||||
var enemy = _create_enemy()
|
var enemy = _create_enemy()
|
||||||
%SpawnArea.add_child(enemy)
|
%SpawnArea.add_child(enemy)
|
||||||
var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
|
# var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
|
||||||
create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
|
# create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
|
||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
|
||||||
#var closestEnemy = _get_closest_enemy()
|
|
||||||
deltaCount += 1
|
|
||||||
#if numEnemies != 0:
|
|
||||||
#print(playerPos.distance_squared_to(closestEnemy.position))
|
|
||||||
# change movement test, not sure it's working right...
|
|
||||||
#create_tween().tween_property(enemies[randi_range(0, numEnemies-1)], "position", Vector2(100, 100), 1.0)
|
|
||||||
#if deltaCount % 200 == 0:
|
|
||||||
#%SpawnArea.remove_child(closestEnemy)
|
|
||||||
# change to signal
|
|
||||||
if questsComplete:
|
|
||||||
$SpawnTimer.stop()
|
|
||||||
if _get_enemies().is_empty():
|
|
||||||
print("Area Complete!")
|
|
||||||
|
|
||||||
|
|
||||||
func _on_button_test_pressed() -> void:
|
func _on_button_test_pressed() -> void:
|
||||||
# remove all existing enemies from scene and array
|
|
||||||
#for enemy in enemies:
|
|
||||||
#remove_child(enemy)
|
|
||||||
#enemies = []
|
|
||||||
|
|
||||||
questsComplete = true
|
questsComplete = true
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user