Compare commits
3 Commits
7136b07de5
...
156da4898e
Author | SHA1 | Date | |
---|---|---|---|
156da4898e
|
|||
ac8ffdcd96
|
|||
56278de1d7
|
@@ -10,6 +10,8 @@ signal sig_debug_enemy_god_mode(value: bool)
|
|||||||
signal sig_debug_stats_set(key: String, value: String)
|
signal sig_debug_stats_set(key: String, value: String)
|
||||||
@warning_ignore("unused_signal")
|
@warning_ignore("unused_signal")
|
||||||
signal sig_stop_spawning(value: bool)
|
signal sig_stop_spawning(value: bool)
|
||||||
|
@warning_ignore("unused_signal")
|
||||||
|
signal sig_set_spawn_rate(value: float)
|
||||||
|
|
||||||
const GROUP_ENEMY = "enemy"
|
const GROUP_ENEMY = "enemy"
|
||||||
const GROUP_DAMAGEABLE = "damagable"
|
const GROUP_DAMAGEABLE = "damagable"
|
||||||
|
@@ -5,7 +5,7 @@ extends CharacterBody2D
|
|||||||
@export var max_health: float = 10.0
|
@export var max_health: float = 10.0
|
||||||
@export var default_contact_damage: float = 0.0
|
@export var default_contact_damage: float = 0.0
|
||||||
@export var target_distance: float = 6.0
|
@export var target_distance: float = 6.0
|
||||||
@export var path_update_interval: float = 0.5
|
@export var path_update_interval: float = 1.5
|
||||||
|
|
||||||
@onready var target_cast: RayCast2D = $TargetCast
|
@onready var target_cast: RayCast2D = $TargetCast
|
||||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
@@ -48,14 +48,13 @@ func do_movement(delta: float) -> void:
|
|||||||
return
|
return
|
||||||
if global_position.distance_to(target.global_position) < target_distance:
|
if global_position.distance_to(target.global_position) < target_distance:
|
||||||
return
|
return
|
||||||
_path_update_timer -= delta
|
_path_update_timer -= delta + randf()
|
||||||
if _has_direct_path():
|
if _has_direct_path():
|
||||||
shape_cast_2d.enabled = false
|
shape_cast_2d.enabled = false
|
||||||
_do_simple_movement()
|
_do_simple_movement()
|
||||||
else:
|
else:
|
||||||
_do_nav_agent_movement()
|
_do_nav_agent_movement()
|
||||||
|
|
||||||
|
|
||||||
func _has_direct_path():
|
func _has_direct_path():
|
||||||
target_cast.target_position = to_local(target.global_position)
|
target_cast.target_position = to_local(target.global_position)
|
||||||
target_cast.enabled = true
|
target_cast.enabled = true
|
||||||
|
@@ -56,7 +56,6 @@ shape = SubResource("CircleShape2D_satqt")
|
|||||||
|
|
||||||
[node name="TargetCast" type="RayCast2D" parent="." groups=["damagable", "enemy"]]
|
[node name="TargetCast" type="RayCast2D" parent="." groups=["damagable", "enemy"]]
|
||||||
enabled = false
|
enabled = false
|
||||||
collision_mask = 3
|
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
libraries = {
|
libraries = {
|
||||||
@@ -71,5 +70,6 @@ wait_time = 0.5
|
|||||||
|
|
||||||
[node name="ShapeCast2D" type="ShapeCast2D" parent="."]
|
[node name="ShapeCast2D" type="ShapeCast2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_pkqou")
|
shape = SubResource("CircleShape2D_pkqou")
|
||||||
|
max_results = 2
|
||||||
|
|
||||||
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
|
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
|
||||||
|
@@ -14,7 +14,6 @@ func _process(delta: float) -> void:
|
|||||||
elapsed_time += delta
|
elapsed_time += delta
|
||||||
main_ui.player_ui.set_elapsed_time(elapsed_time)
|
main_ui.player_ui.set_elapsed_time(elapsed_time)
|
||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("ui_cancel"):
|
if event.is_action_pressed("ui_cancel"):
|
||||||
main_ui.pause_ui.toggle_pause_ui()
|
main_ui.pause_ui.toggle_pause_ui()
|
||||||
|
@@ -11,9 +11,10 @@ const ENEMY_RAT = preload("res://scenes/enemies/enemy_rat.tscn")
|
|||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
timer.wait_time = spawn_rate / 1
|
timer.wait_time = 1 / spawn_rate
|
||||||
timer.start()
|
timer.start()
|
||||||
GlobalConst.sig_stop_spawning.connect(_on_stop_spawning)
|
GlobalConst.sig_stop_spawning.connect(_on_stop_spawning)
|
||||||
|
GlobalConst.sig_set_spawn_rate.connect(_on_set_spawn_rate)
|
||||||
|
|
||||||
|
|
||||||
func _on_timer_timeout() -> void:
|
func _on_timer_timeout() -> void:
|
||||||
@@ -25,9 +26,11 @@ func _on_timer_timeout() -> void:
|
|||||||
new_enemy.target = target
|
new_enemy.target = target
|
||||||
add_child(new_enemy)
|
add_child(new_enemy)
|
||||||
|
|
||||||
|
|
||||||
func _on_stop_spawning(val: bool):
|
func _on_stop_spawning(val: bool):
|
||||||
if val:
|
if val:
|
||||||
timer.stop()
|
timer.stop()
|
||||||
elif timer.is_stopped():
|
elif timer.is_stopped():
|
||||||
timer.start()
|
timer.start()
|
||||||
|
|
||||||
|
func _on_set_spawn_rate(val: float):
|
||||||
|
timer.wait_time = 1 / val
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
[node name="EnemyManager" type="Node2D"]
|
[node name="EnemyManager" type="Node2D"]
|
||||||
script = ExtResource("1_tfsap")
|
script = ExtResource("1_tfsap")
|
||||||
max_enemies = 50
|
max_enemies = 500
|
||||||
spawn_rate = 1.0
|
spawn_rate = 1.0
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
|
@@ -75,3 +75,7 @@ func update_debug_stats() -> void:
|
|||||||
|
|
||||||
func _on_time_scale_slider_value_changed(value: float) -> void:
|
func _on_time_scale_slider_value_changed(value: float) -> void:
|
||||||
Engine.time_scale = value
|
Engine.time_scale = value
|
||||||
|
|
||||||
|
|
||||||
|
func _on_spawn_rate_value_changed(value: float) -> void:
|
||||||
|
GlobalConst.sig_set_spawn_rate.emit(value)
|
||||||
|
@@ -154,6 +154,27 @@ max_value = 1.0
|
|||||||
step = 0.1
|
step = 0.1
|
||||||
value = 1.0
|
value = 1.0
|
||||||
|
|
||||||
|
[node name="MarginContainer2" type="MarginContainer" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
theme_override_constants/margin_left = 6
|
||||||
|
theme_override_constants/margin_right = 6
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer2"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer2/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
text = "Spawn rate"
|
||||||
|
|
||||||
|
[node name="SpawnRate" type="HSlider" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer2/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
max_value = 10.0
|
||||||
|
step = 0.1
|
||||||
|
value = 1.0
|
||||||
|
|
||||||
[node name="StatsContainer" type="PanelContainer" parent="CanvasLayer/DebugUI"]
|
[node name="StatsContainer" type="PanelContainer" parent="CanvasLayer/DebugUI"]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_left = 938.0
|
offset_left = 938.0
|
||||||
@@ -176,3 +197,4 @@ layout_mode = 2
|
|||||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/EnemyGodModeCheck" to="CanvasLayer/DebugUI" method="_on_enemy_god_mode_check_toggled"]
|
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/EnemyGodModeCheck" to="CanvasLayer/DebugUI" method="_on_enemy_god_mode_check_toggled"]
|
||||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/StatsCheck" to="CanvasLayer/DebugUI" method="_on_stats_check_toggled"]
|
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/StatsCheck" to="CanvasLayer/DebugUI" method="_on_stats_check_toggled"]
|
||||||
[connection signal="value_changed" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer/HBoxContainer/TimeScaleSlider" to="CanvasLayer/DebugUI" method="_on_time_scale_slider_value_changed"]
|
[connection signal="value_changed" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer/HBoxContainer/TimeScaleSlider" to="CanvasLayer/DebugUI" method="_on_time_scale_slider_value_changed"]
|
||||||
|
[connection signal="value_changed" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer2/HBoxContainer/SpawnRate" to="CanvasLayer/DebugUI" method="_on_spawn_rate_value_changed"]
|
||||||
|
Reference in New Issue
Block a user