Created
October 26, 2014 06:07
-
-
Save tariqkhatib/eae25c51daf75e9fa7fc to your computer and use it in GitHub Desktop.
Simulate Space in less than 30 lines of Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
starCtr = 0 | |
stars = {} | |
currTransSpeed = 500 | |
displayHeight = display.contentHeight | |
math.randomseed( os.time() ) | |
local function removeMe() --remove stars after reaching end of screen | |
for i=1,1100 do | |
if stars[i] ~= nil then | |
if stars[i].y >= displayHeight then | |
display.remove( stars[i] ) | |
stars[i] = nil | |
end | |
end | |
end | |
if starCtr >= 1000 then | |
starCtr = 0 | |
end | |
end | |
local function loadSpace() -- create starts and move them | |
starCtr = starCtr + 1 | |
local currX = math.random( 1,display.contentWidth) | |
local currY = math.random( 1,display.contentHeight) | |
local currRadius = math.random( 1,2) | |
stars[starCtr] = display.newCircle( currX, currY, currRadius ) | |
transition.to( stars[starCtr], {y=display.contentHeight + currRadius,time = currTransSpeed,onComplete = removeMe} ) | |
end | |
local function startSpace() | |
timer.performWithDelay( 10, loadSpace , -1 ) | |
-- timer.performWithDelay( 5000, loadPlanet , -1 ) | |
end | |
startSpace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment