forked from team-sg/hero-mark-2
spider implementation! death_blood_offset variable added to enemy.gd to facilitate
This commit is contained in:
parent
b1beffd97b
commit
bc4510a103
6 changed files with 128 additions and 3 deletions
34
objects/enemy/spider.gd
Normal file
34
objects/enemy/spider.gd
Normal file
|
@ -0,0 +1,34 @@
|
|||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
export var speed = 0.0
|
||||
export var direction = 1.0
|
||||
|
||||
onready var line = $Line2D
|
||||
onready var hitbox = $Hitbox
|
||||
|
||||
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
|
||||
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 > floor_y:
|
||||
hitbox.position.y = floor_y
|
||||
direction = -1.0
|
||||
line.points[1].y = hitbox.position.y
|
||||
death_blood_offset = hitbox.position
|
Loading…
Add table
Add a link
Reference in a new issue