forked from team-sg/hero-mark-2
debug drawing of moving enemy paths
This commit is contained in:
parent
5862958924
commit
563bb46a44
2 changed files with 76 additions and 5 deletions
|
@ -1,8 +1,9 @@
|
||||||
|
tool
|
||||||
extends "res://objects/enemy/enemy.gd"
|
extends "res://objects/enemy/enemy.gd"
|
||||||
|
|
||||||
export var walk_speed = 25.0
|
export var walk_speed = 25.0
|
||||||
export var left_boundary = 0.0
|
export var left_boundary = 0.0 setget _set_left_boundary
|
||||||
export var right_boundary = 0.0
|
export var right_boundary = 0.0 setget _set_right_boundary
|
||||||
export var direction = 1.0
|
export var direction = 1.0
|
||||||
export var idle_turns = 4
|
export var idle_turns = 4
|
||||||
export var turn_time = 0.5
|
export var turn_time = 0.5
|
||||||
|
@ -19,6 +20,9 @@ var shooting = false
|
||||||
var turns = 0
|
var turns = 0
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
if Engine.editor_hint:
|
||||||
|
update()
|
||||||
|
return
|
||||||
# convert boundaries into actual coordinate positions
|
# convert boundaries into actual coordinate positions
|
||||||
left_boundary = position.x - left_boundary * 8.0
|
left_boundary = position.x - left_boundary * 8.0
|
||||||
right_boundary = position.x + right_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)
|
sprite.speed_scale = inverse_lerp(0.0, 25.0, walk_speed)
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
return
|
||||||
if !shooting:
|
if !shooting:
|
||||||
# check for player in raycast
|
# check for player in raycast
|
||||||
var collider = shoot_cast.get_collider()
|
var collider = shoot_cast.get_collider()
|
||||||
|
@ -84,3 +90,34 @@ func _stop_shoot():
|
||||||
sprite.play("walk")
|
sprite.play("walk")
|
||||||
else:
|
else:
|
||||||
sprite.play("idle")
|
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()
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
|
tool
|
||||||
extends "res://objects/enemy/enemy.gd"
|
extends "res://objects/enemy/enemy.gd"
|
||||||
|
|
||||||
|
enum Direction {HORIZONTAL, VERTICAL}
|
||||||
|
|
||||||
#How far to move
|
#How far to move
|
||||||
export var left_up_boundary = 0.0
|
export var left_up_boundary = 0.0 setget _set_left_up_boundary
|
||||||
export var right_down_boundary = 0.0
|
export var right_down_boundary = 0.0 setget _set_right_down_boundary
|
||||||
#Start direction
|
#Start direction
|
||||||
export var direction = 1
|
export var direction = 1
|
||||||
export var speed = 50
|
export var speed = 50
|
||||||
#Move horizontal or vertical
|
#Move horizontal or vertical
|
||||||
export(int, "Horizontal", "Vertical") var move_direction
|
export(Direction) var move_direction
|
||||||
export var flip_sprite = true
|
export var flip_sprite = true
|
||||||
#Onreadys
|
#Onreadys
|
||||||
onready var startpos = position
|
onready var startpos = position
|
||||||
onready var sprite = $AnimatedSprite
|
onready var sprite = $AnimatedSprite
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
if Engine.editor_hint:
|
||||||
|
return
|
||||||
left_up_boundary *= 8
|
left_up_boundary *= 8
|
||||||
right_down_boundary *= 8
|
right_down_boundary *= 8
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
return
|
||||||
if right_down_boundary == 0 and left_up_boundary == 0:
|
if right_down_boundary == 0 and left_up_boundary == 0:
|
||||||
return
|
return
|
||||||
elif move_direction == 0:
|
elif move_direction == 0:
|
||||||
|
@ -45,3 +52,30 @@ func move_up_and_down(delta):
|
||||||
if position.y <= startpos.y + (-left_up_boundary):
|
if position.y <= startpos.y + (-left_up_boundary):
|
||||||
direction = 1
|
direction = 1
|
||||||
if flip_sprite == true: sprite.scale.y = -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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue