84 lines
2.1 KiB
GDScript
84 lines
2.1 KiB
GDScript
extends Node3D
|
|
|
|
##车
|
|
class_name Train
|
|
@onready var train_animation_player: AnimationPlayer = $"../trainAnimationPlayer"
|
|
|
|
## 车的类型枚举
|
|
enum TrainType{
|
|
four = 2,# 4编组
|
|
six = 4,#6编组
|
|
}
|
|
|
|
@export var trainType:TrainType = TrainType.four
|
|
|
|
## 车的状态枚举
|
|
enum Train_STATE{
|
|
come,# 进站
|
|
comeAndStop,# 进站且停稳
|
|
leave,# 出站
|
|
}
|
|
|
|
##车的状态
|
|
@onready var trainState : Train_STATE = Train_STATE.leave :
|
|
set(value):
|
|
if trainState != value:
|
|
trainState = value
|
|
if trainState == Train_STATE.come :
|
|
train_animation_player.play("trainCome")
|
|
elif trainState == Train_STATE.leave :
|
|
train_animation_player.play("trainLeave")
|
|
|
|
|
|
##进站停车
|
|
func trainCome ()-> void:
|
|
trainState=Train_STATE.come
|
|
|
|
|
|
##出站
|
|
func trainLeave ()-> void:
|
|
trainState=Train_STATE.leave
|
|
|
|
|
|
func _on_train_animation_player_animation_finished(anim_name: StringName) -> void:
|
|
if anim_name == 'trainCome' :
|
|
trainState = Train_STATE.comeAndStop
|
|
|
|
|
|
var leftTrainDoorALL = []
|
|
|
|
##开左侧车门
|
|
func openLeftTrainDoorALL ()-> void:
|
|
for child in leftTrainDoorALL:
|
|
child.openTrainDoor()
|
|
|
|
##关左侧车门
|
|
func closeLeftTrainDoorALL ()-> void:
|
|
for child in leftTrainDoorALL:
|
|
child.closeTrainDoor()
|
|
|
|
func _ready() -> void:
|
|
var trainDoor_scene = preload("res://sceen/train/trainDoor.tscn")
|
|
var lasttrainDoorPosX = -4.385
|
|
for i in range(1, (trainType+2)*4+1):
|
|
##左侧有动画的车门
|
|
var trainDoorInstance = trainDoor_scene.instantiate()
|
|
add_child(trainDoorInstance)
|
|
leftTrainDoorALL.append(trainDoorInstance)
|
|
if i % 4 ==1 and i != 1:
|
|
trainDoorInstance.position.x=lasttrainDoorPosX+6.104
|
|
else:
|
|
trainDoorInstance.position.x=lasttrainDoorPosX+4.385
|
|
##右侧无动画的车门
|
|
if i>1:
|
|
var copyNoMoveDoor = $NoMoveDoor.duplicate()
|
|
add_child(copyNoMoveDoor)
|
|
copyNoMoveDoor.position.x = lasttrainDoorPosX
|
|
lasttrainDoorPosX = trainDoorInstance.position.x
|
|
trainDoorInstance.name = 'trainDoor{0}'.format([i])
|
|
for i in range(1, trainType):
|
|
var copyTrainBody = $TrainBody.duplicate()
|
|
$".".add_child(copyTrainBody)
|
|
copyTrainBody.position.x=19.259*(i+1)
|
|
$TrainHeadH.position.x += 19.259*(trainType-1)
|