47 lines
1.3 KiB
GDScript
47 lines
1.3 KiB
GDScript
extends "res://objects/enemy/enemy.gd"
|
|
|
|
#How far to move
|
|
export var left_up_boundary = 0.0
|
|
export var right_down_boundary = 0.0
|
|
#Start direction
|
|
export var direction = 1
|
|
export var speed = 50
|
|
#Move horizontal or vertical
|
|
export(int, "Horizontal", "Vertical") var move_direction
|
|
export var flip_sprite = true
|
|
#Onreadys
|
|
onready var startpos = position
|
|
onready var sprite = $AnimatedSprite
|
|
|
|
func _ready():
|
|
left_up_boundary *= 8
|
|
right_down_boundary *= 8
|
|
|
|
func _physics_process(delta):
|
|
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 flip_sprite == true: sprite.scale.x = -1
|
|
if position.x <= startpos.x + (-left_up_boundary):
|
|
direction = 1
|
|
if flip_sprite == true: sprite.scale.x = 1
|
|
|
|
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 flip_sprite == true: sprite.scale.y = 1
|
|
if position.y <= startpos.y + (-left_up_boundary):
|
|
direction = 1
|
|
if flip_sprite == true: sprite.scale.y = -1
|