|
@@ -1,45 +1,80 @@
|
|
|
extends Node
|
|
|
|
|
|
-onready var hero = get_node("Hero_character/hero_kinematic_body")
|
|
|
-var is_moving = false
|
|
|
+onready var hero = get_node("hero_kinematic_body")
|
|
|
+onready var levelNavigation = get_node("LevelNavigation")
|
|
|
+
|
|
|
+#var is_moving = false
|
|
|
+onready var SPEED = 40
|
|
|
+var velocity = Vector2.ZERO
|
|
|
+var position = null
|
|
|
+
|
|
|
+var path = []
|
|
|
|
|
|
# Add more variables if there are more zones
|
|
|
-var zone_sizes = {1:[Vector2(256, 160), Vector2(0, 0), false],
|
|
|
-2:[Vector2(160, 128), Vector2(0, 192), false],
|
|
|
-3:[Vector2(288, 160), Vector2(192, 160), false],
|
|
|
-4:[Vector2(256, 128), Vector2(256, 0), false],
|
|
|
-5:[Vector2(160, 160), Vector2(544, 0), false],
|
|
|
-6:[Vector2(160, 96), Vector2(544, 224), false]}
|
|
|
+#var zone_sizes = {1:[Vector2(512, 320), Vector2(-1600, -64), false],
|
|
|
+#2:[Vector2(512, 256), Vector2(-1088, -64), false],
|
|
|
+#3:[Vector2(320, 256), Vector2(-1600, 320), false],
|
|
|
+#4:[Vector2(576, 320), Vector2(-1216, 256), false],
|
|
|
+#5:[Vector2(320, 192), Vector2(-512, 384), false],
|
|
|
+#6:[Vector2(320, 320), Vector2(-512, -64), false]}
|
|
|
+#
|
|
|
+#
|
|
|
+#func pick_random_point():
|
|
|
+# var position_to_go_to = Vector2.ZERO
|
|
|
+# var needed_zone = 0
|
|
|
+#
|
|
|
+# var rng = RandomNumberGenerator.new()
|
|
|
+# rng.randomize()
|
|
|
+# needed_zone = round(rng.randf_range(1, 6))
|
|
|
+#
|
|
|
+# while zone_sizes[int(needed_zone)][2] != false:
|
|
|
+# needed_zone = round(rng.randf_range(1, 6))
|
|
|
+#
|
|
|
+# position_to_go_to.x = rng.randf_range(0, zone_sizes[int(needed_zone)][0].x)
|
|
|
+# position_to_go_to.y = rng.randf_range(0, zone_sizes[int(needed_zone)][0].y)
|
|
|
+#
|
|
|
+# position_to_go_to.x += zone_sizes[int(needed_zone)][1].x
|
|
|
+# position_to_go_to.y += zone_sizes[int(needed_zone)][1].y
|
|
|
+#
|
|
|
+# $Line2D.add_point(position_to_go_to)
|
|
|
+# $Line2D.add_point(position_to_go_to + Vector2(20, 20))
|
|
|
+# return position_to_go_to
|
|
|
|
|
|
|
|
|
-func pick_random_point():
|
|
|
- var position_to_go_to = Vector2.ZERO
|
|
|
- var needed_zone = 0
|
|
|
-
|
|
|
- var rng = RandomNumberGenerator.new()
|
|
|
- rng.randomize()
|
|
|
- needed_zone = round(rng.randf_range(1, 6))
|
|
|
-
|
|
|
- while zone_sizes[int(needed_zone)][2] != false:
|
|
|
- needed_zone = round(rng.randf_range(1, 6))
|
|
|
-
|
|
|
- position_to_go_to.x = rng.randf_range(0, zone_sizes[int(needed_zone)][0].x)
|
|
|
- position_to_go_to.y = rng.randf_range(0, zone_sizes[int(needed_zone)][0].y)
|
|
|
-
|
|
|
- position_to_go_to.x += zone_sizes[int(needed_zone)][1].x
|
|
|
- position_to_go_to.y += zone_sizes[int(needed_zone)][1].y
|
|
|
+func generate_path(path_to_move_to):
|
|
|
+ path = levelNavigation.get_simple_path(hero.global_position, path_to_move_to, false)
|
|
|
+ print(path)
|
|
|
+# $Line2D.points = path
|
|
|
+
|
|
|
+
|
|
|
+func navigate():
|
|
|
+ if path.size() > 0:
|
|
|
+ velocity = hero.global_position.direction_to(path[1]) * SPEED
|
|
|
+
|
|
|
+ if hero.global_position == path[0]:
|
|
|
+ path.pop_front()
|
|
|
|
|
|
- return position_to_go_to
|
|
|
+# print(path[0])
|
|
|
+# print(hero.global_position)
|
|
|
|
|
|
|
|
|
func move_to_random_point():
|
|
|
- var position = pick_random_point()
|
|
|
- is_moving = true
|
|
|
+# is_moving = true
|
|
|
+ velocity = hero.move_and_slide(velocity)
|
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
- if is_moving == false:
|
|
|
- move_to_random_point()
|
|
|
-
|
|
|
if Input.is_action_just_pressed("left_mouse_button"):
|
|
|
- pass
|
|
|
+ position = hero.get_global_mouse_position()
|
|
|
+# print(velocity)
|
|
|
+# $Line2D.global_position = Vector2.ZERO
|
|
|
+ if hero != null and levelNavigation != null:
|
|
|
+ if position != null:
|
|
|
+# is_moving = true
|
|
|
+ generate_path(position)
|
|
|
+ print(position)
|
|
|
+
|
|
|
+ else:
|
|
|
+ navigate()
|
|
|
+
|
|
|
+ move_to_random_point()
|