mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:41:53 +00:00
Working lanterns as floors pass by, need to work on going down, start working on hall displays
This commit is contained in:
@@ -49,8 +49,11 @@ type Impl_Static_Props = {
|
||||
FloorLevelingDistance: number,
|
||||
DoorOpeningDistance: number,
|
||||
LeveledDistance: number,
|
||||
__Moving: boolean,
|
||||
__CurrentFloor: number
|
||||
Attributes: {
|
||||
PassingFloor: IntValue,
|
||||
Moving: BoolValue,
|
||||
CurrentFloor: IntValue
|
||||
},
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ElevatorButtons, LanternsTags: Tags.Lanterns, LandingDoors: Tags.LandingTags) -> ClassConstructor
|
||||
@@ -96,9 +99,18 @@ Otis1960.LanternDisplayColorOn = Color3.fromRGB(255,114,71)
|
||||
Otis1960.LanternDisplayColorOff = Color3.fromRGB(55,55,55)
|
||||
Otis1960.LanternChimeDirection = "rbxassetid://16990287228"
|
||||
Otis1960.LanternChimeLanding = "rbxassetid://16990290265"
|
||||
--*read-only*
|
||||
Otis1960.__Moving = false
|
||||
Otis1960.__CurrentFloor = 1
|
||||
|
||||
Otis1960.Attributes = {
|
||||
PassingFloor = Instance.new("IntValue") :: IntValue,
|
||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||
CurrentFloor = Instance.new("IntValue") :: IntValue
|
||||
}
|
||||
|
||||
Otis1960.Attributes.PassingFloor.Value = 1
|
||||
Otis1960.Attributes.Moving.Value = false
|
||||
Otis1960.Attributes.CurrentFloor.Value = 1
|
||||
|
||||
local Attributes = Otis1960.Attributes
|
||||
|
||||
local ButtonFunctions: ButtonFunctions = {
|
||||
[Enums.ButtonTree.Landing] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
|
||||
@@ -116,12 +128,12 @@ local ButtonFunctions: ButtonFunctions = {
|
||||
task.spawn(function()
|
||||
ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonActivatedColor)
|
||||
|
||||
if DecodedFloor == Otis1960.__CurrentFloor then
|
||||
if DecodedFloor == Attributes.CurrentFloor.Value then
|
||||
ButtonsConstructor:DeactivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonDeactivatedColor)
|
||||
end
|
||||
end)
|
||||
|
||||
if DecodedFloor ~= Otis1960.__CurrentFloor then
|
||||
if DecodedFloor ~= Attributes.CurrentFloor.Value then
|
||||
self:GoToLevel(DecodedFloor)
|
||||
end
|
||||
end
|
||||
@@ -214,51 +226,74 @@ end
|
||||
local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
|
||||
(self.__MovingConnection :: RBXScriptConnection):Disconnect()
|
||||
|
||||
Otis1960.__Moving = false
|
||||
Otis1960.__CurrentFloor = RequestedLevel
|
||||
Attributes.Moving.Value = false
|
||||
Attributes.CurrentFloor.Value = RequestedLevel
|
||||
self.BoxAlignPosition.MaxVelocity = Otis1960.MaxVelocity
|
||||
|
||||
self.LanternsConstructor:Reset(Otis1960.__CurrentFloor)
|
||||
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
||||
end
|
||||
|
||||
local FloorPassingLookAhead = Attributes.CurrentFloor.Value+1
|
||||
|
||||
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
||||
if ElevatorPositionY>=Leveling[FloorPassingLookAhead] then
|
||||
FloorPassingLookAhead+=1
|
||||
Attributes.CurrentFloor.Value+=1
|
||||
|
||||
if Attributes.CurrentFloor.Value ~= RequestedLevel then
|
||||
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
||||
self.LanternsConstructor:Toggle(false, Attributes.CurrentFloor.Value-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
||||
--Attributes.CurrentFloor.Value -= 1
|
||||
|
||||
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
self.ElevatorDoors:ToggleElevatorDoors(false, Otis1960.__CurrentFloor)
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
self.ElevatorDoors:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
||||
|
||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||
self.__MovingConnection:Disconnect()
|
||||
end
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
if GoingUp then
|
||||
self.LanternsConstructor:DirectionUp(true)
|
||||
else
|
||||
self.LanternsConstructor:DirectionDown(true)
|
||||
end
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
|
||||
FloorPassingLookAhead = Attributes.CurrentFloor.Value
|
||||
|
||||
--Otis1960_ShaftGovernor
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt) --Not safe for parallel
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
|
||||
Delta+=1
|
||||
Otis1960.__Moving = true
|
||||
Attributes.Moving.Value = true
|
||||
|
||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||
local ElevatorPositionY: number = ElevatorPosition.Y
|
||||
local BoxAlignY: number = self.BoxAlignPosition.Position.Y
|
||||
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
|
||||
self.TractionRopes:Move(27, self.ElevatorBox_1960.Position)
|
||||
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
||||
self.TractionRopes:Move(27, ElevatorPosition)
|
||||
|
||||
--Kill the connection
|
||||
if GoingUp then
|
||||
FloorPassingUp(self, ElevatorPositionY, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.FloorLevelingDistance then
|
||||
FloorLeveling(self, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance and not DoorsOpeningEvent then
|
||||
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
|
||||
DoorsOpeningEvent = true
|
||||
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
|
||||
end
|
||||
@@ -268,10 +303,12 @@ function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
FloorLeveled(self, RequestedLevel)
|
||||
end
|
||||
else
|
||||
FloorPassingDown(self, ElevatorPositionY, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY<=BoxAlignY+Otis1960.FloorLevelingDistance then
|
||||
FloorLeveling(self, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance and not DoorsOpeningEvent then
|
||||
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
|
||||
DoorsOpeningEvent = true
|
||||
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
|
||||
end
|
||||
@@ -289,12 +326,12 @@ end
|
||||
function Otis1960:GoToLevel(RequestedLevel)
|
||||
local GoalLevelVEC: number = Leveling[RequestedLevel]
|
||||
|
||||
if GoalLevelVEC and GoalLevelVEC ~= 0 and GoalLevelVEC ~= Otis1960.__CurrentFloor then
|
||||
local GoingUp: boolean = -(Otis1960.__CurrentFloor-RequestedLevel)>0 --My clever math function for determining if the elevator goal is to move upwards or not
|
||||
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
|
||||
local GoingUp: boolean = -(Attributes.CurrentFloor.Value-RequestedLevel)>0 --My clever math function for determining if the elevator goal is to move upwards or not
|
||||
|
||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
else
|
||||
warn(`[{Enums.Elevator.Otis1960}]: landing out of range or equals the same range as goal! requested landing: {tostring(RequestedLevel)}`)
|
||||
warn(`[{Enums.Elevator.Otis1960}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user