valencia-rail-rush/chunk.gd

88 lines
3.3 KiB
GDScript

extends Node3D
var exits: Array = [false, false, false, false]
const ASPHALT_WIDTH: float = 20
@onready var exit_area = $BuildingAreas/B_area_E/Collision
@onready var building_area = $BuildingAreas/B_area/Collision
var building_scn = preload("res://building.tscn")
func _ready() -> void:
$Mesh.mesh.size.x = Global.chunk_size
$Mesh.mesh.size.y = Global.chunk_size
var building_side = (Global.chunk_size - Global.street_width) / 2
var building_center = (building_side + Global.street_width) / 2
building_area.shape.size.z = building_side
building_area.shape.size.x = building_side
building_area.position.x = building_center
building_area.position.z = building_center
exit_area.shape.size.z = Global.street_width
exit_area.shape.size.x = building_side
var pavement_side = (Global.chunk_size - ASPHALT_WIDTH) / 2
var pavement_center = (pavement_side + ASPHALT_WIDTH) / 2
$BuildingAreas/B_area/Pavement.mesh.size.x = pavement_side
$BuildingAreas/B_area/Pavement.mesh.size.z = pavement_side
$BuildingAreas/B_area/Pavement.position.x = pavement_center
$BuildingAreas/B_area/Pavement.position.z = pavement_center
$BuildingAreas/B_area_E/Pavement.mesh.size.z = Global.chunk_size
$BuildingAreas/B_area_E/Pavement.mesh.size.x = pavement_side
var z_correction_factor = Global.street_width / 40
var x_correction_factor = building_side / 55
for st_body in $BuildingAreas.get_children():
st_body.get_node("Collision").position.x = building_center
if st_body.name != "B_area":
st_body.get_node("Building").scale.z = 0.8 * z_correction_factor
st_body.get_node("Building").scale.x = 1.1 * x_correction_factor
st_body.get_node("Building").position.x = building_center
st_body.get_node("Pavement").position.x = pavement_center
else:
st_body.get_node("Building").scale.z = 1.1 * x_correction_factor
st_body.get_node("Building").scale.x = 1.1 * x_correction_factor
st_body.get_node("Building").position.x = building_center
st_body.get_node("Building").position.z = building_center
for degree in range(1, 4):
var new_area = $BuildingAreas/B_area.duplicate()
new_area.rotation.y = deg_to_rad(90) * degree
$BuildingAreas.add_child(new_area)
func update() -> void:
$BuildingAreas/B_area_N/Building.visible = true
$BuildingAreas/B_area_S/Building.visible = true
$BuildingAreas/B_area_E/Building.visible = true
$BuildingAreas/B_area_W/Building.visible = true
$BuildingAreas/B_area_N/Pavement.visible = true
$BuildingAreas/B_area_S/Pavement.visible = true
$BuildingAreas/B_area_E/Pavement.visible = true
$BuildingAreas/B_area_W/Pavement.visible = true
var i = 0
for exit in exits:
if not exit:
i += 1
continue
if i == 0: #n
$BuildingAreas/B_area_N/Collision.disabled = true
$BuildingAreas/B_area_N/Building.visible = false
$BuildingAreas/B_area_N/Pavement.visible = false
if i == 1: #s
$BuildingAreas/B_area_S/Collision.disabled = true
$BuildingAreas/B_area_S/Building.visible = false
$BuildingAreas/B_area_S/Pavement.visible = false
if i == 2: #w
$BuildingAreas/B_area_W/Collision.disabled = true
$BuildingAreas/B_area_W/Building.visible = false
$BuildingAreas/B_area_W/Pavement.visible = false
if i == 3: #e
$BuildingAreas/B_area_E/Collision.disabled = true
$BuildingAreas/B_area_E/Building.visible = false
$BuildingAreas/B_area_E/Pavement.visible = false
i += 1