76 lines
1.6 KiB
GDScript
76 lines
1.6 KiB
GDScript
extends Area2D
|
|
|
|
@onready var floorRaycast = $RaycastFloor
|
|
@onready var raycastLeft = $RaycastLeft
|
|
@onready var raycastRight = $RaycastRight
|
|
@onready var raycastTop = $RaycastTop
|
|
|
|
@onready var spriteBlock = $Block
|
|
@onready var spriteSpecialBlock = $SpecialBlock
|
|
@onready var spriteExpandBlock = $ExpandBlock
|
|
@onready var spriteSpecialExpandedBlock = $SpecialExpandedBlock
|
|
|
|
@export var UID = 1
|
|
|
|
var secretPosition = Vector2()
|
|
|
|
var turningPoint = false
|
|
|
|
var type = GLOBAL.BLOCKTYPES.LIGHT
|
|
|
|
var expand = false
|
|
|
|
func _ready() -> void:
|
|
secretPosition = position
|
|
|
|
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()
|
|
GLOBAL.Direction.TOP:
|
|
return raycastTop.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)
|
|
|
|
func setlook():
|
|
match type:
|
|
GLOBAL.BLOCKTYPES.LIGHT:
|
|
if expand:
|
|
spriteExpandBlock.show()
|
|
else:
|
|
spriteBlock.show()
|
|
GLOBAL.BLOCKTYPES.HEAVY:
|
|
if expand:
|
|
spriteSpecialExpandedBlock.show()
|
|
else:
|
|
spriteSpecialBlock.show()
|