debug drawing of moving enemy paths

This commit is contained in:
Haze Weathers 2023-03-22 02:58:58 -04:00
parent 5862958924
commit 563bb46a44
2 changed files with 76 additions and 5 deletions

View file

@ -1,8 +1,9 @@
tool
extends "res://objects/enemy/enemy.gd"
export var walk_speed = 25.0
export var left_boundary = 0.0
export var right_boundary = 0.0
export var left_boundary = 0.0 setget _set_left_boundary
export var right_boundary = 0.0 setget _set_right_boundary
export var direction = 1.0
export var idle_turns = 4
export var turn_time = 0.5
@ -19,6 +20,9 @@ var shooting = false
var turns = 0
func _ready():
if Engine.editor_hint:
update()
return
# convert boundaries into actual coordinate positions
left_boundary = position.x - left_boundary * 8.0
right_boundary = position.x + right_boundary * 8.0
@ -28,6 +32,8 @@ func _ready():
sprite.speed_scale = inverse_lerp(0.0, 25.0, walk_speed)
func _physics_process(delta):
if Engine.editor_hint:
return
if !shooting:
# check for player in raycast
var collider = shoot_cast.get_collider()
@ -84,3 +90,34 @@ func _stop_shoot():
sprite.play("walk")
else:
sprite.play("idle")
# editor debug drawing
func _draw():
if Engine.editor_hint:
var left = -left_boundary * 8.0
var right = right_boundary * 8.0
draw_line(
Vector2(left, 0.0),
Vector2(right, 0.0),
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
)
draw_line(
Vector2(left, 2.0),
Vector2(left, -2.0),
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
)
draw_line(
Vector2(right, 2.0),
Vector2(right, -2.0),
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
)
func _set_left_boundary(value):
left_boundary = value
if Engine.editor_hint:
update()
func _set_right_boundary(value):
right_boundary = value
if Engine.editor_hint:
update()

View file

@ -1,23 +1,30 @@
tool
extends "res://objects/enemy/enemy.gd"
enum Direction {HORIZONTAL, VERTICAL}
#How far to move
export var left_up_boundary = 0.0
export var right_down_boundary = 0.0
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(int, "Horizontal", "Vertical") var move_direction
export(Direction) var move_direction
export var flip_sprite = true
#Onreadys
onready var startpos = position
onready var sprite = $AnimatedSprite
func _ready():
if Engine.editor_hint:
return
left_up_boundary *= 8
right_down_boundary *= 8
func _physics_process(delta):
if Engine.editor_hint:
return
if right_down_boundary == 0 and left_up_boundary == 0:
return
elif move_direction == 0:
@ -45,3 +52,30 @@ func move_up_and_down(delta):
if position.y <= startpos.y + (-left_up_boundary):
direction = 1
if flip_sprite == true: sprite.scale.y = -1
# 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()