2024-04-12 11:06:25 +08:00
|
|
|
extends Node3D
|
|
|
|
|
2024-04-29 15:00:41 +08:00
|
|
|
##车
|
|
|
|
class_name Train
|
2024-04-12 11:06:25 +08:00
|
|
|
@onready var train_animation_player: AnimationPlayer = $"../trainAnimationPlayer"
|
|
|
|
|
2024-04-29 15:00:41 +08:00
|
|
|
## 车的类型枚举
|
2024-04-25 17:00:46 +08:00
|
|
|
enum TrainType{
|
2024-04-29 15:00:41 +08:00
|
|
|
four = 2,# 4编组
|
|
|
|
six = 4,#6编组
|
2024-04-25 17:00:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@export var trainType:TrainType = TrainType.four
|
|
|
|
|
2024-04-29 15:00:41 +08:00
|
|
|
## 车的状态枚举
|
|
|
|
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()
|
|
|
|
|
2024-04-25 17:00:46 +08:00
|
|
|
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):
|
2024-04-29 15:00:41 +08:00
|
|
|
##左侧有动画的车门
|
2024-04-25 17:00:46 +08:00
|
|
|
var trainDoorInstance = trainDoor_scene.instantiate()
|
|
|
|
add_child(trainDoorInstance)
|
2024-04-29 15:00:41 +08:00
|
|
|
leftTrainDoorALL.append(trainDoorInstance)
|
2024-04-25 17:00:46 +08:00
|
|
|
if i % 4 ==1 and i != 1:
|
|
|
|
trainDoorInstance.position.x=lasttrainDoorPosX+6.104
|
|
|
|
else:
|
|
|
|
trainDoorInstance.position.x=lasttrainDoorPosX+4.385
|
2024-04-29 15:00:41 +08:00
|
|
|
##右侧无动画的车门
|
2024-04-25 17:00:46 +08:00
|
|
|
if i>1:
|
|
|
|
var copyNoMoveDoor = $NoMoveDoor.duplicate()
|
2024-04-29 15:00:41 +08:00
|
|
|
add_child(copyNoMoveDoor)
|
2024-04-25 17:00:46 +08:00
|
|
|
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)
|
2024-04-12 11:06:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
var count=0
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
count+=1
|
|
|
|
if count<180:
|
2024-04-29 15:00:41 +08:00
|
|
|
if trainState == Train_STATE.leave :
|
|
|
|
trainCome()
|
|
|
|
elif count>180 and count<360:
|
|
|
|
if leftTrainDoorALL[0].trainDoorState != 0 :
|
|
|
|
openLeftTrainDoorALL()
|
|
|
|
elif count>540 and count<720 :
|
|
|
|
if leftTrainDoorALL[0].trainDoorState != 1 :
|
|
|
|
closeLeftTrainDoorALL()
|
2024-04-12 11:06:25 +08:00
|
|
|
elif count>1000 and count<2000:
|
2024-04-29 15:00:41 +08:00
|
|
|
if trainState == Train_STATE.comeAndStop :
|
|
|
|
trainLeave()
|
2024-04-12 11:06:25 +08:00
|
|
|
elif count>2000:
|
|
|
|
count=0
|