34 lines
1,016 B
GDScript
34 lines
1,016 B
GDScript
extends Node2D
|
|
|
|
class_name Connector
|
|
|
|
enum types {power}
|
|
|
|
@export var type : types
|
|
|
|
@onready var inventory : Inventory = get_tree().get_first_node_in_group("inventory")
|
|
|
|
var color_dictionary = {types.power : Color(0,0,1)}
|
|
|
|
func get_connected() -> Item:
|
|
var inventory_position = inventory.global_to_inventory(global_position)
|
|
var direction
|
|
if global_rotation_degrees < 0: global_rotation_degrees += 360
|
|
if 315 <= global_rotation_degrees or global_rotation_degrees < 45:
|
|
direction = Vector2i(1,0)
|
|
elif 45 <= global_rotation_degrees and global_rotation_degrees < 135:
|
|
direction = Vector2i(0,1)
|
|
elif 135 <= global_rotation_degrees and global_rotation_degrees < 225:
|
|
direction = Vector2i(-1,0)
|
|
elif 225 <= global_rotation_degrees and global_rotation_degrees < 315:
|
|
direction = Vector2i(0,-1)
|
|
var item = inventory.inventory[inventory_position.y+direction.y][inventory_position.x+direction.x]
|
|
|
|
if item is Item:
|
|
return item
|
|
else:
|
|
return null
|
|
|
|
func _ready():
|
|
%Sprite.modulate = color_dictionary[type]
|