tool extends "res://objects/enemy/enemy.gd" enum Direction {HORIZONTAL, VERTICAL} #How far to move export var left_up_boundary = 0.0 setget _set_left_up_boundary export var right_down_boundary = 0.0 setget _set_right_down_boundary #Start direction export var direction = 1 export var speed = 50 #Move horizontal or vertical export(Direction) var move_direction export var node_to_flip: NodePath #Onreadys onready var startpos = position onready var _flipped_node: Node2D = get_node_or_null(node_to_flip) func _ready(): if Engine.editor_hint: return left_up_boundary *= 8 right_down_boundary *= 8 #Easy mode if Game.is_easy_mode == true: speed = speed * Game.easy_mode_speed_factor func _physics_process(delta): if Engine.editor_hint: return if right_down_boundary == 0 and left_up_boundary == 0: return elif move_direction == 0: move_side_to_side(delta) else: move_up_and_down(delta) func move_side_to_side(delta): #Move position.x += direction * (speed * delta) #Switch dir if position.x >= startpos.x + (right_down_boundary): direction = -1 if is_instance_valid(_flipped_node): _flipped_node.scale.x = -1.0 if position.x <= startpos.x + (-left_up_boundary): direction = 1 if is_instance_valid(_flipped_node): _flipped_node.scale.x = 1.0 func move_up_and_down(delta): #Move position.y += direction * (speed * delta) #Switch dir if position.y >= startpos.y + (right_down_boundary): direction = -1 if is_instance_valid(_flipped_node): _flipped_node.scale.y = 1.0 if position.y <= startpos.y + (-left_up_boundary): direction = 1 if is_instance_valid(_flipped_node): _flipped_node.scale.y = -1.0 # editor debug drawing func _draw(): if Engine.editor_hint: match move_direction: Direction.HORIZONTAL: draw_line( Vector2(-left_up_boundary * 8.0, 0.0), Vector2(right_down_boundary * 8.0, 0.0), Color(0.4, 0.2, 0.6, 0.75), 1.01, false ) Direction.VERTICAL: draw_line( Vector2(0.0, -left_up_boundary * 8.0), Vector2(0.0, right_down_boundary * 8.0), Color(0.4, 0.2, 0.6, 0.75), 1.01, false ) func _set_left_up_boundary(value): left_up_boundary = value if Engine.editor_hint: update() func _set_right_down_boundary(value): right_down_boundary = value if Engine.editor_hint: update()