88 lines
2.1 KiB
GDScript
88 lines
2.1 KiB
GDScript
extends Area2D
|
|
|
|
@onready var floorRaycast = $RaycastFloor
|
|
@onready var raycastLeft = $RaycastLeft
|
|
@onready var raycastRight = $RaycastRight
|
|
|
|
@export var UID = 1
|
|
|
|
var secretPosition = Vector2()
|
|
|
|
var turningPoint = false
|
|
|
|
var type = GLOBAL.BLOCKTYPES.LIGHT
|
|
|
|
func _ready() -> void:
|
|
secretPosition = position
|
|
|
|
#func _physics_process(delta: float) -> void:
|
|
#print(secretPosition)
|
|
#print(getNeighbours())
|
|
#print(getNeighboursUID(UID))
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _physics_process(delta: float) -> void:
|
|
#if not getIsOnFloor():
|
|
# position = secretPosition.snapped(Vector2(64,64))
|
|
#if Input.is_action_just_pressed("left"):
|
|
# if not raycastLeft.is_colliding():
|
|
# secretPosition.x -= GLOBAL.GRID
|
|
#if Input.is_action_just_pressed("right"):
|
|
# if not raycastRight.is_colliding():
|
|
# secretPosition.x += GLOBAL.GRID
|
|
#secretPosition.y += GLOBAL.currentSpeed * delta * 30
|
|
|
|
func getIsOnFloor() -> bool:
|
|
return floorRaycast.is_colliding()
|
|
|
|
#func getFloorCollider():
|
|
#return floorRaycast.get_collider()
|
|
#
|
|
#func getLeftCollider():
|
|
#return raycastLeft.get_collider()
|
|
#
|
|
#func getRightCollider():
|
|
#return raycastRight.get_collider()
|
|
|
|
func getLeftColliding() -> bool:
|
|
return raycastLeft.is_colliding()
|
|
|
|
func getRightColliding() -> bool:
|
|
return raycastRight.is_colliding()
|
|
|
|
func getCollider(direction : GLOBAL.Direction):
|
|
match direction:
|
|
GLOBAL.Direction.BOTTOM:
|
|
return floorRaycast.get_collider()
|
|
GLOBAL.Direction.LEFT:
|
|
return raycastLeft.get_collider()
|
|
GLOBAL.Direction.RIGHT:
|
|
return raycastRight.get_collider()
|
|
|
|
|
|
func getNeighbours():
|
|
var neighbours = []
|
|
for i in get_overlapping_areas():
|
|
if i.is_in_group("Block"):
|
|
neighbours.append(i)
|
|
return neighbours
|
|
|
|
func getNeighboursUID(uid):
|
|
var neighbours = []
|
|
for i in get_overlapping_areas():
|
|
if i.is_in_group("Block"):
|
|
if i.UID == uid:
|
|
neighbours.append(i)
|
|
return neighbours
|
|
|
|
func move(x,y):
|
|
secretPosition = position
|
|
secretPosition.x += x
|
|
secretPosition.y += y
|
|
position = secretPosition.snapped(Vector2(64, 64))
|
|
|
|
func moveDown():
|
|
move(0, 64)
|
|
func moveLeft():
|
|
move(-64, 0)
|
|
func moveRight():
|
|
move(64, 0)
|