forked from team-sg/hero-mark-2
rolling fiend mark 3....
This commit is contained in:
parent
58eae4a8f7
commit
153f11aea2
1 changed files with 13 additions and 10 deletions
|
@ -1,30 +1,33 @@
|
|||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
const DIRS = [Vector2.DOWN, Vector2.RIGHT, Vector2.UP, Vector2.LEFT]
|
||||
|
||||
export var move_speed: float = 0.0
|
||||
export var clockwise: bool = false
|
||||
|
||||
onready var floor_test = Physics2DShapeQueryParameters.new()
|
||||
onready var test_shape = $FloorTestShape
|
||||
|
||||
var floor_direction = Vector2.ZERO
|
||||
var floor_direction = 0
|
||||
|
||||
func _ready():
|
||||
if clockwise:
|
||||
$AnimatedSprite.flip_h = true
|
||||
floor_test.set_shape(test_shape.shape)
|
||||
floor_test.collision_layer = 1
|
||||
for dir in [Vector2.DOWN, Vector2.UP, Vector2.LEFT, Vector2.RIGHT]:
|
||||
if is_on_surface(dir):
|
||||
floor_direction = dir
|
||||
for i in DIRS.size():
|
||||
if is_on_surface(DIRS[i]):
|
||||
floor_direction = i
|
||||
break
|
||||
|
||||
func _physics_process(delta):
|
||||
var rot_dir = -1.5708 if clockwise else 1.5708
|
||||
if !is_on_surface(floor_direction):
|
||||
floor_direction = floor_direction.rotated(-rot_dir)
|
||||
elif is_on_surface(floor_direction.rotated(rot_dir)):
|
||||
floor_direction = floor_direction.rotated(rot_dir)
|
||||
position += floor_direction.rotated(rot_dir) * move_speed * delta
|
||||
var offset = -1 if clockwise else 1
|
||||
var move_dir = posmod(floor_direction + offset, DIRS.size())
|
||||
if !is_on_surface(DIRS[floor_direction]):
|
||||
floor_direction = posmod(floor_direction - offset, DIRS.size())
|
||||
elif is_on_surface(DIRS[move_dir]):
|
||||
floor_direction = move_dir
|
||||
position += DIRS[posmod(floor_direction + offset, DIRS.size())] * move_speed * delta
|
||||
|
||||
func is_on_surface(dir):
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue