extends GridMap @onready var entities = [] const Entity3D = preload("res://scenes/Instance.tscn") func _ready(): setFloor() setEntities() func setFloor(): clear() for mz in range(0, Global.world.width - 1): for mx in range(0, Global.world.height - 1): var bloc = Global.world.get_bloc(Vector2i(mx, mz)) var my: float = bloc.position.y var meshID var mesh_rotation if bloc.type != 0: var neighbours = Global.world.get_neighbours_4_at_same_height(Vector2i(mx, mz)) if neighbours == Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.TOP: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM: meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_0 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == 0: meshID = Global.bloc_sides_id.SIDE_4 mesh_rotation = Global.GRID_ROTATION[0] set_cell_item( Vector3(mx, my, mz) , meshID, mesh_rotation) func setEntities(): for entity in Global.world.entities: var entity_instance = Entity3D.instantiate() entity_instance.id = entities.size() entity_instance.position = map_to_local(Vector3(entity.position.x, entity.position.y, entity.position.z)) entity_instance.connect_to_world(entity_instance.id) entities.append(entity_instance) add_child(entity_instance)