mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2026-02-03 23:16:49 +00:00
big commit
This commit is contained in:
98
src/shared/Client/Camera.lua
Normal file
98
src/shared/Client/Camera.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
local Camera = {}
|
||||
Camera.__index = Camera
|
||||
|
||||
Camera.FOV = {
|
||||
Default = 70,
|
||||
Zoomed = 30,
|
||||
}
|
||||
Camera.FOV.Speed = {
|
||||
In = 0.3,
|
||||
Out = 0.4
|
||||
}
|
||||
Camera.VignetteEnabled = true
|
||||
Camera.CrosshairEffect = true
|
||||
Camera.EffectsEase = Enum.EasingStyle.Quad
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
|
||||
local ZoomTween = Tween.constructor()
|
||||
local VignetteTween = Tween.constructor()
|
||||
|
||||
function Camera.constructor(CurrentCamera: Camera, Player: Player)
|
||||
return setmetatable({
|
||||
Camera = CurrentCamera,
|
||||
Player = Player,
|
||||
}, Camera)
|
||||
end
|
||||
|
||||
function Camera:FirstPerson()
|
||||
self.Player.CameraMode = Enum.CameraMode.LockFirstPerson
|
||||
end
|
||||
|
||||
function Camera:ThirdPerson()
|
||||
self.Player.CameraMode = Enum.CameraMode.Classic
|
||||
end
|
||||
|
||||
--damn...
|
||||
type Vignette = any
|
||||
type Crosshair = any
|
||||
|
||||
function Camera:ZoomIn(Vignette: Vignette?, Crosshair: Crosshair?)
|
||||
ZoomTween:Start(self.Camera, {
|
||||
FieldOfView = Camera.FOV.Zoomed
|
||||
}, TweenInfo.new(Camera.FOV.Speed.In, Camera.EffectsEase))
|
||||
|
||||
if Camera.VignetteEnabled then
|
||||
if Vignette then
|
||||
Vignette.Screen.Enabled = true
|
||||
|
||||
VignetteTween:Start(Vignette.Icon, {
|
||||
ImageTransparency = 0
|
||||
}, TweenInfo.new(Camera.FOV.Speed.In, Camera.EffectsEase))
|
||||
else
|
||||
warn("Camera: no Vignette object was provided for the camera", debug.traceback())
|
||||
end
|
||||
end
|
||||
|
||||
if Camera.CrosshairEffect then
|
||||
if Crosshair then
|
||||
VignetteTween:Start(Crosshair.Icon, {
|
||||
ImageTransparency = .9
|
||||
}, TweenInfo.new(Camera.FOV.Speed.In, Camera.EffectsEase))
|
||||
else
|
||||
warn("Camera: no Crosshair object was provided for the camera", debug.traceback())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Camera:ZoomOut(Vignette: Vignette?, Crosshair: Crosshair?)
|
||||
ZoomTween:Start(self.Camera, {
|
||||
FieldOfView = Camera.FOV.Default
|
||||
}, TweenInfo.new(Camera.FOV.Speed.Out, Camera.EffectsEase))
|
||||
|
||||
if Camera.VignetteEnabled then
|
||||
if Vignette then
|
||||
Vignette.Screen.Enabled = true
|
||||
|
||||
VignetteTween:Start(Vignette.Icon, {
|
||||
ImageTransparency = 1
|
||||
}, TweenInfo.new(Camera.FOV.Speed.Out, Camera.EffectsEase))
|
||||
else
|
||||
warn("Camera: no Vignette object was provided for the camera", debug.traceback())
|
||||
end
|
||||
end
|
||||
|
||||
if Camera.CrosshairEffect then
|
||||
if Crosshair then
|
||||
VignetteTween:Start(Crosshair.Icon, {
|
||||
ImageTransparency = 0
|
||||
}, TweenInfo.new(Camera.FOV.Speed.In, Camera.EffectsEase))
|
||||
else
|
||||
warn("Camera: no Crosshair object was provided for the camera", debug.traceback())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Camera
|
||||
82
src/shared/Client/KeyBinds.lua
Normal file
82
src/shared/Client/KeyBinds.lua
Normal file
@@ -0,0 +1,82 @@
|
||||
--I couldn't get ContextActionService to work how i wanted it to
|
||||
|
||||
local BindLink = {}
|
||||
BindLink.__index = BindLink
|
||||
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
export type KeyBindMap = {
|
||||
[string]: {
|
||||
[Enum.KeyCode]: () -> ()
|
||||
}
|
||||
}
|
||||
export type InputBegan = RBXScriptConnection
|
||||
export type InputEnded = RBXScriptConnection
|
||||
|
||||
type CallbackFunction = () -> ()
|
||||
|
||||
function BindLink.constructor() --Allow multiple bindings of the same keys, no overwrites
|
||||
type BindConstructor = {
|
||||
BindMap: KeyBindMap,
|
||||
InputBegan: InputBegan,
|
||||
InputEnded: InputEnded
|
||||
}
|
||||
|
||||
local self: BindConstructor = {}
|
||||
self.BindMap = {
|
||||
Began = {},
|
||||
Ended = {}
|
||||
}
|
||||
|
||||
--Return these for convenience
|
||||
self.InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
|
||||
if not gameProcessedEvent then
|
||||
local switch = self.BindMap.Began[input.KeyCode]
|
||||
if switch then
|
||||
switch()
|
||||
else
|
||||
--switch.default()
|
||||
end
|
||||
end
|
||||
end)
|
||||
self.InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
|
||||
if not gameProcessedEvent then
|
||||
local switch = self.BindMap.Ended[input.KeyCode]
|
||||
if switch then
|
||||
switch()
|
||||
else
|
||||
--switch.default()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return setmetatable(self, BindLink)
|
||||
end
|
||||
|
||||
function BindLink:AddInputBegan(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
|
||||
if self.BindMap.Began[Key] then
|
||||
warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
self.BindMap.Began[Key] = Callback
|
||||
end
|
||||
end
|
||||
|
||||
function BindLink:AddInputEnded(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
|
||||
if self.BindMap.Ended[Key] then
|
||||
warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
self.BindMap.Ended[Key] = Callback
|
||||
end
|
||||
end
|
||||
|
||||
function BindLink:KeyHold(Key: Enum.KeyCode): boolean
|
||||
return UIS:IsKeyDown(Key)
|
||||
end
|
||||
|
||||
return BindLink
|
||||
Reference in New Issue
Block a user