mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
need a serial loop function for everything and pieplate selector module
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
return function(ElevatorBox: BasePart, StartPosition: Vector3): (Attachment, AlignPosition, AlignOrientation)
|
||||
return function(ElevatorBox: BasePart, StartPosition: Vector3, Responsiveness: number, MaxVelocity: number): (Attachment, AlignPosition, AlignOrientation)
|
||||
local BoxAttachment = Instance.new("Attachment")
|
||||
BoxAttachment.Parent = ElevatorBox
|
||||
|
||||
@@ -13,10 +13,11 @@ return function(ElevatorBox: BasePart, StartPosition: Vector3): (Attachment, Ali
|
||||
BoxAlignPosition.Position = StartPosition
|
||||
-- BoxAlignPosition.RigidityEnabled = true
|
||||
-- Lines below are disabled with RigidityEnabled true
|
||||
BoxAlignPosition.Responsiveness = 5
|
||||
BoxAlignPosition.MaxVelocity = 10
|
||||
BoxAlignPosition.Responsiveness = Responsiveness
|
||||
BoxAlignPosition.MaxVelocity = MaxVelocity
|
||||
--
|
||||
BoxAlignPosition.Parent = ElevatorBox
|
||||
|
||||
local BoxAlignOrientation = Instance.new("AlignOrientation")
|
||||
BoxAlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
|
||||
BoxAlignOrientation.Attachment0 = BoxAttachment
|
||||
|
||||
@@ -15,6 +15,7 @@ local Doors = require(script:WaitForChild("Doors"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
|
||||
local ButtonTags = require(Elevators:WaitForChild("Buttons"))
|
||||
local TractionRopes = require(Elevators:WaitForChild("TractionRopes"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
|
||||
@@ -28,14 +29,15 @@ type Impl_Constructor = {
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
Moving: boolean
|
||||
Moving: boolean,
|
||||
Responsiveness: number,
|
||||
MaxVelocity: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
ElevatorBox_1960: BasePart,
|
||||
ElevatorBox: BasePart,
|
||||
ElevatorBox_1960: UnionOperation,
|
||||
ElevatorDoor1: BasePart,
|
||||
ElevatorDoor2: BasePart,
|
||||
ElevatorDoorSensor: Folder,
|
||||
@@ -44,12 +46,18 @@ type Constructor_Return_Props = {
|
||||
BoxAlignPosition: AlignPosition,
|
||||
BoxAlignOrientation: AlignOrientation,
|
||||
ElevatorDoors: Doors.DoorConstructor,
|
||||
Ropes: {Instance},
|
||||
TractionRopes: TractionRopes.TractionRopesConstructor,
|
||||
PiePlateSelector: UnionOperation,
|
||||
__RopeConnection: RBXScriptConnection?
|
||||
}
|
||||
|
||||
local Otis1960 = {} :: Impl_Constructor
|
||||
Otis1960.__index = Otis1960
|
||||
|
||||
Otis1960.Moving = false
|
||||
Otis1960.Responsiveness = 50
|
||||
Otis1960.MaxVelocity = 10
|
||||
|
||||
local function ButtonPress(Button: BasePart, Activated: boolean)
|
||||
task.spawn(function()
|
||||
@@ -83,7 +91,7 @@ local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTag
|
||||
|
||||
ButtonsConstructor:HookPromptButtonsGroup(ButtonTree.Prompt, ButtonTree.Inst, function(_Player: Player)
|
||||
if DecodedFloor then
|
||||
ButtonTree.Prompt.Enabled = false
|
||||
--ButtonTree.Prompt.Enabled = false
|
||||
ButtonPress(ButtonTree.Inst, false)
|
||||
|
||||
self:GoToLevel(DecodedFloor)
|
||||
@@ -112,16 +120,21 @@ end
|
||||
function Otis1960.constructor(Tags)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.Tags = Tags
|
||||
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: BasePart
|
||||
self.ElevatorBox = Tags.ElevatorMover_1960 :: BasePart
|
||||
self.ElevatorDoor1 = Tags.ElevatorDoor_1960_1 :: BasePart
|
||||
self.ElevatorDoor2 = Tags.ElevatorDoor_1960_2 :: BasePart
|
||||
self.ElevatorDoorSensor = Tags.ElevatorDoor_Sensor_1960 :: Folder
|
||||
self.ProximityButtons = Tags.ProximityElevatorButton :: {Instance}
|
||||
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: UnionOperation
|
||||
self.ElevatorDoor1 = Tags.ElevatorDoor_1960_1 :: BasePart
|
||||
self.ElevatorDoor2 = Tags.ElevatorDoor_1960_2 :: BasePart
|
||||
self.ElevatorDoorSensor = Tags.ElevatorDoor_Sensor_1960 :: Folder
|
||||
self.ProximityButtons = Tags.ProximityElevatorButton :: {Instance}
|
||||
self.Ropes = Tags["1960_ElevatorPulleyRope"] :: {Instance}
|
||||
self.PiePlateSelector = Tags.Otis1960_PiePlateSelector :: UnionOperation
|
||||
|
||||
self.BoxAttachment, self.BoxAlignPosition, self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position)
|
||||
self.ElevatorDoors = Doors.constructor(self.ElevatorBox, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
self.BoxAttachment,
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
|
||||
|
||||
self.ElevatorDoors = Doors.constructor(self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
self.TractionRopes = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
|
||||
|
||||
--Buttons
|
||||
local ButtonsConstructor = ButtonTags.constructor(Tags, Enums.Elevator.Otis1960)
|
||||
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
|
||||
@@ -134,20 +147,10 @@ function Otis1960.constructor(Tags)
|
||||
return ClassConstructor
|
||||
end
|
||||
|
||||
local BiggestRopeLength = Leveling[#Leveling]-2
|
||||
|
||||
function Otis1960:__MoveFloors(Level)
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox.Position
|
||||
|
||||
local RopeConnection = RS.Heartbeat:Connect(function(_dt)
|
||||
local Ropes = self.Tags["1960_ElevatorPulleyRope"] :: {Instance}
|
||||
|
||||
for i: number = 1, #Ropes do
|
||||
(Ropes[i] :: RopeConstraint).Length = (BiggestRopeLength-self.ElevatorBox.Position.Y)*10
|
||||
print((Ropes[i] :: RopeConstraint).Length)
|
||||
end
|
||||
end)
|
||||
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
self.TractionRopes:Moving(Level, 26)
|
||||
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, Level, ElevatorBoxCurrentPos.Z)
|
||||
end
|
||||
|
||||
|
||||
66
src/server/main/Elevators/TractionRopes.lua
Normal file
66
src/server/main/Elevators/TractionRopes.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type RopeTags = {Instance}
|
||||
type Leveling = {number}
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Moving: (self: ClassConstructor, Level: number, Offset: number) -> (),
|
||||
Stopped: (self: ClassConstructor) -> (),
|
||||
}
|
||||
|
||||
type Constructor_Fun = (RopeTags: RopeTags, ElevatorBox: UnionOperation, Leveling: Leveling) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Ropes: RopeTags,
|
||||
ElevatorBox: UnionOperation,
|
||||
Leveling: Leveling,
|
||||
BiggestRopeLength: number,
|
||||
__RopeConnection: RBXScriptConnection?
|
||||
}
|
||||
|
||||
export type TractionRopesConstructor = ClassConstructor
|
||||
|
||||
local TractionRopes = {} :: Impl_Constructor
|
||||
TractionRopes.__index = TractionRopes
|
||||
|
||||
local RS: RunService = game:GetService("RunService")
|
||||
|
||||
function TractionRopes.constructor(RopeTags, ElevatorBox, Leveling)
|
||||
local ArbitraryRopeContact = RopeTags[1].Parent :: BasePart
|
||||
local HighestLevel = Leveling[#Leveling]
|
||||
local BiggestRopeLength = HighestLevel-(ArbitraryRopeContact.Position.Y-HighestLevel)
|
||||
|
||||
return setmetatable({
|
||||
Ropes = RopeTags,
|
||||
ElevatorBox = ElevatorBox,
|
||||
Leveling = Leveling,
|
||||
BiggestRopeLength = BiggestRopeLength
|
||||
}, TractionRopes)
|
||||
end
|
||||
|
||||
function TractionRopes:Moving(Level, Offset)
|
||||
if self.__RopeConnection then
|
||||
self.__RopeConnection:Disconnect()
|
||||
end
|
||||
self.__RopeConnection = RS.Heartbeat:Connect(function(_dt)
|
||||
local Elevator = self.ElevatorBox
|
||||
local ElevatorPosition = Elevator.Position
|
||||
local l = self.BiggestRopeLength-ElevatorPosition.Y+Offset
|
||||
|
||||
for i: number = 1, #self.Ropes do
|
||||
(self.Ropes[i] :: RopeConstraint).Length = l
|
||||
end
|
||||
--print(Level-ElevatorPosition.Y)
|
||||
end)
|
||||
end
|
||||
|
||||
function TractionRopes:Stopped()
|
||||
|
||||
end
|
||||
|
||||
return TractionRopes
|
||||
Reference in New Issue
Block a user