mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
work on lanterns, doors now properly open
This commit is contained in:
@@ -23,7 +23,9 @@ type Impl_Constructor = {
|
||||
--Class functions
|
||||
DecodeCarTag: (self: ClassConstructor, FloorTag: string) -> number?,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> Tags.ButtonsTree,
|
||||
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, ActivatedState: boolean, ActivatedColor: Color3) -> thread
|
||||
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, ActivatedColor: Color3) -> (),
|
||||
DeactivateButton: (self: ClassConstructor, Button: BasePart, DeactivatedColor: Color3) -> (),
|
||||
ActivateButton: (self: ClassConstructor, Button: BasePart, ActivatedColor: Color3) -> (),
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
@@ -143,28 +145,38 @@ function ButtonsModule:CreatePromptButtons()
|
||||
return self.Buttons
|
||||
end
|
||||
|
||||
function ButtonsModule:AestheticActivateButton(Button, ActivatedState, ActivatedColor)
|
||||
return task.spawn(function()
|
||||
local Glass = Button:FindFirstChild("Glass") :: BasePart
|
||||
local LookVec = Glass.CFrame.LookVector/50
|
||||
if Glass then
|
||||
Glass.Position+=LookVec
|
||||
function ButtonsModule:DeactivateButton(Button, DeactivatedColor)
|
||||
local Glass = Button:FindFirstChild("Glass") :: BasePart?
|
||||
local Part = Glass and Glass or Button
|
||||
|
||||
if not ActivatedState then
|
||||
Glass.Material = Enum.Material.Neon
|
||||
Glass.Color = ActivatedColor
|
||||
Glass.Transparency = 0
|
||||
end
|
||||
end
|
||||
Button.Position+=LookVec
|
||||
Part.Material = Enum.Material.Glass
|
||||
Part.Color = DeactivatedColor
|
||||
Part.Transparency = 0.3
|
||||
end
|
||||
|
||||
task.wait(.30)
|
||||
function ButtonsModule:ActivateButton(Button, ActivatedColor)
|
||||
local Glass = Button:FindFirstChild("Glass") :: BasePart?
|
||||
local Part = Glass and Glass or Button
|
||||
|
||||
if Glass then
|
||||
Glass.Position-=LookVec
|
||||
end
|
||||
Button.Position-=LookVec
|
||||
end)
|
||||
Part.Material = Enum.Material.Neon
|
||||
Part.Color = ActivatedColor
|
||||
Part.Transparency = 0
|
||||
end
|
||||
|
||||
function ButtonsModule:AestheticActivateButton(Button, ActivatedColor)
|
||||
local Glass = Button:FindFirstChild("Glass") :: BasePart?
|
||||
local LookVec = (Glass and Glass or Button).CFrame.LookVector/50
|
||||
if Glass then
|
||||
Glass.Position+=LookVec
|
||||
self:ActivateButton(Glass, ActivatedColor)
|
||||
end
|
||||
|
||||
Button.Position+=LookVec
|
||||
task.wait(.30)
|
||||
if Glass then
|
||||
Glass.Position-=LookVec
|
||||
end
|
||||
Button.Position-=LookVec
|
||||
end
|
||||
|
||||
return ButtonsModule
|
||||
@@ -20,11 +20,11 @@ type Impl_Constructor = {
|
||||
constructor: Constructor_Fun,
|
||||
Get: (Tags: Tags.TagsConstructor, Model: Enums.ElevatorValues) -> Tags.Lanterns,
|
||||
--Class functions
|
||||
Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Lantern) -> (),
|
||||
Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Tags.Lantern) -> (),
|
||||
DirectionUp: (self: ClassConstructor, Enabled: boolean) -> (),
|
||||
DirectionDown: (self: ClassConstructor, Enabled: boolean) -> (),
|
||||
Toggle: (self: ClassConstructor, Enabled: boolean, Floor: number) -> (),
|
||||
Reset: (self: ClassConstructor) -> ()
|
||||
Reset: (self: ClassConstructor, ExcludeFloor: number?) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
@@ -40,12 +40,6 @@ type Constructor_Return_Props = {
|
||||
Colors: Colors
|
||||
}
|
||||
|
||||
type Lantern = {
|
||||
Inst: BasePart,
|
||||
Light: BasePart?,
|
||||
Played: boolean
|
||||
}
|
||||
|
||||
export type Colors = {
|
||||
Active: Color3,
|
||||
Off: Color3
|
||||
@@ -93,10 +87,27 @@ function Lanterns:Activate(EnabledState, IsDirectionLantern, Lantern)
|
||||
self.AudioChimeLanding:Play()
|
||||
end)
|
||||
end
|
||||
|
||||
if Lantern.PointLight then
|
||||
Lantern.PointLight.Enabled = true
|
||||
LanternLight:Start(Lantern.PointLight, {
|
||||
Color = self.Colors.Active
|
||||
})
|
||||
end
|
||||
else
|
||||
if Lantern.PointLight then
|
||||
local LightTween = LanternLight:Start(Lantern.PointLight, {
|
||||
Color = Color3.new(0,0,0)
|
||||
})
|
||||
|
||||
LightTween.Completed:Once(function()
|
||||
Lantern.PointLight.Enabled = false
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lanterns:Reset()
|
||||
function Lanterns:Reset(ExcludeFloor)
|
||||
if self.LanternsMap.Up then
|
||||
self.LanternsMap.Up.Played = false
|
||||
self:Activate(false, true, self.LanternsMap.Up)
|
||||
@@ -107,8 +118,10 @@ function Lanterns:Reset()
|
||||
end
|
||||
|
||||
for n: number = 1, #self.LanternsMap do
|
||||
self:Activate(false, false, self.LanternsMap[n])
|
||||
self.LanternsMap[n].Played = false
|
||||
local Lantern = self.LanternsMap[n]
|
||||
|
||||
self:Activate(ExcludeFloor and n == ExcludeFloor or false, false, Lantern)
|
||||
Lantern.Played = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -116,10 +116,10 @@ local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, openi
|
||||
|
||||
if not (init_floors_closed[Floor] :: {})[1] and not (init_floors_closed[Floor] :: {})[2] then
|
||||
if FloorDoor1_P then
|
||||
(init_floors_closed[Floor] :: {})[1] = FloorDoor1_P+Doors.Door1Stopped_X
|
||||
(init_floors_closed[Floor] :: {})[1] = FloorDoor1_P-Doors.Door1Stopped_X
|
||||
end
|
||||
if FloorDoor2_P then
|
||||
(init_floors_closed[Floor] :: {})[2] = FloorDoor2_P+Doors.Door2Stopped_X
|
||||
(init_floors_closed[Floor] :: {})[2] = FloorDoor2_P-Doors.Door2Stopped_X
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -175,7 +175,7 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
||||
if opening then
|
||||
--This is mega cringe but the doors can open while the elevator is moving now
|
||||
local StartTime = os.clock()
|
||||
local Timing = 2
|
||||
local Timing = Doors.ElevatorDoorTime-1
|
||||
|
||||
while task.wait() do
|
||||
local Time = math.clamp((os.clock()-StartTime)/Timing, 0, 1)
|
||||
@@ -184,19 +184,18 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
|
||||
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+ElevatorDoor1_P:Lerp(Door1Vector+Doors.Door1Stopped_X, Time)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+ElevatorDoor2_P:Lerp(Door2Vector+Doors.Door2Stopped_X, Time)
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector-Doors.Door1Stopped_X, Time)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector-Doors.Door2Stopped_X, Time)
|
||||
|
||||
if Time>=1 then
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
local TweenTime = activated_via_censor and sensor_opening_speed or opening and opening_speed or Doors.ElevatorDoorTime
|
||||
|
||||
local Door1Tween = self.DoorTween1:Start(nil, {
|
||||
Position = ElevatorDoor1_P-Doors.Door1Stopped_X
|
||||
Position = ElevatorDoor1_P+Doors.Door1Stopped_X
|
||||
}, TweenInfo.new(
|
||||
TweenTime,
|
||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
||||
@@ -204,7 +203,7 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
||||
))
|
||||
|
||||
local Door2Tween = self.DoorTween2:Start(nil, {
|
||||
Position = ElevatorDoor2_P-Doors.Door2Stopped_X
|
||||
Position = ElevatorDoor2_P+Doors.Door2Stopped_X
|
||||
}, TweenInfo.new(
|
||||
TweenTime,
|
||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
||||
@@ -216,15 +215,13 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
||||
end
|
||||
Doors.__DontLeakMemory = self:__DetectSensorHit(Door1Tween, Door2Tween)
|
||||
|
||||
if not opening then
|
||||
--Door clicking noise
|
||||
task.delay(Doors.ElevatorDoorTime-.90, function()
|
||||
--is the door close enough to closing?
|
||||
if (ElevatorDoor2_P+Doors.Door2Stopped_X).X-self.ElevatorDoor2.Position.X>5 then
|
||||
self.DoorClosingClick:Play()
|
||||
end
|
||||
end)
|
||||
end
|
||||
--Door clicking noise
|
||||
task.delay(Doors.ElevatorDoorTime-.90, function()
|
||||
--is the door close enough to closing?
|
||||
if (Doors.Door2Stopped_X-ElevatorDoor2_P).X-self.ElevatorDoor2.Position.X>10 then
|
||||
self.DoorClosingClick:Play()
|
||||
end
|
||||
end)
|
||||
|
||||
return Door2Tween
|
||||
end
|
||||
@@ -285,7 +282,10 @@ function Doors:ToggleElevatorDoors(opening, floor)
|
||||
end
|
||||
end
|
||||
|
||||
local FloorDoors = DoorsAnimationFloor(self.FloorDoorsTags[floor], floor, opening)
|
||||
local FloorDoorsObjects = self.FloorDoorsTags[floor]
|
||||
if FloorDoorsObjects then
|
||||
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
||||
end
|
||||
local Door2Tween = ElevatorDoorsAnimation(self, opening)
|
||||
|
||||
if Door2Tween then
|
||||
@@ -294,7 +294,7 @@ function Doors:ToggleElevatorDoors(opening, floor)
|
||||
self.ElevatorDoor1.CanCollide = true
|
||||
self.ElevatorDoor2.CanCollide = true
|
||||
|
||||
if Doors.__DontLeakMemory then
|
||||
if Doors.__DontLeakMemory and Doors.__DontLeakMemory.Connected then
|
||||
Doors.__DontLeakMemory:Disconnect()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,6 +41,7 @@ type Impl_Static_Props = {
|
||||
Responsiveness: number,
|
||||
MaxVelocity: number,
|
||||
ButtonActivatedColor: Color3,
|
||||
ButtonDeactivatedColor: Color3,
|
||||
LanternDisplayColorOn: Color3,
|
||||
LanternDisplayColorOff: Color3,
|
||||
LanternChimeDirection: rbxassetid,
|
||||
@@ -90,6 +91,7 @@ Otis1960.LeveledDistance = 0.5
|
||||
Otis1960.Responsiveness = 50
|
||||
Otis1960.MaxVelocity = 10
|
||||
Otis1960.ButtonActivatedColor = Color3.fromRGB(180,0,0)
|
||||
Otis1960.ButtonDeactivatedColor = Color3.fromRGB(139,139,139)
|
||||
Otis1960.LanternDisplayColorOn = Color3.fromRGB(255,114,71)
|
||||
Otis1960.LanternDisplayColorOff = Color3.fromRGB(55,55,55)
|
||||
Otis1960.LanternChimeDirection = "rbxassetid://16990287228"
|
||||
@@ -111,10 +113,21 @@ local ButtonFunctions: ButtonFunctions = {
|
||||
|
||||
Prompt:AddHookTriggered(function(Player: Player)
|
||||
if DecodedFloor then
|
||||
local _ButtonThread = ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, false, Otis1960.ButtonActivatedColor)
|
||||
self:GoToLevel(DecodedFloor)
|
||||
task.spawn(function()
|
||||
ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonActivatedColor)
|
||||
|
||||
if DecodedFloor == Otis1960.__CurrentFloor then
|
||||
ButtonsConstructor:DeactivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonDeactivatedColor)
|
||||
end
|
||||
end)
|
||||
|
||||
if DecodedFloor ~= Otis1960.__CurrentFloor then
|
||||
self:GoToLevel(DecodedFloor)
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
warn(`Otis1960: Failed to decode car button, ButtonName={ButtonName}`)
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -205,7 +218,7 @@ local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
|
||||
Otis1960.__CurrentFloor = RequestedLevel
|
||||
self.BoxAlignPosition.MaxVelocity = Otis1960.MaxVelocity
|
||||
|
||||
self.LanternsConstructor:Reset()
|
||||
self.LanternsConstructor:Reset(Otis1960.__CurrentFloor)
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
@@ -238,7 +251,7 @@ function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
|
||||
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
||||
self.TractionRopes:Move(26.3, ElevatorPosition)
|
||||
self.TractionRopes:Move(27, ElevatorPosition)
|
||||
|
||||
--Kill the connection
|
||||
if GoingUp then
|
||||
@@ -257,6 +270,11 @@ function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
else
|
||||
if ElevatorPositionY<=BoxAlignY+Otis1960.FloorLevelingDistance then
|
||||
FloorLeveling(self, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance and not DoorsOpeningEvent then
|
||||
DoorsOpeningEvent = true
|
||||
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
|
||||
end
|
||||
end
|
||||
|
||||
if ElevatorPositionY<=BoxAlignY+Otis1960.LeveledDistance then
|
||||
@@ -273,6 +291,7 @@ function Otis1960:GoToLevel(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
|
||||
|
||||
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)}`)
|
||||
|
||||
@@ -34,9 +34,10 @@ type Constructor_Return_Props = {
|
||||
__export: ExportedTags
|
||||
}
|
||||
|
||||
type Lantern = {
|
||||
export type Lantern = {
|
||||
Inst: BasePart,
|
||||
Light: BasePart?,
|
||||
PointLight: PointLight?,
|
||||
Played: boolean
|
||||
}
|
||||
|
||||
@@ -183,26 +184,35 @@ function Tags:__ElevatorLanterns()
|
||||
|
||||
if Floor then
|
||||
if not Lanterns[EnumValue :: Enums.ElevatorValues][Floor] then
|
||||
local Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?
|
||||
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues][Floor] = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
Inst = Inst :: BasePart,
|
||||
Light = Light,
|
||||
PointLight = Light and Light:FindFirstChildOfClass("PointLight") :: PointLight?,
|
||||
Played = false
|
||||
}
|
||||
else
|
||||
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
|
||||
end
|
||||
else
|
||||
if FloorHint == "Up" then
|
||||
local Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?
|
||||
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues].Up = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
Inst = Inst :: BasePart,
|
||||
Light = Light,
|
||||
PointLight = Light and Light:FindFirstChildOfClass("PointLight") :: PointLight?,
|
||||
Played = false
|
||||
}
|
||||
elseif FloorHint == "Down" then
|
||||
local Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?
|
||||
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues].Down = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
Inst = Inst :: BasePart,
|
||||
Light = Light,
|
||||
PointLight = Light and Light:FindFirstChildOfClass("PointLight") :: PointLight?,
|
||||
Played = false
|
||||
}
|
||||
else
|
||||
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {FloorHint}`)
|
||||
|
||||
Reference in New Issue
Block a user