mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
Spinning objects
This commit is contained in:
@@ -76,7 +76,7 @@ function StudioEntities.indexAll(enabled: boolean)
|
||||
local Case: HideEditor = EditorEntities[Item.Name]
|
||||
if Case then
|
||||
table.insert(StudioEntities.IndexedEntities, Item)
|
||||
Case(Item, enabled)
|
||||
Case(Item :: BasePart | Folder, enabled)
|
||||
end
|
||||
|
||||
if Item:IsA("BasePart") then
|
||||
|
||||
@@ -9,7 +9,8 @@ local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type TagsConstructor = TagsModule.TagsConstructor
|
||||
type TagProduct = TagsModule.TagProduct
|
||||
type HumanoidRootPart = BasePart
|
||||
type PromptCallback = (Player: Player) -> ()
|
||||
|
||||
@@ -30,9 +31,9 @@ type Impl_Static_Props = {
|
||||
ButtonEnum: any
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags, Model: string) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, Model: string) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
Tags: TagsConstructor,
|
||||
Model: string,
|
||||
Buttons: ButtonsTree
|
||||
}
|
||||
@@ -53,9 +54,9 @@ export type ButtonsConstructor = ClassConstructor
|
||||
local ButtonsModule = {} :: Impl_Constructor
|
||||
ButtonsModule.__index = ButtonsModule
|
||||
|
||||
function ButtonsModule.constructor(Tags, Model)
|
||||
function ButtonsModule.constructor(TagsConstructor, Model)
|
||||
return setmetatable({
|
||||
Tags = Tags,
|
||||
Tags = TagsConstructor,
|
||||
Model = Model,
|
||||
Buttons = {
|
||||
Landing = {},
|
||||
@@ -76,7 +77,7 @@ end
|
||||
function ButtonsModule:Get()
|
||||
local Buttons: GetButtons = {}
|
||||
|
||||
for TagName: string, Inst: Instance | {Instance} in self.Tags do
|
||||
for TagName: string, Inst: TagProduct in self.Tags.__export do
|
||||
local Split = TagName:split('_')
|
||||
if Split[1] == self.Model and (Split[2] == "ElevatorButton" or Split[2] == "RelayButton") then
|
||||
if typeof(Inst) == "Instance" then
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
local Enums = {}
|
||||
|
||||
export type EnumValue = typeof(Enums.Button)
|
||||
| typeof(Enums.ButtonTree)
|
||||
| typeof(Enums.Elevator)
|
||||
export type EnumValue = EnumButton | EnumButtonTree | EnumElevator
|
||||
export type EnumButton = typeof(Enums.Button)
|
||||
export type EnumButtonTree = typeof(Enums.ButtonTree)
|
||||
export type EnumElevator = typeof(Enums.Elevator)
|
||||
|
||||
Enums.Button = {
|
||||
Car = "CarButton" :: "CarButton",
|
||||
|
||||
@@ -8,6 +8,7 @@ local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RS: RunService = game:GetService("RunService")
|
||||
|
||||
local TagsModule = require(Storage:WaitForChild("Tags"))
|
||||
local Easings = require(Storage:WaitForChild("AlgebraEasings"))
|
||||
|
||||
local Leveling = require(script:WaitForChild("Leveling"))
|
||||
local Doors = require(script:WaitForChild("Doors"))
|
||||
@@ -19,13 +20,14 @@ local ButtonTags = require(Elevators:WaitForChild("Buttons"))
|
||||
local TractionRopes = require(Elevators:WaitForChild("TractionRopes"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type TagsConstructor = TagsModule.TagsConstructor
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
__MoveFloors: (self: ClassConstructor, Level: number) -> (),
|
||||
_MoveFloors: (self: ClassConstructor, Level: number) -> (),
|
||||
GoToLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
@@ -35,14 +37,13 @@ type Impl_Static_Props = {
|
||||
MaxVelocity: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
ElevatorBox_1960: UnionOperation,
|
||||
ElevatorDoor1: BasePart,
|
||||
ElevatorDoor2: BasePart,
|
||||
ElevatorDoorSensor: Folder,
|
||||
ProximityButtons: {Instance},
|
||||
BoxAttachment: Attachment,
|
||||
BoxAlignPosition: AlignPosition,
|
||||
BoxAlignOrientation: AlignOrientation,
|
||||
@@ -50,9 +51,16 @@ type Constructor_Return_Props = {
|
||||
Ropes: {Instance},
|
||||
TractionRopes: TractionRopes.TractionRopesConstructor,
|
||||
PiePlateSelector: UnionOperation,
|
||||
__RopeConnection: RBXScriptConnection?
|
||||
Pulley: UnionOperation,
|
||||
Pulley2: UnionOperation,
|
||||
Governor: UnionOperation,
|
||||
GovernorFlyballs: UnionOperation,
|
||||
PieplatePulley: UnionOperation,
|
||||
__MovingConnection: RBXScriptConnection?
|
||||
}
|
||||
|
||||
type ButtonFunction = () -> ()
|
||||
|
||||
local Otis1960 = {} :: Impl_Constructor
|
||||
Otis1960.__index = Otis1960
|
||||
|
||||
@@ -82,6 +90,20 @@ local function ButtonPress(Button: BasePart, Activated: boolean)
|
||||
end)
|
||||
end
|
||||
|
||||
local ButtonFunctions: {[Enums.EnumButtonTree]: ButtonFunction} = {
|
||||
[Enums.ButtonTree.Landing] = function()
|
||||
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Car] = function()
|
||||
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Special] = function()
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonType: Enums.EnumValue)
|
||||
for ButtonNameType, ButtonList in ButtonsConstructor.Buttons do
|
||||
for ButtonName, ButtonTree in ButtonList do
|
||||
@@ -118,19 +140,23 @@ local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTag
|
||||
end
|
||||
end
|
||||
|
||||
function Otis1960.constructor(Tags)
|
||||
function Otis1960.constructor(TagsConstructor)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.Tags = Tags
|
||||
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.PiePlatePlates = Tags.Otis1960_PiePlatePlates :: UnionOperation
|
||||
self.WheelRotation = Tags.WheelRotation :: {Instance}
|
||||
self.ElevatorBox_1960 = TagsConstructor:Request("ElevatorMover_1960") :: UnionOperation
|
||||
self.ElevatorDoor1 = TagsConstructor:Request("ElevatorDoor_1960_1") :: BasePart
|
||||
self.ElevatorDoor2 = TagsConstructor:Request("ElevatorDoor_1960_2") :: BasePart
|
||||
self.ElevatorDoorSensor = TagsConstructor:Request("ElevatorDoor_Sensor_1960") :: Folder
|
||||
self.Ropes = TagsConstructor:Request("1960_ElevatorPulleyRope") :: {Instance}
|
||||
self.PiePlateSelector = TagsConstructor:Request("Otis1960_PiePlateSelector") :: UnionOperation
|
||||
self.PiePlatePlates = TagsConstructor:Request("Otis1960_PiePlatePlates") :: UnionOperation
|
||||
|
||||
--Rotation objects
|
||||
self.Pulley = TagsConstructor:Request("Otis1960_Pulley") :: UnionOperation
|
||||
self.Pulley2 = TagsConstructor:Request("Otis1960_Pulley2") :: UnionOperation
|
||||
self.Governor = TagsConstructor:Request("Otis1960_Governor") :: UnionOperation
|
||||
self.GovernorFlyballs = TagsConstructor:Request("Otis1960_GovernorFlyballs") :: UnionOperation
|
||||
self.PieplatePulley = TagsConstructor:Request("Otis1960_PieplatePulley") :: UnionOperation
|
||||
|
||||
self.BoxAttachment,
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
|
||||
@@ -140,7 +166,7 @@ function Otis1960.constructor(Tags)
|
||||
self.PiePlate = PieplateModule.constructor(self.PiePlateSelector, self.PiePlatePlates, self.ElevatorBox_1960)
|
||||
|
||||
--Buttons
|
||||
local ButtonsConstructor = ButtonTags.constructor(Tags, Enums.Elevator.Otis1960)
|
||||
local ButtonsConstructor = ButtonTags.constructor(TagsConstructor, Enums.Elevator.Otis1960)
|
||||
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
|
||||
|
||||
local ClassConstructor = setmetatable(self, Otis1960)
|
||||
@@ -151,18 +177,54 @@ function Otis1960.constructor(Tags)
|
||||
return ClassConstructor
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(Level)
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
self.TractionRopes:Moving(Level, 26)
|
||||
--self.PiePlate:test()
|
||||
|
||||
function Otis1960:_MoveFloors(Level)
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
local RotationDelta = 0
|
||||
local PulleyPosition = self.Pulley.CFrame
|
||||
local GovernorPosition = self.Governor.CFrame
|
||||
local FlyballPosition = self.GovernorFlyballs.CFrame
|
||||
local Pulley2Position = self.Pulley2.CFrame
|
||||
local PieplatePulleyPosition = self.PieplatePulley.CFrame
|
||||
|
||||
local LastVelocityDelta = 0
|
||||
|
||||
if self.__MovingConnection then
|
||||
self.__MovingConnection:Disconnect()
|
||||
end
|
||||
--Otis1960_ShaftGovernor
|
||||
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt) --Not safe for parallel
|
||||
RotationDelta+=1
|
||||
|
||||
local ElevatorPosition = self.ElevatorBox_1960.Position
|
||||
local ElevatorVelocity = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
local VelocitySmoothing = Easings.Linear(LastVelocityDelta, ElevatorVelocity, .5)
|
||||
LastVelocityDelta = ElevatorVelocity
|
||||
|
||||
local PullAngle_2 = math.rad(RotationDelta*VelocitySmoothing/2)
|
||||
local PullAngle = math.rad(RotationDelta*VelocitySmoothing)
|
||||
|
||||
self.Pulley.CFrame = PulleyPosition *CFrame.Angles(-PullAngle_2, 0, 0)
|
||||
self.Pulley2.CFrame = Pulley2Position *CFrame.Angles(PullAngle_2, 0, 0)
|
||||
self.Governor.CFrame = GovernorPosition *CFrame.Angles(0, PullAngle_2, 0)
|
||||
self.GovernorFlyballs.CFrame = FlyballPosition *CFrame.Angles(PullAngle, 0, 0)
|
||||
self.PieplatePulley.CFrame = PieplatePulleyPosition*CFrame.Angles(PullAngle_2, 0, 0)
|
||||
|
||||
self.TractionRopes:Move(26.3, ElevatorPosition)
|
||||
|
||||
if ElevatorPosition.Y>=self.BoxAlignPosition.Position.Y then
|
||||
(self.__MovingConnection :: RBXScriptConnection):Disconnect()
|
||||
print("Dead")
|
||||
end
|
||||
end)
|
||||
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, Level, ElevatorBoxCurrentPos.Z)
|
||||
end
|
||||
|
||||
function Otis1960:GoToLevel(RequestedLevel)
|
||||
local level: number = Leveling[RequestedLevel]
|
||||
if level and level ~= 0 then
|
||||
self:__MoveFloors(level)
|
||||
self:_MoveFloors(level)
|
||||
else
|
||||
warn(`[{Enums.Elevator.Otis1960}]: landing out of range! requested landing: {tostring(RequestedLevel)}`)
|
||||
end
|
||||
|
||||
@@ -10,17 +10,15 @@ type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Moving: (self: ClassConstructor, Level: number, Offset: number) -> (),
|
||||
Move: (self: ClassConstructor, Offset: number, ElevatorPosition: Vector3) -> (),
|
||||
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
|
||||
@@ -28,8 +26,6 @@ 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]
|
||||
@@ -37,26 +33,17 @@ function TractionRopes.constructor(RopeTags, ElevatorBox, Leveling)
|
||||
|
||||
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) --Not safe for parallel
|
||||
local Elevator = self.ElevatorBox
|
||||
local ElevatorPosition = Elevator.Position
|
||||
local l = self.BiggestRopeLength-ElevatorPosition.Y+Offset
|
||||
function TractionRopes:Move(Offset, ElevatorPosition)
|
||||
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)
|
||||
for i: number = 1, #self.Ropes do
|
||||
(self.Ropes[i] :: RopeConstraint).Length = l
|
||||
end
|
||||
end
|
||||
|
||||
function TractionRopes:Stopped()
|
||||
|
||||
@@ -9,7 +9,7 @@ export type Effects = {
|
||||
}
|
||||
|
||||
local Lighting = game:GetService("Lighting")
|
||||
local mat_fullbright = false
|
||||
local mat_fullbright = game:GetService("RunService"):IsStudio()
|
||||
|
||||
local Lighting_PropsTree: LightingProps = {
|
||||
["Ambient"] = mat_fullbright and Color3.new(1,1,1) or Color3.fromRGB(40,40,40),
|
||||
|
||||
@@ -16,8 +16,7 @@ local StarterPlayer_Stuff = require(script:WaitForChild("StarterPlayer"))
|
||||
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
|
||||
|
||||
local TagsConstructor = TagsModule.constructor()
|
||||
local Tags = TagsConstructor.Exports
|
||||
print("[DEBUG] Tags=", Tags)
|
||||
print("[DEBUG] Tags=", TagsConstructor.__export)
|
||||
|
||||
HideEditorEntities.indexAll(not false)
|
||||
TagsConstructor:Nuke()
|
||||
@@ -27,4 +26,4 @@ Lighting_Stuff()
|
||||
Workspace_Stuff()
|
||||
|
||||
--Start the elevators
|
||||
local Otis1960 = Otis1960_Module.constructor(Tags)
|
||||
local Otis1960 = Otis1960_Module.constructor(TagsConstructor)
|
||||
|
||||
@@ -2,28 +2,30 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type Error = never
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Nuke: (self: ClassConstructor) -> (),
|
||||
Nuke: (self: ClassConstructor) -> (),
|
||||
Request: (self: ClassConstructor, Name: string) -> TagProduct | Error
|
||||
}
|
||||
|
||||
type Constructor_Fun = () -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Exports: ExportedTags
|
||||
__export: ExportedTags
|
||||
}
|
||||
|
||||
export type ExportedTags = {
|
||||
[string]: Instance | {Instance}
|
||||
}
|
||||
export type TagProduct = Instance | {Instance}
|
||||
export type ExportedTags = {[string]: TagProduct}
|
||||
export type TagsConstructor = ClassConstructor
|
||||
|
||||
local Tags = {} :: Impl_Constructor
|
||||
Tags.__index = Tags
|
||||
|
||||
local CS = game:GetService("CollectionService")
|
||||
local CS: CollectionService = game:GetService("CollectionService")
|
||||
|
||||
function Tags.constructor()
|
||||
local Exports: ExportedTags = {}
|
||||
@@ -34,15 +36,20 @@ function Tags.constructor()
|
||||
local Tagged = CS:GetTagged(TagName)
|
||||
Exports[TagName] = #Tagged>1 and Tagged or Tagged[1]
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
Exports = Exports
|
||||
__export = Exports
|
||||
}, Tags)
|
||||
end
|
||||
|
||||
function Tags:Nuke()
|
||||
local Exports = self.Exports
|
||||
function Tags:Request(Name)
|
||||
return self.__export[Name] or error(`Error requesting tag name, tag name "{Name}" does not exist`, 2)
|
||||
end
|
||||
|
||||
for i: string, v: Instance | {Instance} in Exports do
|
||||
function Tags:Nuke()
|
||||
local Exports = self.__export
|
||||
|
||||
for i: string, v: TagProduct in Exports do
|
||||
if type(v) == "table" then
|
||||
for n: number = 1, #v do
|
||||
CS:RemoveTag(v[n], i)
|
||||
|
||||
Reference in New Issue
Block a user