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.
91 lines
3.9 KiB
91 lines
3.9 KiB
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(Vector2(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(Vector2(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)
|
|
|
|
# TEST À ENLEVER
|
|
var inputs = {"ui_right": Vector2.RIGHT,
|
|
"ui_left": Vector2.LEFT,
|
|
"ui_up": Vector2.UP,
|
|
"ui_down": Vector2.DOWN}
|
|
|
|
func _unhandled_input(event):
|
|
for dir in inputs.keys():
|
|
if event.is_action_pressed(dir):
|
|
var new_position = Global.world.entities[23].position2D + inputs[dir]
|
|
Global.world.entities[23].move(new_position)
|
|
|