revo-jailbreak/objects/enemy/enemy_speedup_in_range.gd
Hazel Snider a2974d8dd3 the damage system refactor!
killing is now done based on groups, the same way enemies already killed
the player.

these groups go on the entity's hitbox, not the entity itself.
enemies' hitboxes have all been put in "enemy_hitbox"

the arrow_projectile has a variable for the target group, so it could
easily be simply set to "player" for arrows shot by enemies

blocking is also done with groups. any hitbox with "blocks_arrow"
will block arrows, same with "blocks_sword" and "blocks_squash"
2023-01-20 00:06:34 -05:00

65 lines
1.7 KiB
GDScript

extends "res://objects/enemy/enemy.gd"
#How far to move
export var left_up_boundry = 0.0
export var right_down_boundry = 0.0
#Start direction
export var direction = 1
export var slower_speed = 50
export var faster_speed = 100
#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
onready var raycast = $Hitbox/RayCast2D
onready var timer = $Timer
var speed = 50
var go_fast = false
func _physics_process(delta):
if move_direction == 0:
move_side_to_side(delta)
else: move_up_and_down(delta)
#Speed up if in raycast
if raycast.get_collider() != null:
if raycast.get_collider().is_in_group("player"):
go_fast = true
timer.set_wait_time(0.5)
timer.start()
#chnage speed depedning on you know
if go_fast:
speed = faster_speed
else:
speed = slower_speed
#flip raycast with sprite
raycast.scale.x = sprite.scale.x
func move_side_to_side(delta):
#Move
position.x += direction * (speed * delta)
#Switch dir
if position.x >= startpos.x + (right_down_boundry * 8):
direction = -1
if flip_sprite == true: sprite.scale.x = -1
if position.x <= startpos.x + (-left_up_boundry * 8):
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_boundry * 8):
direction = -1
if flip_sprite == true: sprite.scale.y = 1
if position.y <= startpos.y + (-left_up_boundry * 8):
direction = 1
if flip_sprite == true: sprite.scale.y = -1
func _on_Timer_timeout():
go_fast = false