Compare commits
No commits in common. "308967fccc760a03ed6fd4fe26d9dc2271fb6f99" and "6951a80fdb2da7ddfbe74d612cfd2c2513e87138" have entirely different histories.
308967fccc
...
6951a80fdb
|
@ -10,9 +10,21 @@ script = ExtResource("1_44r7b")
|
||||||
texture = ExtResource("1_5amrr")
|
texture = ExtResource("1_5amrr")
|
||||||
centered = false
|
centered = false
|
||||||
|
|
||||||
[node name="MoveRay" type="RayCast2D" parent="."]
|
[node name="UpCast" type="RayCast2D" parent="."]
|
||||||
position = Vector2(8, 8)
|
position = Vector2(8, 8)
|
||||||
target_position = Vector2(0, 0)
|
target_position = Vector2(0, -16)
|
||||||
|
|
||||||
|
[node name="LeftCast" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
|
target_position = Vector2(-16, 0)
|
||||||
|
|
||||||
|
[node name="DownCast" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
|
target_position = Vector2(0, 16)
|
||||||
|
|
||||||
|
[node name="RightCast" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
|
target_position = Vector2(16, 0)
|
||||||
|
|
||||||
[node name="MoveTimer" type="Timer" parent="."]
|
[node name="MoveTimer" type="Timer" parent="."]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
|
@ -4,13 +4,13 @@ const TILE_SIZE : int = 16
|
||||||
|
|
||||||
const MOVE_TIME : float = 0.2
|
const MOVE_TIME : float = 0.2
|
||||||
|
|
||||||
|
enum {UP,LEFT,DOWN,RIGHT,NONE = -1}
|
||||||
|
|
||||||
|
@onready var DirectionCast : Array[RayCast2D] = [$UpCast,$LeftCast,$DownCast,$RightCast]
|
||||||
|
|
||||||
@onready var MoveTimer : Timer = $MoveTimer
|
@onready var MoveTimer : Timer = $MoveTimer
|
||||||
|
|
||||||
@onready var MoveRay : RayCast2D = $MoveRay
|
var direction : int
|
||||||
|
|
||||||
var direction : Vector2i
|
|
||||||
|
|
||||||
var last_direction : Vector2i
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -19,43 +19,40 @@ func _ready() -> void:
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
direction = Vector2i(0,0)
|
direction = NONE
|
||||||
|
|
||||||
if Input.is_action_pressed("ui_left"):
|
if Input.is_action_pressed("ui_left"):
|
||||||
direction.x -= 1
|
direction = LEFT
|
||||||
if Input.is_action_just_pressed("ui_left"):
|
if Input.is_action_just_pressed("ui_left"):
|
||||||
last_direction = Vector2i(-1,0)
|
|
||||||
move()
|
move()
|
||||||
|
|
||||||
if Input.is_action_pressed("ui_right"):
|
if Input.is_action_pressed("ui_right"):
|
||||||
direction.x += 1
|
direction = RIGHT
|
||||||
if Input.is_action_just_pressed("ui_right"):
|
if Input.is_action_just_pressed("ui_right"):
|
||||||
last_direction = Vector2i(1,0)
|
|
||||||
move()
|
move()
|
||||||
|
|
||||||
if Input.is_action_pressed("ui_up"):
|
if Input.is_action_pressed("ui_up"):
|
||||||
direction.y -= 1
|
direction = UP
|
||||||
if Input.is_action_just_pressed("ui_up"):
|
if Input.is_action_just_pressed("ui_up"):
|
||||||
last_direction = Vector2i(0,-1)
|
|
||||||
move()
|
move()
|
||||||
|
|
||||||
if Input.is_action_pressed("ui_down"):
|
if Input.is_action_pressed("ui_down"):
|
||||||
direction.y += 1
|
direction = DOWN
|
||||||
if Input.is_action_just_pressed("ui_down"):
|
if Input.is_action_just_pressed("ui_down"):
|
||||||
last_direction = Vector2i(0,1)
|
|
||||||
move()
|
move()
|
||||||
|
|
||||||
if MoveTimer.is_stopped():
|
if MoveTimer.is_stopped():
|
||||||
move()
|
move()
|
||||||
|
|
||||||
|
|
||||||
func move() -> void:
|
func move() -> void:
|
||||||
if last_direction.x:
|
if direction == LEFT and not DirectionCast[LEFT].is_colliding():
|
||||||
direction.y = 0
|
position.x -= TILE_SIZE
|
||||||
if last_direction.y:
|
if direction == RIGHT and not DirectionCast[RIGHT].is_colliding():
|
||||||
direction.x = 0
|
position.x += TILE_SIZE
|
||||||
|
if direction == UP and not DirectionCast[UP].is_colliding():
|
||||||
MoveRay.target_position = Vector2(TILE_SIZE * direction)
|
position.y -= TILE_SIZE
|
||||||
MoveRay.force_raycast_update()
|
if direction == DOWN and not DirectionCast[DOWN].is_colliding():
|
||||||
|
position.y += TILE_SIZE
|
||||||
if not MoveRay.is_colliding():
|
|
||||||
position += Vector2(TILE_SIZE * direction)
|
|
||||||
|
|
||||||
|
|
||||||
MoveTimer.start(MOVE_TIME)
|
MoveTimer.start(MOVE_TIME)
|
||||||
|
|
Loading…
Reference in a new issue