Advertisement
Guest User

Core.lua

a guest
Jul 1st, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.64 KB | None | 0 0
  1. repeat wait() until game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name)
  2. game.Players.LocalPlayer.Character:Destroy()
  3.  
  4. cam = game.Workspace.CurrentCamera
  5.  
  6. _G.settings = {
  7.    
  8.     --Debug _G.settings--
  9. _debugShowPlrBox = true , --Show the collision box of the player [Might change to an Adornee]
  10.     --User _G.settings--
  11. plrCamOffset = Vector3.new(0,0.5,10), --How far the camera will offset
  12. plrSprites = { --List of images used for the sprite
  13.     ["Idle"] = {[1] = ""}, --Standing still, the number in the enclosed array is the number of keyframes, the string value is the image link
  14.     ["Run"] = {[1] = ""}, --Running
  15.     ["Jump"] = {[1] = ""}, --Jumping
  16.     ["HP"] = {[1] = "http://www.roblox.com/asset/?id=156071939"} --The health display's image
  17. },
  18. plrSize = Vector3.new(1.6,3.2,0), --I recromend things like 3.2 for 32x sprites and 6.4 for 64x
  19. plrJmpTyp = 1, -- 0 = Normal, 1 = glide
  20. plrMaxHealth = 200, --Maximum health for the player
  21. plrDefaultLives = 3, --Number of lives the player starts with, respawns with
  22.     --Game _G.settings--
  23. _gameName = "Platformer framework testing", --The game's title
  24. _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)
  25. _gameAuthor = "Evolutional Studios", --Person or group who created the game
  26. _gameLevelHubID = 1
  27. }
  28.  
  29.     --Unmodified value set up--
  30. ks = {}
  31. ip = game:GetService("UserInputService")
  32. oldStage = 0
  33. currentStage = 0
  34. jump = false
  35. lives = _G.settings.plrDefaultLives
  36. script.Parent.UI.Lives.TextLabel.Text = lives
  37. dying = false
  38.  
  39. stages = {
  40. [1] = {
  41.     ["Bounds"] = {["Min"]=-50,["Max"]=100},
  42.     ["SpawnPos"]=Vector3.new(0,10,0),
  43.     ["Lighting"] = { --Default lighting, can be changed via triggers
  44.         ["Ambient"]=Color3.new(0,0,0),
  45.         ["Brightness"]=0,
  46.         ["CShift_Bot"] = Color3.new(0,0,0),
  47.         ["CShift_Top"]=Color3.new(56/255,56/255,56/255),
  48.         ["OutdoorAmbient"]=Color3.new(178/255,178/255,178/255),
  49.         ["ShadowCol"]=Color3.new(127/255,127/255,127/255),
  50.         ["GeoLat"] = 40,
  51.         ["ToD"] = "04:00:00",
  52.         ["FogCol"]=Color3.new(0/255,0/255,0/255),
  53.         ["FogEnd"]=30,
  54.         ["FogStart"]=5}
  55.     }      
  56. }
  57.  
  58.     --Core player code, do not touch--
  59.  
  60.  
  61.     --Functions--
  62. function spawnPlr()
  63.     cam.FieldOfView = 90
  64.     plr = Instance.new("Part",game.Workspace)
  65.     plr.FormFactor = "Custom"
  66.     plr.Size = _G.settings.plrSize
  67.     plr.BrickColor = BrickColor.Gray()
  68.     plr.Transparency = 1
  69.     plr.TopSurface = "Smooth"
  70.     plr.BottomSurface = "Smooth"
  71.     plr.Name = "Plr"
  72.     plr.Friction = 1
  73.     if _G.settings._debugShowPlrBox == true then
  74.         plr.Transparency = 0.45
  75.     end
  76.    
  77.     local spriteC = Instance.new("SurfaceGui",plr)
  78.     spriteC.Face = "Back"
  79.     sprite = Instance.new("ImageLabel",spriteC)
  80.     sprite.Image = _G.settings.plrSprites.Idle[1]
  81.     sprite.Size = UDim2.new(1,0,1,0)
  82.     sprite.BackgroundTransparency = 1
  83.     sprite.BorderSizePixel = 0
  84.     script.Parent.UI.Health.ImageLabel.Image = _G.settings.plrSprites.HP[1]
  85.     local bg = Instance.new("BodyGyro",plr) --Keep the physics from making the player fall
  86.     bg.cframe = CFrame.Angles(0,0,math.rad(180))   
  87.     bg.maxTorque = Vector3.new(400000,400000,400000)   
  88.     dmg = Instance.new("BoolValue",plr)
  89.     dmg.Name = "dmg"
  90.     bts = Instance.new("BoolValue",plr) --Back to spawn [lastPos]  
  91.     bts.Name = "bts"
  92.     health = Instance.new("NumberValue",plr)   
  93.     health.Name = "health"
  94.     health.Value = _G.settings.plrMaxHealth
  95.     plr.Parent = game.Workspace
  96.        
  97. end
  98.  
  99. _G.createStage = function(level)
  100.    
  101.         game.Workspace[oldStage]:Destroy()
  102.        
  103.         game.ReplicatedStorage[level]:clone().Parent = game.Workspace
  104.         currentStage = level
  105.         oldStage = level
  106.         plr.Position = stages[currentStage].SpawnPos
  107.         game.Lighting.Ambient = stages[currentStage].Lighting.Ambient
  108.         game.Lighting.Brightness = stages[currentStage].Lighting.Brightness
  109.         game.Lighting.ColorShift_Bottom = stages[currentStage].Lighting.CShift_Bot
  110.         game.Lighting.ColorShift_Top = stages[currentStage].Lighting.CShift_Top
  111.         game.Lighting.OutdoorAmbient = stages[currentStage].Lighting.OutdoorAmbient
  112.         game.Lighting.ShadowColor = stages[currentStage].Lighting.ShadowCol
  113.         game.Lighting.GeographicLatitude = stages[currentStage].Lighting.GeoLat
  114.         game.Lighting.TimeOfDay = stages[currentStage].Lighting.ToD
  115.         game.Lighting.FogColor = stages[currentStage].Lighting.FogCol
  116.         game.Lighting.FogStart = stages[currentStage].Lighting.FogStart
  117.         game.Lighting.FogEnd = stages[currentStage].Lighting.FogEnd
  118. end
  119.  
  120. function isGround(hit)
  121.     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
  122.         return true
  123.     else return false
  124.     end
  125. end
  126.  
  127. function plrGrounded()
  128.     local ray = Ray.new(plr.Position, Vector3.new(0, -10, 0))
  129.     local hit, position = game.Workspace:FindPartOnRay(ray, plr)
  130.     if  (position - plr.Position).magnitude <= 1.6  and isGround(hit) then return true else return false end
  131. end
  132.  
  133. function died()
  134.    
  135.     if dying ~= true then
  136.     dying = true
  137.     print("Death")
  138.     lives = (lives - 1)
  139.     script.Parent.UI.Lives.TextLabel.Text = lives
  140.     if lives <= 0 then
  141.         script.Parent.DeathScreen.Core.Visible = true
  142.         health.Value = _G.settings.plrMaxHealth
  143.         lives = _G.settings.plrDefaultLives
  144.     end
  145.     health.Value = _G.settings.plrMaxHealth
  146.     wait(.5)
  147.     dying = false  
  148.     end
  149. end
  150.  
  151.     --Coroutines--
  152. camUpd = coroutine.wrap(function()
  153.  
  154. cam.CameraType = Enum.CameraType.Scriptable
  155.  
  156. game:GetService("RunService").RenderStepped:connect(function()
  157.  
  158. cam.CoordinateFrame = CFrame.new(plr.Position + _G.settings.plrCamOffset)
  159.  
  160. end)
  161. end)
  162.  
  163. inp = coroutine.wrap(function()
  164. game:GetService("RunService").RenderStepped:connect(function() 
  165.     ip.InputBegan:connect(function(k,p)
  166.             ks[k.KeyCode] = true
  167.         end)
  168.        
  169.     ip.InputEnded:connect(function(k,p)
  170.             ks[k.KeyCode] = false
  171.         end)   
  172.     end)
  173. end)
  174.  
  175. plrControl = coroutine.wrap(function()
  176. game:GetService("RunService").RenderStepped:connect(function()
  177.  
  178. plr.CFrame = CFrame.new(plr.CFrame.x,plr.CFrame.y,0)*CFrame.Angles(0,0,math.rad(180))
  179. plr.Velocity = Vector3.new(plr.Velocity.x/1.25,plr.Velocity.y/1.05,0)
  180.  
  181. --[[if plr.Position.z ~= 0 then
  182.     plr.Position = Vector3.new(plr.Position.x,plr.Position.y,0)
  183. end]]--
  184.  
  185. --[[if ks[Enum.KeyCode.W] and ks[Enum.KeyCode.A] then
  186.        
  187. elseif ks[Enum.KeyCode.W] and ks[Enum.KeyCode.D] then
  188.  
  189. elseif ks[Enum.KeyCode.S] and ks[Enum.KeyCode.A] then
  190.        
  191. elseif ks[Enum.KeyCode.S] and ks[Enum.KeyCode.D] then]]--
  192.        
  193. if ks[Enum.KeyCode.W] then
  194.  
  195. elseif ks[Enum.KeyCode.S] then
  196.  
  197. elseif ks[Enum.KeyCode.A] then
  198.     plr.Velocity = Vector3.new(-25,plr.Velocity.y,0)
  199. elseif ks[Enum.KeyCode.D] then
  200.     plr.Velocity = Vector3.new(25,plr.Velocity.y,0)
  201. end
  202. if ks[Enum.KeyCode.Space] and jump ~= true then
  203.    
  204.     jump = true
  205.     if _G.settings.plrJmpTyp == 0 then
  206.     plr.Velocity = Vector3.new(plr.Velocity.x,50,0)
  207.     elseif _G.settings.plrJmpTyp == 1 then
  208.         for i=1, 10 do
  209.             plr.Velocity = Vector3.new(plr.Velocity.x,i*5,0)
  210.         end
  211.     end
  212.    
  213.     repeat wait(0.05) until plrGrounded() == true
  214.     plr.Velocity = Vector3.new(plr.Velocity.x,0,0)
  215.     jump = false
  216. end
  217. end)
  218. end)
  219.  
  220. bounds = coroutine.wrap(function()
  221.  
  222. lastPos = Vector3.new(0,0,0)
  223.  
  224. game:GetService("RunService").RenderStepped:connect(function()
  225. plr.TouchEnded:connect(function(hit)       
  226.         local lEdge = Vector2.new(hit.Position.x - hit.Size.x/2,hit.Position.y + hit.Size.y/2)
  227.         local rEdge = Vector2.new(hit.Position.x + hit.Size.x/2,hit.Position.y + hit.Size.y/2)
  228.        
  229.         if isGround(hit) == true then
  230.             if plr.Position.x < hit.Position.x then            
  231.                 lastPos = Vector3.new(lEdge.x + 0.5,lEdge.y)       
  232.             elseif plr.Position.x > hit.Position.x then
  233.                 lastPos = Vector3.new(rEdge.x - 0.5,rEdge.y)   
  234.             else plr.Position = hit.Position * Vector3.new(0,hit.Position.y + hit.Position.Size.y/2,0)         
  235.             end
  236.         end
  237. end)
  238.  
  239.     if plr.Position.y < stages[currentStage].Bounds.Min then       
  240.         plr.Position = lastPos
  241.         plr.Velocity = Vector3.new(0,-10,0)
  242.     end
  243.     if plr.Position.y > stages[currentStage].Bounds.Max then
  244.         plr.Position = lastPos
  245.         plr.Velocity = Vector3.new(0,-10,0)
  246.     end
  247. end)
  248. end)
  249.  
  250. danger = coroutine.wrap(function()
  251.  
  252. health.Changed:connect(function()
  253.         if health.Value > _G.settings.plrMaxHealth then
  254.             health.Value = _G.settings.plrMaxHealth
  255.         elseif health.Value <= 0 then
  256.             health.Value = 0
  257.             died()     
  258.         end
  259.    
  260.         script.Parent.UI.Health.HPCont.HP.Size = UDim2.new(health.Value/_G.settings.plrMaxHealth,0,1,0)
  261. end)
  262.  
  263. game:GetService("RunService").RenderStepped:connect(function()
  264.    
  265.     if bts.Value == true then
  266.         plr.Position = lastPos
  267.         plr.Velocity = Vector3.new(0,-10,0)
  268.         bts.Value = false
  269.     end
  270.     if dmg.Value == true then
  271.         --Flicker effect, no damage
  272.         wait(1)
  273.         dmg.Value = false
  274.     end
  275.        
  276. end)
  277. end)
  278.  
  279. --Run--
  280. wait(0.5)
  281. spawnPlr()
  282. camUpd()
  283. inp()
  284. plrControl()
  285. _G.createStage(1)
  286. bounds()
  287. danger()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement