godot-psd-training/sceen/totalOfLargePassengerFlow.gd

355 lines
14 KiB
GDScript3
Raw Normal View History

2024-06-17 14:22:23 +08:00
extends TotalScene
2024-06-18 09:03:09 +08:00
class_name LargePassengerFlowScene
2024-06-17 14:22:23 +08:00
## 照相机名字的枚举
enum Camera_name{
2024-06-18 09:03:09 +08:00
#VehicleControlRoom,#车控室
SparePartsCabinet,#备品柜
PartsArea,#备品区
2024-06-17 14:22:23 +08:00
StationHall,#站厅
UpPlatform,#上行站台
2024-06-18 09:03:09 +08:00
DownPlatform,#下行站台
2024-06-17 19:49:24 +08:00
#APassageway,#A出入口
2024-06-18 08:45:49 +08:00
StationHallAExit,#站厅A出口
AEntrance,#A入口
APassage,#A口通道
2024-06-18 09:03:09 +08:00
#BPassageway,#B出入口
2024-06-18 08:45:49 +08:00
StationHallBExit,#站厅B出口
BEntrance,#B入口
BPassage,#B口通道
2024-06-18 09:03:09 +08:00
#CPassageway,#C出入口
2024-06-18 08:45:49 +08:00
StationHallCExit,#站厅C出口
CEntrance,#C入口
2024-06-18 10:22:05 +08:00
CPassage,#C口通道
2024-06-18 09:03:09 +08:00
#DPassageway,#D出入口
2024-06-18 08:45:49 +08:00
StationHallDExit,#站厅D出口
DEntrance,#D入口
2024-06-18 10:22:05 +08:00
DPassage,#D口通道
2024-06-18 09:03:09 +08:00
#StaionHallA,#站厅A端
2024-06-18 08:45:49 +08:00
ALowerStepSwitch,#A端扶梯下部开关
ATVM,#A端TVM
AInboundGate,#A端进站闸机
AExitGate,#A端出站闸机
AUpperStep,#A端扶梯上部
ALowerStep,#A端扶梯下部
AGangway,#A端站厅步梯口
2024-06-18 09:03:09 +08:00
#StationHallB,#站厅B端
2024-06-18 08:45:49 +08:00
BLowerStepSwitch,#B端扶梯下部开关
BTVM,#B端TVM
BInboundGate,#B端进站闸机
BExitGate,#B端出站闸机
BUpperStep,#B端扶梯上部
BLowerStep,#B端扶梯下部
BGangway,#B端站厅步梯口
2024-06-17 14:22:23 +08:00
}
@onready var cameras = $AllCamera.get_children()
2024-06-17 14:22:23 +08:00
2024-07-09 17:27:43 +08:00
var currentActiveCameraOfLarge:Camera_name = Camera_name.StationHall
2024-06-17 14:22:23 +08:00
##切换相机
func switchCamera (camera :Camera_name)-> void:
currentActiveCamera = cameras[camera]
2024-07-09 17:27:43 +08:00
currentActiveCameraOfLarge = camera
2024-06-17 14:22:23 +08:00
cameras[camera].make_current()
## 人运动区域的枚举
enum PlayerWalkArea3D {
2024-07-11 17:49:28 +08:00
entrance,#入口
passage,#通道
stationHallExit,#出口
ticketingArea, #购票区
entranceGateArea, #闸机入口区
gangwayUpArea, #站厅步梯上
gangwayDownArea,#站厅步梯下
screenDoorWaitArea,#屏蔽门等待区域
}
2024-07-11 17:49:28 +08:00
const areaInfo = {
'A':{
'entrance':[Vector3(-60,9.8,43)],
'passage':Vector3(3,5.22,41),
'stationHallExit':Vector3(3,5.22,18.74),
'ticketingArea':[Vector3(-11.27,5.22,18.74)],
'entranceGateArea':[Vector3(-11.27,5.22,17.25),Vector3(36,5.22,17.25),Vector3(36,5.22,14)],
'gangwayUpArea':[Vector3(36,5.22,7.45),Vector3(31,5.22,7.45)],
'gangwayDownArea': [Vector3(14.12,0.85,7.45)]
},
'B':{
'entrance':[ Vector3(-54.8,9.8,-67.3),Vector3(-50,9.8,-64),Vector3(-30.1,9.8,-62.3)],
'passage':Vector3(1.92,5.22,-62.3),
'stationHallExit':Vector3(1.92,5.22,0),
},
'C':{'entrance':[Vector3(144.12,9.8,-60),Vector3(144.12,9.8,-68.7),Vector3(142,9.8,-68.7),Vector3(142,9.8,-60),Vector3(140,9.8,-60),Vector3(140,9.8,-67),Vector3(122.46,9.8,-66.38)],
'passage':Vector3(87.3,5.22,-66.38),
'stationHallExit':Vector3(87.3,5.22,-1.77),
},
'D':{'entrance':[Vector3(144.12,9.8,46),Vector3(144.12,9.8,36.58),Vector3(142,9.8,36.58),Vector3(142,9.8,46),Vector3(140,9.8,46),Vector3(140,9.8,38.28),Vector3(122.46,9.8,39.55)],
'passage':Vector3(93.38,5.22,39.55),
'stationHallExit':Vector3(93.38,5.22,21.04),
'ticketingArea':[Vector3(99,5.22,14.25),Vector3(99,5.22,7.86),Vector3(109.26,5.22,7.86)],
'entranceGateArea':[Vector3(109.26,5.22,6.86),Vector3(92,5.22,6.86),Vector3(92,5.22,12.98),Vector3(78.33,5.22,17.29),Vector3(56,5.22,17.29),Vector3(56,5.22,14)],
'gangwayUpArea':[Vector3(56,5.22,7.45),Vector3(61.46,5.22,7.45)],
'gangwayDownArea': [Vector3(77,0.85,7.45)]
}
}
##区域运动(进站-连续的路径点)
func playerGoToNextArea(peopleWalkFollow:PlayerPathFollow,nextArea: PlayerWalkArea3D) -> void:
2024-07-11 17:49:28 +08:00
var targetAreaInfo = areaInfo[peopleWalkFollow.generateArea]
match nextArea:
2024-07-11 17:49:28 +08:00
PlayerWalkArea3D.entrance:
walkByPathFollow(targetAreaInfo.entrance,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
2024-07-11 17:49:28 +08:00
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.passage)
PlayerWalkArea3D.passage:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.passage,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
2024-07-11 17:49:28 +08:00
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.stationHallExit)
PlayerWalkArea3D.stationHallExit:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.stationHallExit,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(1).timeout
2024-07-11 17:49:28 +08:00
if peopleWalkFollow.generateArea == 'B' || peopleWalkFollow.generateArea == 'C':
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.stationHallExit)
else :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.ticketingArea)
PlayerWalkArea3D.ticketingArea:
walkByPathFollow(targetAreaInfo.ticketingArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(5).timeout
2024-07-11 17:49:28 +08:00
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entranceGateArea)
PlayerWalkArea3D.entranceGateArea:
2024-07-15 10:29:36 +08:00
peopleWalkFollow.waitTimeWalkAgain = 0.5
2024-07-11 17:49:28 +08:00
walkByPathFollow(targetAreaInfo.entranceGateArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
2024-07-09 17:27:43 +08:00
await get_tree().create_timer(0.2).timeout
2024-07-11 17:49:28 +08:00
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.gangwayUpArea)
PlayerWalkArea3D.gangwayUpArea:
walkByPathFollow(targetAreaInfo.gangwayUpArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
2024-07-11 17:49:28 +08:00
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.gangwayDownArea)
PlayerWalkArea3D.gangwayDownArea:
walkByPathFollow(targetAreaInfo.gangwayDownArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
2024-07-15 10:29:36 +08:00
#playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.screenDoorWaitArea)
PlayerWalkArea3D.screenDoorWaitArea:
goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,0)
2024-07-11 17:49:28 +08:00
const areaBackInfo = {
'B':{
'stationHallExit':[Vector3(1.92,5.22,3.5),Vector3(5.3,5.22,3.5)],
'passage':Vector3(5.3,5.22,-66.15),
'entrance':Vector3(-13,5.22,-66.15),
},
'C':{
'stationHallExit':[Vector3(82,5.22,6.75),Vector3(90,5.22,6.75)],
'passage':Vector3(90,5.22,-63.43),
'entrance':Vector3(106.6,5.22,-63.43),
},
}
##区域运动(出站)
func playerBackGoToNextArea(peopleWalkFollow:PlayerPathFollow,nextArea: PlayerWalkArea3D) -> void:
var targetAreaInfo = areaBackInfo[peopleWalkFollow.generateArea]
match nextArea:
PlayerWalkArea3D.stationHallExit:
walkByPathFollow(targetAreaInfo.stationHallExit,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.passage)
PlayerWalkArea3D.passage:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.passage,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entrance)
PlayerWalkArea3D.entrance:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.entrance,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entrance)
##演示排队的区域
var screenDoorAreaInfo = [
{
"areaName": "ScreenDoorWaitArea1",
"screenDoorName": 'screenDoor1',
},
{
"areaName": "ScreenDoorWaitArea2",
"screenDoorName": 'screenDoor2',
},
{
"areaName": "ScreenDoorWaitArea3",
"screenDoorName": 'screenDoor3',
},
{
"areaName": "ScreenDoorWaitArea4",
"screenDoorName": 'screenDoor4',
},
]
##进入指定屏蔽门区域并等待上车
func goToScreenDoorAreaAndWaitTrain(peopleWalkFollow:PlayerPathFollow, screenDoorAreaInfoIndex:int) -> void:
var screenDoorPos = $platform.get_node(screenDoorAreaInfo[screenDoorAreaInfoIndex].screenDoorName).get_node('dimiantishi').get_global_position()
2024-07-15 10:29:36 +08:00
screenDoorPos.z += 1.2
var addPoint = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z+3.2)
walkByPathFollow([addPoint,screenDoorPos],peopleWalkFollow)
await self.screenDoorOpenConfirmSignal
2024-07-15 10:29:36 +08:00
var trainPoint1 = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z-3.5)
var trainPoint2 = Vector3(screenDoorPos.x+3,screenDoorPos.y,screenDoorPos.z-3.5)
walkByPathFollow([trainPoint1,trainPoint2],peopleWalkFollow)
await self.screenDoorCloseConfirmSignal
peopleWalkFollow.queue_free()
const ArrayUtils = preload("res://util/ArrayUtils.gd")
func _on_screen_door_wait_area_screen_door_area_enter(curentArea: Area3D, peopleWalkFollow: PlayerPathFollow) -> void:
2024-07-15 10:29:36 +08:00
var waitPeopleCounts = [$AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea2.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea3.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea4.waitPeopleCount]
for index in range(screenDoorAreaInfo.size()):
if screenDoorAreaInfo[index].areaName == curentArea.name and curentArea.waitPeopleCount-1 <= ArrayUtils.removeElementByIndex(waitPeopleCounts,index).min() :
peopleWalkFollow.peopleStopWalk()
goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,index)
2024-07-15 10:29:36 +08:00
var trainLeaveAtDownPlatform = true
func _on_screen_door_wait_area_1_area_entered(area: Area3D) -> void:
2024-07-15 10:29:36 +08:00
if $AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount>=4 and trainLeaveAtDownPlatform:
trainComeAndLeace()
##通过PathFollow运动
func walkByPathFollow(allTargetPos:Array,peopleWalkFollow:PlayerPathFollow,curveAngle=Vector3()) -> void:
var walkPoints = [peopleWalkFollow.player.position]
for child in allTargetPos:
var xOffset = child.x - peopleWalkFollow.buildPos.x
var yOffset = child.y - peopleWalkFollow.buildPos.y
var zOffset = child.z - peopleWalkFollow.buildPos.z
walkPoints.append(Vector3(xOffset,yOffset,zOffset))
peopleWalkFollow.setPathPoints(walkPoints,curveAngle)
peopleWalkFollow.peopleBeginWalk()
2024-07-09 17:27:43 +08:00
##开始生成人的运动
2024-07-09 17:27:43 +08:00
var people_scene = preload("res://sceen/people/peoplewalkfollow.tscn")
func startGeneratePeople() -> void:
$AllTimer/generatePeopleAEntranceTimer.start()
##A入口生成
var totalOfAEntrance=0
2024-07-09 17:27:43 +08:00
func generatePeopleAtAEntrance() -> void:
2024-07-15 10:29:36 +08:00
if $AllAreaDetection/APassageAreaDetection.passPeopleCount< 0 and currentActiveCameraOfLarge != Camera_name.APassage:
generatePeopleAPassage()
if $AllAreaDetection/TicketingLfetAreaDetection.passPeopleCount< 0 and currentActiveCameraOfLarge != Camera_name.BTVM:
generatePeopleAtBTVM()
totalOfAEntrance += 1
if totalOfAEntrance > 15:
$AllTimer/generatePeopleAEntranceTimer.wait_time = 10
var peoplePosition = Vector3(-80,9.8,40.5)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'A',totalOfAEntrance)
##A通道生成
var totalOfAPassage=0
func generatePeopleAPassage() -> void:
totalOfAPassage += 1
2024-07-09 17:27:43 +08:00
var peoplePosition = Vector3(3,5.22,41)
2024-07-11 17:49:28 +08:00
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.stationHallExit,'A')
2024-07-09 17:27:43 +08:00
2024-07-15 10:29:36 +08:00
##A闸机生成
var totalOfBTVM=0
func generatePeopleAtBTVM() -> void:
totalOfBTVM += 1
var peoplePosition = Vector3(-11.27,5.22,18.74)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entranceGateArea,'A')
2024-07-09 17:27:43 +08:00
##售票厅循环排队
2024-07-15 10:29:36 +08:00
var totalOfBTicketingArea = 8
2024-07-09 17:27:43 +08:00
func generatePeopleAtBTicketingArea() -> void:
2024-07-15 10:29:36 +08:00
if $AllAreaDetection/TicketingAreaDetection.waitPeopleCount < totalOfBTicketingArea:
2024-07-09 17:27:43 +08:00
var peoplrInstance = people_scene.instantiate()
add_child(peoplrInstance)
peoplrInstance.global_position = Vector3(1,5.22,15.84)
peoplrInstance.buildPos = Vector3(1,5.22,15.84)
walkByPathFollow([Vector3(-11.27,5.22,15.84)],peoplrInstance)
await peoplrInstance.player.ArriveTargetPos
await get_tree().create_timer(5).timeout
walkByPathFollow([Vector3(-11.27,5.22,14.4),Vector3(2,5.22,14.4)],peoplrInstance)
await peoplrInstance.player.ArriveTargetPos
peoplrInstance.queue_free()
2024-07-15 10:29:36 +08:00
##下行站台生成
func letPeopleWaitTrainAtDownPlatform() -> void:
$AllTimer/generatePeopleDownPlatformTimer.start()
var totalOfDownPlatform = 16
func generatePeopleAtDownPlatform() -> void:
if totalOfDownPlatform > 0:
totalOfDownPlatform -= 1
var peoplePosition = Vector3(13.54,0.85,11.2)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.screenDoorWaitArea,'A')
else :
$AllTimer/generatePeopleDownPlatformTimer.stop()
2024-07-11 17:49:28 +08:00
##B入口生成(从进到出3分钟间隔10秒18个人完成循环)
var totalOfBEntrance=18
func generatePeopleAtBEntrance() -> void:
if totalOfBEntrance> 0:
totalOfBEntrance -= 1
var peoplePosition = Vector3(-54.8,9.8,-61)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'B',totalOfAEntrance)
else :
$AllTimer/generatePeopleBEntranceTimer.stop()
##C入口生成
var totalOfCEntrance=21
func generatePeopleAtCEntrance() -> void:
if totalOfCEntrance> 0:
totalOfCEntrance -= 1
var peoplePosition = Vector3(146.12,9.8,-60)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'C',totalOfAEntrance)
else :
$AllTimer/generatePeopleCEntranceTimer.stop()
##D入口生成
var totalOfDEntrance=15
func generatePeopleAtDEntrance() -> void:
if totalOfDEntrance > 0:
totalOfDEntrance -= 1
var peoplePosition = Vector3(146.12,9.8,46)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'D',totalOfAEntrance)
else :
$AllTimer/generatePeopleDEntranceTimer.stop()
2024-07-09 17:27:43 +08:00
##在指定区域增加人
2024-07-11 17:49:28 +08:00
func generatePeopleAtDesignatedArea(peoplePosition:Vector3, goToNextArea: PlayerWalkArea3D,generateArea:String, peopleId:int=0) -> void:
2024-07-09 17:27:43 +08:00
var peoplrInstance = people_scene.instantiate()
add_child(peoplrInstance)
peoplrInstance.global_position = peoplePosition
peoplrInstance.buildPos = peoplePosition
2024-07-11 17:49:28 +08:00
peoplrInstance.generateArea = generateArea
2024-07-09 17:27:43 +08:00
if peopleId :
peoplrInstance.id = peopleId
playerGoToNextArea(peoplrInstance,goToNextArea)
2024-07-11 17:49:28 +08:00
signal trainComingSignal()
func trainComeAndLeace() -> void:
2024-07-15 10:29:36 +08:00
trainLeaveAtDownPlatform = false
2024-07-11 17:49:28 +08:00
trainComingSignal.emit()
self.trainComeAndOpenScreenDoor()
await get_tree().create_timer(25).timeout
self.closeScreenDoorAndTrainLeave()
2024-07-15 10:29:36 +08:00
trainLeaveAtDownPlatform = true
2024-07-09 17:27:43 +08:00
func temporaryTicketOfficeComing() -> void:
$platform.get_node('TemporaryTicketOffice').temporaryTicketOfficeComing()
2024-07-11 17:49:28 +08:00
func allTimerStopAndShowRedStripe() -> void:
$platform.get_node('ShortcutToolModel2').allTimerStopAndShowRedStripe()
func _ready():
$platform.showCameraAndShortcutTool()
2024-07-15 10:29:36 +08:00
$platform.screenDoorOpenAndCloseNoMusic()