diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-09-02 23:36:00 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-09-02 23:36:00 +0200 |
commit | 7d7d845e76f78a87cf87c9464d700e52cd88ce6f (patch) | |
tree | 4d2fc8cd2f8b5b7b0a142c596155de095e1915a2 | |
parent | 14e51610a66099af5cba7cb92876e691fe017216 (diff) |
next commit
-rw-r--r-- | Mob.gd | 17 | ||||
-rw-r--r-- | Mob.tscn | 9 | ||||
-rw-r--r-- | MobPathLine.tscn | 6 | ||||
-rw-r--r-- | mob_path_line.gd | 34 | ||||
-rw-r--r-- | world.gd | 45 | ||||
-rw-r--r-- | world.tscn | 9 |
6 files changed, 75 insertions, 45 deletions
@@ -12,10 +12,12 @@ var is_selected = false : Mob.selected_unit = self selected.emit() $Label.visible = true + line.visible = true else: if Mob.selected_unit == self: Mob.selected_unit = null $Label.visible = false + line.visible = false is_selected = value queue_redraw() @@ -31,7 +33,11 @@ var target: Node2D : var immediate_target: Vector2 var current_path: PackedVector2Array -var current_path_idx = 0 +var current_path_idx = 0 : + set(value): + current_path_idx = value + if line: + line.points = PackedVector2Array(current_path.slice(value)) var previous_path: PackedVector2Array var previous_path_idx = 0 @@ -42,6 +48,8 @@ var recent_closest_paths: Array[PackedVector2Array] var roaming_mode = false +@onready var line: Line2D = $MobPathLine.duplicate() + @export var speed: float = 100 @export var hp = 50 @@ -52,6 +60,8 @@ func _ready(): if not target: target = get_tree().current_scene.find_child("Goal") + get_tree().current_scene.add_child(line) + reset_path() Game.path_grid_changed.connect(func(): reset_path() @@ -165,6 +175,10 @@ func reset_path(): current_path_idx = 0 + if line: + line.points = PackedVector2Array(current_path) + + func get_grid_path(partial = false): return Game.path_grid.get_point_path( Game.map.local_to_map(global_position), @@ -191,3 +205,4 @@ func _on_selection_area_mouse_exited() -> void: func _on_tree_exiting() -> void: is_selected = false + line.queue_free() @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://cslaufgh6ber3"] +[gd_scene load_steps=8 format=3 uid="uid://cslaufgh6ber3"] [ext_resource type="Script" path="res://Mob.gd" id="1_bbcew"] [ext_resource type="Texture2D" uid="uid://dsy7k2v5fhh6v" path="res://Assets/Mobs/angesnow-front.png" id="2_rxqq1"] [ext_resource type="PackedScene" uid="uid://bjcrf4o4a80iv" path="res://HPBar.tscn" id="3_e777u"] +[ext_resource type="PackedScene" uid="uid://cifs0kcy5r0x2" path="res://MobPathLine.tscn" id="4_r0qfv"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_1cqix"] size = Vector2(3, 3) @@ -56,6 +57,12 @@ horizontal_alignment = 1 [node name="CollisionShape2D" type="CollisionShape2D" parent="SelectionArea"] shape = SubResource("RectangleShape2D_o5ax3") +[node name="MobPathLine" parent="." instance=ExtResource("4_r0qfv")] +visible = false +width = 1.0 +default_color = Color(1, 1, 1, 0.392157) +target_circle_radius = 4.0 + [connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/MobPathLine.tscn b/MobPathLine.tscn new file mode 100644 index 0000000..323d1e1 --- /dev/null +++ b/MobPathLine.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://cifs0kcy5r0x2"] + +[ext_resource type="Script" path="res://mob_path_line.gd" id="1_qbhs7"] + +[node name="MobPathLine" type="Line2D"] +script = ExtResource("1_qbhs7") diff --git a/mob_path_line.gd b/mob_path_line.gd new file mode 100644 index 0000000..e7bd4bc --- /dev/null +++ b/mob_path_line.gd @@ -0,0 +1,34 @@ +extends Line2D + + +signal points_changed + +@export_group("Target Circle", "target_circle") +@export_custom(PROPERTY_HINT_NONE, "suffix:px") var target_circle_radius: float = 0.0 +@export var target_circle_color: Color = Color(0,0,0,0) + +@onready var last_points = points + + +func _ready(): + points_changed.connect(func(): + queue_redraw() + ) + + if target_circle_color == Color(0,0,0,0): + target_circle_color = default_color + + +func _process(_delta): + if last_points == points: + points_changed.emit() + + last_points = points + + +func _draw(): + draw_circle( + points[points.size() - 1] - global_position, + target_circle_radius, + default_color + ) @@ -14,48 +14,15 @@ func _ready(): ] ) - #while true: - #var scene = preload("res://Mob.tscn") - #var mob = scene.instantiate() - #add_child(Game.spawn_mob(mob, $Spawn)) - #await get_tree().create_timer(randi_range(1, 2)).timeout - #await get_tree().create_timer(0.01).timeout + while true: + var scene = preload("res://Mob.tscn") + var mob = scene.instantiate() + add_child(Game.spawn_mob(mob, $Spawn)) + await get_tree().create_timer(randi_range(1, 2)).timeout + await get_tree().create_timer(0.01).timeout #break -func _draw(): - if Game.debug: - var area = Game.path_grid.region - var cell_size = Game.path_grid.cell_size - var offset = Game.path_grid.offset + (Game.path_grid.cell_size / 2) - for row in range(0, area.size.y + 1): - draw_line( - Vector2(offset.x, offset.y + row * cell_size.y), - Vector2(offset.x + area.size.x * cell_size.x, offset.y + row * cell_size.y), - Color(1, 1, 0, 0.25), - 1.0 - ) - for column in range(0, area.size.x + 1): - draw_line( - Vector2(offset.x + column * cell_size.x, offset.y), - Vector2(offset.x + column * cell_size.x, offset.y + area.size.y * cell_size.y), - Color(1, 1, 0, 0.25), - 1.0 - ) - - for row in range(0, area.size.y): - for column in range(0, area.size.x): - if Game.path_grid.is_point_solid(Vector2i(column, row)): - draw_circle( - Vector2( - offset.x + column * cell_size.x + cell_size.x/2, - offset.y + row * cell_size.y + cell_size.y/2 - ), - 1, - Color(1, 1, 0, 0.25) - ) - - func _input(event: InputEvent): if event.is_action_pressed("ui_accept"): for _i in range(0, 1): @@ -2205,6 +2205,7 @@ next_node = NodePath("../Goal") position = Vector2(608, 48) [node name="Camera" parent="." instance=ExtResource("6_yijl8")] +position = Vector2(112, 256) zoom = Vector2(1.5, 1.5) drag_horizontal_enabled = true drag_vertical_enabled = true @@ -2218,22 +2219,22 @@ position = Vector2(176, 256) position = Vector2(224, 640) [node name="Tower5" parent="Towers" instance=ExtResource("7_5o3d3")] -position = Vector2(592, 672) +position = Vector2(576, 656) [node name="Tower7" parent="Towers" instance=ExtResource("7_5o3d3")] -position = Vector2(576, 640) +position = Vector2(592, 624) [node name="Tower8" parent="Towers" instance=ExtResource("7_5o3d3")] position = Vector2(208, 672) [node name="Tower11" parent="Towers" instance=ExtResource("7_5o3d3")] -position = Vector2(608, 624) +position = Vector2(624, 640) [node name="Tower12" parent="Towers" instance=ExtResource("7_5o3d3")] position = Vector2(208, 240) [node name="Tower15" parent="Towers" instance=ExtResource("7_5o3d3")] -position = Vector2(624, 656) +position = Vector2(608, 672) [node name="Tower19" parent="Towers" instance=ExtResource("7_5o3d3")] position = Vector2(176, 656) |