mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-13 22:31:55 +00:00
Built with pure steam coming out of my brain, have to heal brain power after a long break of programming
This commit is contained in:
@@ -15,18 +15,6 @@ local Leveling: {number} = {
|
||||
[10] = 239.245,
|
||||
}
|
||||
|
||||
--Primarily used for the lanterns
|
||||
local LevelingBetween: {number} = {}
|
||||
|
||||
--Calculate between leveling
|
||||
for n: number = 1, #Leveling do
|
||||
local FloorAhead: number? = Leveling[n+1]
|
||||
if FloorAhead then
|
||||
LevelingBetween[n] = (Leveling[n]+FloorAhead)/2
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
Leveling = Leveling,
|
||||
LevelingBetween = LevelingBetween
|
||||
}
|
||||
Leveling = Leveling
|
||||
}
|
||||
|
||||
@@ -81,11 +81,13 @@ type Impl_Static_Props = {
|
||||
LanternDisplayOff: Color3,
|
||||
},
|
||||
Attributes: {
|
||||
CurrentFloor: IntValue,
|
||||
Moving: BoolValue,
|
||||
GoingUp: BoolValue,
|
||||
Stopped: BoolValue,
|
||||
Goal: IntValue
|
||||
PreviousFloor: IntValue,
|
||||
CurrentFloor: IntValue,
|
||||
NextFloor: IntValue,
|
||||
Moving: BoolValue,
|
||||
GoingUp: BoolValue,
|
||||
Stopped: BoolValue,
|
||||
Goal: IntValue
|
||||
},
|
||||
Events: {
|
||||
CabProgression: BindableEvent,
|
||||
@@ -97,9 +99,9 @@ type Impl_Static_Props = {
|
||||
}
|
||||
|
||||
type Constructor_Fun = (
|
||||
TagsConstructor: TagsConstructor,
|
||||
ButtonsTags: Tags.ElevatorButtons,
|
||||
LanternsTags: Tags.Lanterns,
|
||||
TagsConstructor: TagsConstructor,
|
||||
ButtonsTags: Tags.ElevatorButtons,
|
||||
LanternsTags: Tags.Lanterns,
|
||||
LandingDoors: Tags.LandingTags
|
||||
) -> ClassConstructor
|
||||
|
||||
@@ -142,7 +144,7 @@ Elevator.Name = Enums.Elevator.Otis1960
|
||||
Elevator.FloorLevelingDistance = 4
|
||||
Elevator.FloorLeveling3PhaseDistance = 1.5
|
||||
Elevator.ParkedDistance = 0.2
|
||||
Elevator.Responsiveness = 10
|
||||
Elevator.Responsiveness = 20
|
||||
Elevator.MaxVelocity = 7
|
||||
Elevator.LevelingVelocity = 2
|
||||
Elevator.Phase3LevelingVelocity = .5
|
||||
@@ -168,14 +170,17 @@ Elevator.Events = {
|
||||
}
|
||||
|
||||
Elevator.Attributes = {
|
||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
PreviousFloor = Instance.new("IntValue") :: IntValue,
|
||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||
NextFloor = Instance.new("IntValue") :: IntValue,
|
||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
}
|
||||
|
||||
Elevator.Attributes.CurrentFloor.Value = 1
|
||||
Elevator.Attributes.NextFloor.Value = Elevator.Attributes.CurrentFloor.Value+1
|
||||
Elevator.Attributes.Moving.Value = false
|
||||
Elevator.Attributes.GoingUp.Value = false
|
||||
Elevator.Attributes.Goal.Value = 1
|
||||
@@ -189,14 +194,6 @@ local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: nu
|
||||
return CurrentFloor<RequestedFloor
|
||||
end
|
||||
|
||||
local function elevatorwarn<T...>(...: T...)
|
||||
warn("🛗 ["..Elevator.Name.."]:", ...)
|
||||
end
|
||||
|
||||
local function elevatorprint<T...>(...: T...)
|
||||
print("🛗 ["..Elevator.Name.."]:", ...)
|
||||
end
|
||||
|
||||
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
|
||||
@@ -217,20 +214,20 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
self.MachineRoom.PiePlatePulley = TagsConstructor:Request("Otis1960_PieplatePulley") :: UnionOperation
|
||||
self.MachineRoom.PiePlatePlates = TagsConstructor:Request("Otis1960_PiePlatePlates") :: UnionOperation
|
||||
self.MachineRoom.PiePlateSelector = TagsConstructor:Request("Otis1960_PiePlateSelector") :: UnionOperation
|
||||
|
||||
|
||||
local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation
|
||||
|
||||
self.MOConstructor = MovingObjects.constructor({MachineRoom = self.MachineRoom} :: MovingObjects.InstanceTree)
|
||||
|
||||
|
||||
--Start the hall displays
|
||||
self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
|
||||
|
||||
|
||||
--Init the doors
|
||||
self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
|
||||
|
||||
--Init the ropes
|
||||
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, LevelingModule.Leveling)
|
||||
|
||||
|
||||
--Init the lanterns
|
||||
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Elevator.Sounds, Elevator.Colors)
|
||||
|
||||
@@ -240,11 +237,11 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
self.ButtonsConstructor = Buttons.constructor(Elevator.Attributes, Elevator.Colors)
|
||||
|
||||
self.HallDisplaysConstructor:BindHallDisplays()
|
||||
|
||||
|
||||
self.BoxAttachment,
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(
|
||||
self.ElevatorBox_1960,
|
||||
self.ElevatorBox_1960,
|
||||
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[Attributes.Goal.Value] or LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
|
||||
Elevator.Responsiveness,
|
||||
Elevator.MaxVelocity
|
||||
@@ -266,49 +263,50 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
--self.RelayConstructor:BulkConnect()
|
||||
|
||||
local ClassConstructor = setmetatable(self, Elevator)
|
||||
|
||||
elevatorprint("Initialized and ready")
|
||||
|
||||
print(`🛗 [{Elevator.Name}]: Initialized and ready`)
|
||||
return ClassConstructor
|
||||
end
|
||||
|
||||
local function CheckFloorQueue(self: ClassConstructor)
|
||||
if self.RelayAlgorithmConstructor.__FloorQueue[1] ~= Attributes.CurrentFloor.Value then
|
||||
elevatorwarn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
|
||||
warn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
|
||||
end
|
||||
table.remove(self.RelayAlgorithmConstructor.__FloorQueue, 1)
|
||||
|
||||
local NextFloor = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||
if NextFloor then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, NextFloor)
|
||||
local LevelVec3 = LevelingModule.Leveling[NextFloor]
|
||||
local NextFloorInQueue = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||
if NextFloorInQueue then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, NextFloorInQueue)
|
||||
local LevelVec3 = LevelingModule.Leveling[NextFloorInQueue]
|
||||
|
||||
self:__TravelToFloor(NextFloor, LevelVec3, ElevatorGoingUp)
|
||||
self:__TravelToFloor(NextFloorInQueue, LevelVec3, ElevatorGoingUp)
|
||||
end
|
||||
end
|
||||
|
||||
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3: number, ElevatorGoingUp: boolean)
|
||||
local Elevator_Position = self.ElevatorBox_1960.Position
|
||||
local Between_Levels = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value]
|
||||
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean)
|
||||
local ElevatorPosition = self.ElevatorBox_1960.Position
|
||||
local AtFloorY = LevelingModule.Leveling[ElevatorGoingUp and Attributes.CurrentFloor.Value+1 or Attributes.CurrentFloor.Value-1]
|
||||
|
||||
if ElevatorGoingUp then
|
||||
--Detecting between the floors
|
||||
if Elevator_Position.Y>=Between_Levels then
|
||||
local PreviousFloor = Attributes.CurrentFloor.Value
|
||||
if ElevatorPosition.Y>=AtFloorY-Elevator.FloorLevelingDistance then
|
||||
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
|
||||
Attributes.CurrentFloor.Value+=1
|
||||
Attributes.NextFloor.Value = math.clamp(1, Attributes.CurrentFloor.Value+1, #LevelingModule.Leveling)
|
||||
|
||||
Events.CabProgression:Fire(PreviousFloor, Attributes.CurrentFloor.Value)
|
||||
Events.CabProgression:Fire(Attributes.PreviousFloor.Value, Attributes.CurrentFloor.Value, Attributes.NextFloor.Value)
|
||||
end
|
||||
|
||||
--Elevator is riding upwards towards the destination
|
||||
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLevelingDistance then
|
||||
if ElevatorPosition.Y>=LevelVec3-Elevator.FloorLevelingDistance then
|
||||
Events.Leveling:Fire()
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
|
||||
|
||||
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
|
||||
if ElevatorPosition.Y>=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
|
||||
Events.Leveling3Phase:Fire()
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
|
||||
|
||||
if Elevator_Position.Y>=LevelVec3-Elevator.ParkedDistance then
|
||||
if ElevatorPosition.Y>=LevelVec3-Elevator.ParkedDistance then
|
||||
Events.Parked:Fire()
|
||||
CheckFloorQueue(self);
|
||||
|
||||
@@ -317,35 +315,34 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
|
||||
end
|
||||
end
|
||||
else
|
||||
--Detecting between the floors
|
||||
--leaving floor ElevatorPosition Y=62, Between_levels=75
|
||||
if Elevator_Position.Y<=Between_Levels then
|
||||
local PreviousFloor = Attributes.CurrentFloor.Value
|
||||
if ElevatorPosition.Y<=AtFloorY+Elevator.FloorLevelingDistance then
|
||||
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
|
||||
Attributes.CurrentFloor.Value-=1
|
||||
Attributes.NextFloor.Value = math.clamp(1, Attributes.CurrentFloor.Value-1, #LevelingModule.Leveling)
|
||||
|
||||
Events.CabProgression:Fire(PreviousFloor, Attributes.CurrentFloor.Value)
|
||||
Events.CabProgression:Fire(Attributes.PreviousFloor.Value, Attributes.CurrentFloor.Value, Attributes.NextFloor.Value)
|
||||
end
|
||||
|
||||
--Elevator is riding upwards towards the destination
|
||||
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLevelingDistance then
|
||||
if ElevatorPosition.Y<=LevelVec3+Elevator.FloorLevelingDistance then
|
||||
Events.Leveling:Fire()
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
|
||||
|
||||
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
|
||||
if ElevatorPosition.Y<=LevelVec3+Elevator.FloorLeveling3PhaseDistance then
|
||||
Events.Leveling3Phase:Fire()
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
|
||||
|
||||
if Elevator_Position.Y<=LevelVec3-Elevator.ParkedDistance then
|
||||
if ElevatorPosition.Y<=LevelVec3+Elevator.ParkedDistance then
|
||||
Events.Parked:Fire()
|
||||
CheckFloorQueue(self);
|
||||
|
||||
|
||||
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Events.CabTraveling:Fire(Elevator_Position, Attributes.CurrentFloor.Value)
|
||||
Events.CabTraveling:Fire(deltaTime, ElevatorPosition)
|
||||
end
|
||||
|
||||
function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
|
||||
@@ -357,7 +354,7 @@ function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
|
||||
Attributes.GoingUp.Value = ElevatorGoingUp
|
||||
|
||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(deltaTime)
|
||||
CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp)
|
||||
CabTraveling(self, deltaTime, LevelInt, LevelVec3, ElevatorGoingUp)
|
||||
end)
|
||||
|
||||
--Set the elevator's AlignPosition to the floor Y vector
|
||||
@@ -372,7 +369,7 @@ function Elevator:RequestLevel(RequestedLevel)
|
||||
if LevelVec3 then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
|
||||
if #self.RelayAlgorithmConstructor.__FloorQueue == 1 then
|
||||
self:__TravelToFloor(RequestedLevel, LevelVec3, ElevatorGoingUp)
|
||||
end
|
||||
@@ -380,8 +377,8 @@ function Elevator:RequestLevel(RequestedLevel)
|
||||
return true
|
||||
end
|
||||
|
||||
elevatorwarn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
|
||||
warn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
|
||||
return false
|
||||
end
|
||||
|
||||
return Elevator
|
||||
return Elevator
|
||||
|
||||
@@ -55,19 +55,14 @@ local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
|
||||
local Otis1960LandingDoors = LandingDoors[Enums.Elevator.Otis1960]
|
||||
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns, Otis1960LandingDoors)
|
||||
|
||||
task.wait(5)
|
||||
Otis1960:RequestLevel(3)
|
||||
|
||||
Otis1960_Module.Events.Parked.Event:Connect(function()
|
||||
print("Cab parked")
|
||||
task.wait(3)
|
||||
Otis1960:RequestLevel(1)
|
||||
|
||||
end)
|
||||
|
||||
Otis1960_Module.Events.CabProgression.Event:Connect(function(previousFloor: number?, nextFloor: number)
|
||||
--print("previousFloor=",previousFloor, "nextFloor=",nextFloor)
|
||||
Otis1960_Module.Events.CabProgression.Event:Connect(function(previousFloor: number, currentFloor: number, nextFloor: number)
|
||||
print("previousFloor=",previousFloor, "currentFloor=",currentFloor, "nextFloor=",nextFloor)
|
||||
end)
|
||||
|
||||
Otis1960_Module.Events.CabTraveling.Event:Connect(function(Elevator_Position: Vector3, CurrentFloor: number)
|
||||
print("CurrentFloor=",CurrentFloor)
|
||||
end)
|
||||
Otis1960_Module.Events.CabTraveling.Event:Connect(function(deltaTime: number, Elevator_Position: Vector3)
|
||||
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user