You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Gridmap/scripts/Chunks.gd

76 lines
3.4 KiB

extends GridMap
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 = entity.id
entity_instance.position = map_to_local(Vector3(entity.position.x, entity.position.y, entity.position.z))
entity_instance.connect_to_world(entity_instance.id)
add_child(entity_instance)