Codeblocks

Untitled

Aug 10th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. Script.maxBuildHeight = 100
  2. Script.minBuildHeight = 0
  3. Script.distancePerBlock = 0.5 --Example
  4. Script.minXRandom = -0.2 --Example
  5. Script.maxXRandom = 0.2 --Example
  6. Script.minYRandom = -0.2 --Example
  7. Script.maxYRandom = 0.2 --Example.
  8. Script.minZRandom = -0.1 --Example
  9. Script.maxZRandom = 0.1 --Example
  10. Script.totalBlocks = 50 --Example
  11. Script.FinishBlock=-1
  12.  
  13. function Script:Start()
  14.     --Create a light
  15.     local light = DirectionalLight:Create()
  16.     light:SetRotation(35,35,0)
  17.    
  18.     --creating table
  19.     self.blocks = {}
  20.     self.blockCount = 0 --Example (maybe this way it won't show up in the editor?)
  21.    
  22.     ----[[
  23.     --Create a player
  24.     self.camera = Camera:Create()
  25.     self.camera:SetFOV(70)
  26.     self.camera:SetRange(0.05,1000)
  27.     self.camera:SetPosition(0,0,0)
  28.     self.camera:SetScript("Scripts/Objects/Camera/SpectatorCam.lua")
  29.     --]]
  30.     --[[
  31.     --spawning the player
  32.     self.player = Pivot:Create()
  33.     self.player:SetMass(10)
  34.     self.healthbar = Pivot:Create()
  35.     self.healthbar:SetParent(self.player)
  36.     self.player:SetScript("Scripts/Objects/Player/LeadBlocksFps.lua")
  37.     --self.healthbar:SetScript("Scripts/Objects/Player/PlayerHealthBar.lua")
  38.  
  39.     --self.player:SetShape(shape)
  40.     self.player:SetPhysicsMode(Entity.CharacterPhysics)
  41.     math.randomseed(tostring(self:MakeRndSeed()))
  42.  
  43.     for n = 0, 15 do
  44.         num = math.random(9)
  45.         --System:Print(num)
  46.     end
  47.     ----]]
  48.     --create origin point box
  49.     model = Model:Box()
  50.    
  51.     local color = Context:GetCurrent():GetColor()
  52.                 color.r = 0.6
  53.                 color.g = 0.6
  54.                 color.b = 1
  55.        
  56.     for i=0 , (self.totalBlocks-1) do
  57.         local num = Vec3(math.random(self.minXRandom, self.maxXRandom),math.random(self.minYRandom,self.maxYRandom),math.random(self.minZRandom,self.maxZRandom)) --Careful! num was global here before, and wouldn't delete after the scope.
  58.         --System:Print(num.z.." <<")
  59.         --System:Print(math.random(9).." <<")
  60.         self:MakeBox(num.x,num.y,num.z,color)
  61.     end
  62.  
  63.     self.FinishBlock = self.blocks[self.totalBlocks]
  64.    
  65.     self.camera:SetPosition(self.blocks[1]:GetPosition(true))
  66.    
  67. end
  68.  
  69. function Script:MakeRndSeed()
  70.     local seed = 1
  71.     seed = Math:Random(1,9)
  72.     seed = seed*10000000*Time:GetCurrent()+Math:Random(0,400)
  73.     return Math:Round(seed)
  74. end
  75.  
  76. function Script:MakeBox(x, y, z, color)
  77.     local box = Model:Box()
  78.     local shape = Shape:Box()
  79.     box:SetShape(shape)
  80.     --if y > 99.0 then
  81.     --  color.r = 11
  82.         --System:Print(">> >> "..y)
  83.     --end
  84.     local newZ = (self.blockCount * self.distancePerBlock) + z --Example ( + z for that little bit of extra randomness)
  85.     box:SetPosition(x,y,newZ,true)
  86.     box:SetColor(color)
  87. --[[
  88.     if math.random(0,1) == 1 then
  89.         box:SetScript("floatupanddown/floating.lua")
  90.         box:SetColor(1,1,1)
  91.         box:SetKeyValue("box","floating")
  92.     end
  93. --]]
  94.     --put the block in tabledasdasdasdasd
  95.     self.blocks[self.blockCount+1] = box
  96.     self.blockCount = self.blockCount + 1
  97. end
  98.  
  99.  
  100. function Script:UpdatePhysics()
  101.     --end the level if player reched the end
  102.  
  103.     --if self.player:GetPosition(true).x >= self.FinishBlock:GetPosition(true).x then
  104.     if Window:GetCurrent():KeyHit(Key.E) then
  105.         changemapname = "start"
  106.     end
  107.  
  108. end
  109.  
  110. --[[
  111. --This can be used to select which objects an entity collides with.  This overrides collision types completely.
  112. function Script:Overlap(e)
  113.     return Collision:Collide
  114. end
  115. ]]
  116.  
  117. --[[
  118. function Script:Collision(entity, position, normal, speed)
  119.    
  120. end
  121. ]]
  122.  
  123. --[[
  124. function Script:Draw()
  125.    
  126. end
  127. ]]
  128.  
  129. --[[
  130. function Script:DrawEach(camera)
  131.    
  132. end
  133. ]]
  134.  
  135. --[[
  136. --This function will be called after the world is rendered, before the screen is refreshed.
  137. --Use this to perform any 2D drawing you want the entity to display.
  138. function Script:PostRender(context)
  139.    
  140. end
  141. ]]
  142.  
  143. --[[
  144. --This function will be called when the entity is deleted.
  145. function Script:Detach()
  146.    
  147. end
  148. ]]
  149.  
  150. --[[
  151. --This function will be called when the last instance of this script is deleted.
  152. function Script:Cleanup()
  153.    
  154. end
  155. ]]
Advertisement
Add Comment
Please, Sign In to add comment