|
@@ -1,11 +1,27 @@
|
|
extends Area2D
|
|
extends Area2D
|
|
|
|
|
|
var direction = Vector2()
|
|
var direction = Vector2()
|
|
|
|
+
|
|
const DEG_UP = 0
|
|
const DEG_UP = 0
|
|
const DEG_RIGHT = 90
|
|
const DEG_RIGHT = 90
|
|
const DEG_DOWN = 180
|
|
const DEG_DOWN = 180
|
|
const DEG_LEFT = 270
|
|
const DEG_LEFT = 270
|
|
|
|
|
|
|
|
+const DEG_LIST = [DEG_UP, DEG_RIGHT, DEG_DOWN, DEG_LEFT]
|
|
|
|
+
|
|
|
|
+const DIR_UP = 0
|
|
|
|
+const DIR_RIGHT = 1
|
|
|
|
+const DIR_DOWN = 2
|
|
|
|
+const DIR_LEFT = 3
|
|
|
|
+
|
|
|
|
+var posix
|
|
|
|
+var posiy
|
|
|
|
+
|
|
|
|
+var dirx = 0
|
|
|
|
+var diry = 0
|
|
|
|
+
|
|
|
|
+var dire = DIR_UP
|
|
|
|
+
|
|
var grid
|
|
var grid
|
|
|
|
|
|
var blocks = []
|
|
var blocks = []
|
|
@@ -19,27 +35,34 @@ var raycast
|
|
func _ready():
|
|
func _ready():
|
|
grid = get_parent()
|
|
grid = get_parent()
|
|
|
|
|
|
- turn(Vector2(0,1))
|
|
|
|
|
|
+ posix = int (position.x / 64)
|
|
|
|
+ posiy = int (position.y / 64)
|
|
|
|
+
|
|
|
|
+ turn(DIR_UP)
|
|
pass
|
|
pass
|
|
|
|
|
|
func _physics_process(delta):
|
|
func _physics_process(delta):
|
|
- direction = Vector2()
|
|
|
|
|
|
|
|
- if Input.is_action_pressed("ui_up"):
|
|
|
|
- direction.y -= 1
|
|
|
|
- elif Input.is_action_pressed("ui_down"):
|
|
|
|
- direction.y += 1
|
|
|
|
- elif Input.is_action_pressed("ui_left"):
|
|
|
|
- direction.x -= 1
|
|
|
|
|
|
+ if Input.is_action_pressed("ui_left"):
|
|
|
|
+ dire -= 1
|
|
|
|
+ if dire < 0:
|
|
|
|
+ dire = 3
|
|
|
|
+ update_avatar_dir()
|
|
|
|
+
|
|
elif Input.is_action_pressed("ui_right"):
|
|
elif Input.is_action_pressed("ui_right"):
|
|
- direction.x += 1
|
|
|
|
-
|
|
|
|
- if direction != Vector2():
|
|
|
|
|
|
+ dire += 1
|
|
|
|
+ if dire > 3:
|
|
|
|
+ dire = 0
|
|
|
|
+ update_avatar_dir()
|
|
|
|
+
|
|
|
|
+ if Input.is_action_pressed("ui_up"):
|
|
|
|
|
|
- turn(direction)
|
|
|
|
|
|
+ turn(dire)
|
|
|
|
|
|
if !raycast.is_colliding():
|
|
if !raycast.is_colliding():
|
|
- position = get_position() + direction * grid.get_cell_size()
|
|
|
|
|
|
+ posix += dirx
|
|
|
|
+ posiy += diry
|
|
|
|
+ position = Vector2(posix * 64 + 32, posiy * 64 + 32)
|
|
pass
|
|
pass
|
|
|
|
|
|
func _on_area_entered(a):
|
|
func _on_area_entered(a):
|
|
@@ -54,13 +77,22 @@ func _on_area_exited(a):
|
|
is_blocked = blocks.size()
|
|
is_blocked = blocks.size()
|
|
pass
|
|
pass
|
|
|
|
|
|
-func turn(dir:Vector2):
|
|
|
|
- if dir.y < 0:
|
|
|
|
|
|
+func turn(dir:int):
|
|
|
|
+ dirx = 0
|
|
|
|
+ diry = 0
|
|
|
|
+ if dir == DIR_UP:
|
|
raycast=get_node(rayU)
|
|
raycast=get_node(rayU)
|
|
- elif dir.x < 0:
|
|
|
|
- raycast=get_node(rayL)
|
|
|
|
- elif dir.x > 0:
|
|
|
|
|
|
+ diry -= 1
|
|
|
|
+ elif dir == DIR_RIGHT:
|
|
raycast=get_node(rayR)
|
|
raycast=get_node(rayR)
|
|
- else:
|
|
|
|
|
|
+ dirx += 1
|
|
|
|
+ elif dir == DIR_DOWN:
|
|
raycast=get_node(rayD)
|
|
raycast=get_node(rayD)
|
|
|
|
+ diry += 1
|
|
|
|
+ else:
|
|
|
|
+ raycast=get_node(rayL)
|
|
|
|
+ dirx -= 1
|
|
pass
|
|
pass
|
|
|
|
+
|
|
|
|
+func update_avatar_dir():
|
|
|
|
+ $Sprite.rotation_degrees = DEG_LIST[dire]
|