mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
need the floor algorithm
This commit is contained in:
@@ -40,8 +40,8 @@ type Constructor_Return_Props = {
|
||||
|
||||
type ElevatorAttributes = {
|
||||
PassingFloor: IntValue,
|
||||
CurrentFloor: IntValue,
|
||||
Moving: BoolValue,
|
||||
CurrentFloor: IntValue
|
||||
}
|
||||
|
||||
type ElevatorEvents = {
|
||||
|
||||
@@ -36,8 +36,8 @@ type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
__MoveFloors: (self: ClassConstructor, Level: number, RequestedLevel: number, GoingUp: boolean) -> (),
|
||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
||||
__RequestFloor: (self: ClassConstructor, Level: number, RequestedLevel: number, GoingUp: boolean) -> (),
|
||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
@@ -129,8 +129,8 @@ Otis1960.Events = {
|
||||
}
|
||||
|
||||
Otis1960.Attributes.PassingFloor.Value = 1
|
||||
Otis1960.Attributes.Moving.Value = false
|
||||
Otis1960.Attributes.CurrentFloor.Value = 1
|
||||
Otis1960.Attributes.Moving.Value = false
|
||||
|
||||
local Attributes = Otis1960.Attributes
|
||||
|
||||
@@ -259,7 +259,9 @@ local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: numbe
|
||||
end
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
local FloorQueue = {}
|
||||
|
||||
function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
self.ElevatorDoors:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
||||
|
||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||
@@ -327,8 +329,6 @@ function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
|
||||
end
|
||||
|
||||
local FloorAdvancer = {}
|
||||
|
||||
--My clever math function for determining if the elevator goal is to move upwards or not
|
||||
local function ElevatorDirectionGoingUp(Floor: number, RequestedFloor: number): boolean
|
||||
return -(Floor-RequestedFloor)>0
|
||||
@@ -338,21 +338,10 @@ function Otis1960:RequestLevel(RequestedLevel)
|
||||
local GoalLevelVEC: number = Leveling[RequestedLevel]
|
||||
|
||||
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
|
||||
--My clever math function for determining if the elevator goal is to move upwards or not
|
||||
local GoingUp = ElevatorDirectionGoingUp(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
|
||||
if Attributes.Moving.Value then
|
||||
if GoingUp then
|
||||
if Attributes.CurrentFloor.Value<=RequestedLevel then
|
||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
end
|
||||
else
|
||||
if Attributes.CurrentFloor.Value>=RequestedLevel then
|
||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
self:__RequestFloor(GoalLevelVEC, RequestedLevel, ElevatorDirectionGoingUp(Attributes.CurrentFloor.Value, RequestedLevel))
|
||||
end
|
||||
else
|
||||
warn(`[{Otis1960.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
||||
|
||||
Reference in New Issue
Block a user