38 lines
988 B
GDScript
38 lines
988 B
GDScript
extends "res://objects/enemy/enemy.gd"
|
|
|
|
export var speed = 0.0
|
|
export var direction = 1.0
|
|
|
|
onready var line = $Line2D
|
|
onready var hitbox = $Hitbox
|
|
|
|
export var up_boundary = 0
|
|
export var down_boundary = 0
|
|
|
|
#var floor_y = 0.0
|
|
|
|
func _ready():
|
|
var raycast = $RayCast2D
|
|
# detect ceiling
|
|
raycast.force_raycast_update()
|
|
var old_y = hitbox.global_position.y
|
|
global_position.y = raycast.get_collision_point().y
|
|
hitbox.global_position.y = old_y
|
|
line.points[1].y = hitbox.position.y
|
|
# detect floor
|
|
raycast.cast_to = Vector2(0.0, 192.0)
|
|
raycast.force_raycast_update()
|
|
#floor_y = to_local(raycast.get_collision_point()).y - 3
|
|
down_boundary *= 8
|
|
raycast.queue_free()
|
|
|
|
func _physics_process(delta):
|
|
hitbox.position.y += direction * speed * delta
|
|
if hitbox.position.y < 5.0:
|
|
hitbox.position.y = 5.0
|
|
direction = 1.0
|
|
if hitbox.position.y > down_boundary:
|
|
hitbox.position.y = down_boundary
|
|
direction = -1.0
|
|
line.points[1].y = hitbox.position.y
|
|
death_blood_offset = hitbox.position
|