Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- repeat wait() until game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name)
- game.Players.LocalPlayer.Character:Destroy()
- cam = game.Workspace.CurrentCamera
- _G.settings = {
- --Debug _G.settings--
- _debugShowPlrBox = true , --Show the collision box of the player [Might change to an Adornee]
- --User _G.settings--
- plrCamOffset = Vector3.new(0,0.5,10), --How far the camera will offset
- plrSprites = { --List of images used for the sprite
- ["Idle"] = {[1] = ""}, --Standing still, the number in the enclosed array is the number of keyframes, the string value is the image link
- ["Run"] = {[1] = ""}, --Running
- ["Jump"] = {[1] = ""}, --Jumping
- ["HP"] = {[1] = "http://www.roblox.com/asset/?id=156071939"} --The health display's image
- },
- plrSize = Vector3.new(1.6,3.2,0), --I recromend things like 3.2 for 32x sprites and 6.4 for 64x
- plrJmpTyp = 1, -- 0 = Normal, 1 = glide
- plrMaxHealth = 200, --Maximum health for the player
- plrDefaultLives = 3, --Number of lives the player starts with, respawns with
- --Game _G.settings--
- _gameName = "Platformer framework testing", --The game's title
- _gameVers = UDim2.new(0,1,14,56), --Version of the game, I used a UDim2 to simulate a vector 4, It goes in the order: (Major,Minor,Revision,Build)
- _gameAuthor = "Evolutional Studios", --Person or group who created the game
- _gameLevelHubID = 1
- }
- --Unmodified value set up--
- ks = {}
- ip = game:GetService("UserInputService")
- oldStage = 0
- currentStage = 0
- jump = false
- lives = _G.settings.plrDefaultLives
- script.Parent.UI.Lives.TextLabel.Text = lives
- dying = false
- stages = {
- [1] = {
- ["Bounds"] = {["Min"]=-50,["Max"]=100},
- ["SpawnPos"]=Vector3.new(0,10,0),
- ["Lighting"] = { --Default lighting, can be changed via triggers
- ["Ambient"]=Color3.new(0,0,0),
- ["Brightness"]=0,
- ["CShift_Bot"] = Color3.new(0,0,0),
- ["CShift_Top"]=Color3.new(56/255,56/255,56/255),
- ["OutdoorAmbient"]=Color3.new(178/255,178/255,178/255),
- ["ShadowCol"]=Color3.new(127/255,127/255,127/255),
- ["GeoLat"] = 40,
- ["ToD"] = "04:00:00",
- ["FogCol"]=Color3.new(0/255,0/255,0/255),
- ["FogEnd"]=30,
- ["FogStart"]=5}
- }
- }
- --Core player code, do not touch--
- --Functions--
- function spawnPlr()
- cam.FieldOfView = 90
- plr = Instance.new("Part",game.Workspace)
- plr.FormFactor = "Custom"
- plr.Size = _G.settings.plrSize
- plr.BrickColor = BrickColor.Gray()
- plr.Transparency = 1
- plr.TopSurface = "Smooth"
- plr.BottomSurface = "Smooth"
- plr.Name = "Plr"
- plr.Friction = 1
- if _G.settings._debugShowPlrBox == true then
- plr.Transparency = 0.45
- end
- local spriteC = Instance.new("SurfaceGui",plr)
- spriteC.Face = "Back"
- sprite = Instance.new("ImageLabel",spriteC)
- sprite.Image = _G.settings.plrSprites.Idle[1]
- sprite.Size = UDim2.new(1,0,1,0)
- sprite.BackgroundTransparency = 1
- sprite.BorderSizePixel = 0
- script.Parent.UI.Health.ImageLabel.Image = _G.settings.plrSprites.HP[1]
- local bg = Instance.new("BodyGyro",plr) --Keep the physics from making the player fall
- bg.cframe = CFrame.Angles(0,0,math.rad(180))
- bg.maxTorque = Vector3.new(400000,400000,400000)
- dmg = Instance.new("BoolValue",plr)
- dmg.Name = "dmg"
- bts = Instance.new("BoolValue",plr) --Back to spawn [lastPos]
- bts.Name = "bts"
- health = Instance.new("NumberValue",plr)
- health.Name = "health"
- health.Value = _G.settings.plrMaxHealth
- plr.Parent = game.Workspace
- end
- _G.createStage = function(level)
- game.Workspace[oldStage]:Destroy()
- game.ReplicatedStorage[level]:clone().Parent = game.Workspace
- currentStage = level
- oldStage = level
- plr.Position = stages[currentStage].SpawnPos
- game.Lighting.Ambient = stages[currentStage].Lighting.Ambient
- game.Lighting.Brightness = stages[currentStage].Lighting.Brightness
- game.Lighting.ColorShift_Bottom = stages[currentStage].Lighting.CShift_Bot
- game.Lighting.ColorShift_Top = stages[currentStage].Lighting.CShift_Top
- game.Lighting.OutdoorAmbient = stages[currentStage].Lighting.OutdoorAmbient
- game.Lighting.ShadowColor = stages[currentStage].Lighting.ShadowCol
- game.Lighting.GeographicLatitude = stages[currentStage].Lighting.GeoLat
- game.Lighting.TimeOfDay = stages[currentStage].Lighting.ToD
- game.Lighting.FogColor = stages[currentStage].Lighting.FogCol
- game.Lighting.FogStart = stages[currentStage].Lighting.FogStart
- game.Lighting.FogEnd = stages[currentStage].Lighting.FogEnd
- end
- function isGround(hit)
- if string.lower(hit.Name) == "baseplate" or string.lower(hit.Name) == "ground" or string.lower(hit.Name) == "floor" or string.lower(hit.Name) == "floor" then
- return true
- else return false
- end
- end
- function plrGrounded()
- local ray = Ray.new(plr.Position, Vector3.new(0, -10, 0))
- local hit, position = game.Workspace:FindPartOnRay(ray, plr)
- if (position - plr.Position).magnitude <= 1.6 and isGround(hit) then return true else return false end
- end
- function died()
- if dying ~= true then
- dying = true
- print("Death")
- lives = (lives - 1)
- script.Parent.UI.Lives.TextLabel.Text = lives
- if lives <= 0 then
- script.Parent.DeathScreen.Core.Visible = true
- health.Value = _G.settings.plrMaxHealth
- lives = _G.settings.plrDefaultLives
- end
- health.Value = _G.settings.plrMaxHealth
- wait(.5)
- dying = false
- end
- end
- --Coroutines--
- camUpd = coroutine.wrap(function()
- cam.CameraType = Enum.CameraType.Scriptable
- game:GetService("RunService").RenderStepped:connect(function()
- cam.CoordinateFrame = CFrame.new(plr.Position + _G.settings.plrCamOffset)
- end)
- end)
- inp = coroutine.wrap(function()
- game:GetService("RunService").RenderStepped:connect(function()
- ip.InputBegan:connect(function(k,p)
- ks[k.KeyCode] = true
- end)
- ip.InputEnded:connect(function(k,p)
- ks[k.KeyCode] = false
- end)
- end)
- end)
- plrControl = coroutine.wrap(function()
- game:GetService("RunService").RenderStepped:connect(function()
- plr.CFrame = CFrame.new(plr.CFrame.x,plr.CFrame.y,0)*CFrame.Angles(0,0,math.rad(180))
- plr.Velocity = Vector3.new(plr.Velocity.x/1.25,plr.Velocity.y/1.05,0)
- --[[if plr.Position.z ~= 0 then
- plr.Position = Vector3.new(plr.Position.x,plr.Position.y,0)
- end]]--
- --[[if ks[Enum.KeyCode.W] and ks[Enum.KeyCode.A] then
- elseif ks[Enum.KeyCode.W] and ks[Enum.KeyCode.D] then
- elseif ks[Enum.KeyCode.S] and ks[Enum.KeyCode.A] then
- elseif ks[Enum.KeyCode.S] and ks[Enum.KeyCode.D] then]]--
- if ks[Enum.KeyCode.W] then
- elseif ks[Enum.KeyCode.S] then
- elseif ks[Enum.KeyCode.A] then
- plr.Velocity = Vector3.new(-25,plr.Velocity.y,0)
- elseif ks[Enum.KeyCode.D] then
- plr.Velocity = Vector3.new(25,plr.Velocity.y,0)
- end
- if ks[Enum.KeyCode.Space] and jump ~= true then
- jump = true
- if _G.settings.plrJmpTyp == 0 then
- plr.Velocity = Vector3.new(plr.Velocity.x,50,0)
- elseif _G.settings.plrJmpTyp == 1 then
- for i=1, 10 do
- plr.Velocity = Vector3.new(plr.Velocity.x,i*5,0)
- end
- end
- repeat wait(0.05) until plrGrounded() == true
- plr.Velocity = Vector3.new(plr.Velocity.x,0,0)
- jump = false
- end
- end)
- end)
- bounds = coroutine.wrap(function()
- lastPos = Vector3.new(0,0,0)
- game:GetService("RunService").RenderStepped:connect(function()
- plr.TouchEnded:connect(function(hit)
- local lEdge = Vector2.new(hit.Position.x - hit.Size.x/2,hit.Position.y + hit.Size.y/2)
- local rEdge = Vector2.new(hit.Position.x + hit.Size.x/2,hit.Position.y + hit.Size.y/2)
- if isGround(hit) == true then
- if plr.Position.x < hit.Position.x then
- lastPos = Vector3.new(lEdge.x + 0.5,lEdge.y)
- elseif plr.Position.x > hit.Position.x then
- lastPos = Vector3.new(rEdge.x - 0.5,rEdge.y)
- else plr.Position = hit.Position * Vector3.new(0,hit.Position.y + hit.Position.Size.y/2,0)
- end
- end
- end)
- if plr.Position.y < stages[currentStage].Bounds.Min then
- plr.Position = lastPos
- plr.Velocity = Vector3.new(0,-10,0)
- end
- if plr.Position.y > stages[currentStage].Bounds.Max then
- plr.Position = lastPos
- plr.Velocity = Vector3.new(0,-10,0)
- end
- end)
- end)
- danger = coroutine.wrap(function()
- health.Changed:connect(function()
- if health.Value > _G.settings.plrMaxHealth then
- health.Value = _G.settings.plrMaxHealth
- elseif health.Value <= 0 then
- health.Value = 0
- died()
- end
- script.Parent.UI.Health.HPCont.HP.Size = UDim2.new(health.Value/_G.settings.plrMaxHealth,0,1,0)
- end)
- game:GetService("RunService").RenderStepped:connect(function()
- if bts.Value == true then
- plr.Position = lastPos
- plr.Velocity = Vector3.new(0,-10,0)
- bts.Value = false
- end
- if dmg.Value == true then
- --Flicker effect, no damage
- wait(1)
- dmg.Value = false
- end
- end)
- end)
- --Run--
- wait(0.5)
- spawnPlr()
- camUpd()
- inp()
- plrControl()
- _G.createStage(1)
- bounds()
- danger()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement