59 lines
1.4 KiB
GDScript
59 lines
1.4 KiB
GDScript
extends Area2D
|
|
|
|
class_name Character
|
|
|
|
signal has_moved(direction : Globals.Direction)
|
|
|
|
@onready var RayCastRight : RayCast2D = $RayCastRight;
|
|
@onready var RayCastDown : RayCast2D = $RayCastDown;
|
|
@onready var RayCastUp : RayCast2D = $RayCastUp;
|
|
@onready var RayCastLeft : RayCast2D = $RayCastLeft;
|
|
|
|
|
|
var TileSize : int = 16;
|
|
|
|
|
|
|
|
func move(direction: Globals.Direction) -> bool:
|
|
|
|
var should_emit := false;
|
|
|
|
match direction:
|
|
Globals.Direction.RIGHT:
|
|
var collider : Object = RayCastRight.get_collider()
|
|
if !collider or (collider.is_in_group("box") and collider.go_right()):
|
|
position.x += TileSize
|
|
should_emit = true;
|
|
|
|
Globals.Direction.LEFT:
|
|
var collider : Object = RayCastLeft.get_collider()
|
|
if !collider or (collider.is_in_group("box") and collider.go_left()):
|
|
position.x -= TileSize
|
|
should_emit = true;
|
|
|
|
Globals.Direction.UP:
|
|
var collider : Object = RayCastUp.get_collider()
|
|
if !collider or (collider.is_in_group("box") and collider.go_up()):
|
|
position.y -= TileSize
|
|
should_emit = true;
|
|
|
|
Globals.Direction.DOWN:
|
|
var collider : Object = RayCastDown.get_collider()
|
|
if !collider or (collider.is_in_group("box") and collider.go_down()):
|
|
position.y += TileSize
|
|
should_emit = true;
|
|
|
|
Globals.Direction.NONE:
|
|
pass
|
|
|
|
_:
|
|
print("WTTFF");
|
|
print(direction);
|
|
|
|
|
|
|
|
if should_emit:
|
|
emit_signal("has_moved", direction);
|
|
|
|
return should_emit;
|
|
|