trying to figure out the targeting algorithm
This commit is contained in:
parent
8d5495bcaf
commit
5e51ee43b2
@ -12,6 +12,8 @@ grow_vertical = 2
|
||||
script = ExtResource("1_gc1kb")
|
||||
debug = true
|
||||
|
||||
[node name="SpawnTimer" type="Timer" parent="."]
|
||||
|
||||
[node name="SpawnArea" type="PanelContainer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
@ -19,8 +21,6 @@ anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="SpawnTimer" type="Timer" parent="SpawnArea"]
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
@ -76,7 +76,7 @@ size_flags_vertical = 8
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
text = "Spawn Enemies"
|
||||
text = "Complete Quest"
|
||||
|
||||
[node name="TouchScreenButton" type="TouchScreenButton" parent="MarginContainer/Menus/MenuButtons/DebugMenu/ButtonTest"]
|
||||
|
||||
@ -88,6 +88,6 @@ text = "Exit"
|
||||
|
||||
[node name="TouchScreenButton" type="TouchScreenButton" parent="MarginContainer/Menus/MenuButtons/DebugMenu/ButtonExit"]
|
||||
|
||||
[connection signal="timeout" from="SpawnArea/SpawnTimer" to="." method="_on_spawn_timer_timeout"]
|
||||
[connection signal="timeout" from="SpawnTimer" to="." method="_on_spawn_timer_timeout"]
|
||||
[connection signal="pressed" from="MarginContainer/Menus/MenuButtons/DebugMenu/ButtonTest" to="." method="_on_button_test_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/Menus/MenuButtons/DebugMenu/ButtonExit" to="." method="_on_button_exit_pressed"]
|
||||
|
@ -12,6 +12,5 @@ var gearItem = load("gearRand.gd")
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var gearPiece = gearItem.new(tier=2, quality=4)
|
||||
var gearPiece = gearItem.new()
|
||||
print (gearPiece.statValues)
|
||||
quit(
|
||||
|
@ -27,13 +27,24 @@ func _random_mod_health() -> void:
|
||||
self.maxHealth *= 16
|
||||
# npcTier factor
|
||||
self.maxHealth *= exp(self.npcTier)
|
||||
|
||||
# fun factor (just additional factor to tweak)
|
||||
self.maxHealth *= 10
|
||||
|
||||
|
||||
func _init(npcDifficulty: npcDifficulties = npcDifficulties.NORMAL,
|
||||
npcTier: npcTiers = npcTiers.I) -> void:
|
||||
self.npcDifficulty = npcDifficulty
|
||||
self.npcTier = npcTier
|
||||
func _init() -> void:
|
||||
self.npcDifficulty = npcDifficulties.NORMAL
|
||||
self.npcTier = npcTiers.I
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# add to enemies
|
||||
add_to_group("enemies")
|
||||
|
||||
# modify max health value based on the various factors
|
||||
_random_mod_health()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# if damageTaken > maxHealth:
|
||||
# self.free()?
|
||||
# send signal that I died to be counted, etc.
|
||||
pass
|
||||
|
@ -10,7 +10,7 @@ func format_label_difficulty(label: Node, difficulty: NPC.npcDifficulties) -> vo
|
||||
NPC.npcDifficulties.NORMAL:
|
||||
label.label_settings.outline_color = Color.DARK_GREEN
|
||||
label.label_settings.font_color = Color.LIME_GREEN
|
||||
NPC.npcDifficulties.MINIBOSS:
|
||||
NPC.npcDifficulties.ELITE:
|
||||
label.label_settings.outline_color = Color.DARK_BLUE
|
||||
label.label_settings.font_color = Color.DARK_CYAN
|
||||
NPC.npcDifficulties.BOSS:
|
||||
|
@ -8,11 +8,16 @@ var deltaCount := 0
|
||||
var enemyMoveSpeed := 5.0
|
||||
var questsComplete := 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()
|
||||
$SpawnArea/SpawnTimer.start(spawnTimerValue)
|
||||
$SpawnTimer.start(spawnTimerValue)
|
||||
|
||||
func _create_enemy():
|
||||
var enemy = load("res://scenes/npc.tscn").instantiate()
|
||||
@ -21,30 +26,75 @@ func _create_enemy():
|
||||
#enemy.get_node("%NPCNameLabel").text = "Test"
|
||||
|
||||
return enemy
|
||||
|
||||
func _get_enemies() -> Array:
|
||||
var enemies := get_tree().get_nodes_in_group("enemies")
|
||||
return enemies
|
||||
|
||||
|
||||
func _get_num_enemies() -> int:
|
||||
var enemies := get_tree().get_nodes_in_group("enemies")
|
||||
return len(enemies)
|
||||
|
||||
|
||||
func _get_distance_to_player(enemy: Node) -> float:
|
||||
return enemy.position.distance_squared_to(playerPos)
|
||||
|
||||
|
||||
func _get_target() -> Node:
|
||||
# arrays of enemies by difficulty
|
||||
var enemies := _get_enemies()
|
||||
var numEnemies := _get_num_enemies()
|
||||
#var highestDifficulty
|
||||
var enemyDists
|
||||
var closestEnemy
|
||||
# get array of difficulties using map
|
||||
if not enemies.is_empty():
|
||||
# get index of largest non-zero val in numEnemies array, ignoring minions
|
||||
#highestDifficulty = numEnemies.find(0, 1) - 1
|
||||
enemyDists = enemies.map(_get_distance_to_player)
|
||||
closestEnemy = enemies[enemyDists.find(enemyDists.min())]
|
||||
#var closestDist = INF
|
||||
#for enemy in enemies:
|
||||
#var enemyPos = enemy.position
|
||||
#var enemyDist = playerPos.distance_squared_to(enemyPos)
|
||||
#if enemyDist < closestDist:
|
||||
#closestEnemy = enemy
|
||||
print(enemies)
|
||||
#print(highestDifficulty)
|
||||
print(enemyDists)
|
||||
print(closestEnemy)
|
||||
|
||||
return closestEnemy
|
||||
|
||||
|
||||
func _spawn_enemies() -> void:
|
||||
func _spawn_enemies(maxEnemies: int) -> void:
|
||||
#await get_tree().create_timer(time).timeout
|
||||
var middleX := get_viewport_rect().size.x/2
|
||||
var targetPosition = Vector2(middleX, get_viewport_rect().size.y*(0.75))
|
||||
var numEnemies = randi_range(1, 5)
|
||||
var numEnemies = randi_range(1, maxEnemies)
|
||||
for i in range(numEnemies):
|
||||
var enemy = _create_enemy()
|
||||
%SpawnArea.add_child(enemy)
|
||||
var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
|
||||
create_tween().tween_property(enemy, "position", targetPosition, randEnemyMoveSpeed)
|
||||
create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
#var closestEnemy = _get_closest_enemy()
|
||||
deltaCount += 1
|
||||
var enemies := %SpawnArea.get_children()
|
||||
var numEnemies := %SpawnArea.get_child_count()
|
||||
if numEnemies != 0 and (deltaCount % 60) == 0:
|
||||
#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)
|
||||
pass
|
||||
#if deltaCount % 200 == 0:
|
||||
#%SpawnArea.remove_child(closestEnemy)
|
||||
if not _get_enemies().is_empty() and deltaCount % 100 == 0:
|
||||
var targetEnemy = _get_target()
|
||||
$SpawnArea.remove_child(targetEnemy)
|
||||
# change to signal
|
||||
if questsComplete:
|
||||
%SpawnArea/SpawnTimer.stop()
|
||||
$SpawnTimer.stop()
|
||||
if _get_enemies().is_empty():
|
||||
print("Area Complete!")
|
||||
|
||||
|
||||
func _on_button_test_pressed() -> void:
|
||||
@ -61,4 +111,4 @@ func _on_button_exit_pressed() -> void:
|
||||
|
||||
|
||||
func _on_spawn_timer_timeout() -> void:
|
||||
_spawn_enemies()
|
||||
_spawn_enemies(5)
|
||||
|
Loading…
Reference in New Issue
Block a user