Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (dump)
- local depth = 0
- local function tablelength(t)
- count=0
- for k, v in pairs(t) do
- count=count+1
- end
- return count
- end
- function dump2(o, i)
- depth=depth+1
- if depth==1 then i=true end
- if type(o) == 'table' then
- local s = "\n" .. string.rep(' ', depth-1) .. '{ \n'
- local count=0
- for k,v in pairs(o) do
- u=false
- count=count+1
- if count==tablelength(o) then u=true end
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. string.rep(' ', depth) .. '['..k..'] = ' .. dump2(v, u) .. '\n'
- end
- depth=depth-1
- l = s .. string.rep(' ', depth) .. '}'
- if not i then l=l..', ' end
- return l
- else
- depth=depth-1
- l=tostring(o)
- if not i then l=l..',' end
- return l
- end
- end
- function dump(...)
- print(dump2(...))
- end
- (class)
- Class={}
- function Class:new(args)
- o={}
- if self.init then o=self.init(o, args) end
- self.__index=self
- setmetatable(o, self)
- return o
- end
- function Class:destroy(args)
- if self.dest then self:dest(args) end
- self=nil
- end
- function Class:toTable(args)
- local t = {}
- for k, v in pairs(self) do
- t[k]=v
- end
- if self.totab then t=self.totab(t, args) end
- return t
- end
- function Class:getSuperclass()
- return getmetatable(self)
- end
- function Class:setSuperclass(t)
- setmetatable(self, t)
- end
- function Class:copy()
- local t = {}
- for k, v in pairs(self) do
- t[k]=v
- end
- setmetatable(t, getmetatable(self))
- return t
- end
- --]]
- function love.load()
- require('class')
- require('dump')
- print(love.getVersion())
- math.randomseed(os.time())
- Instance=Class:new()
- function Instance.init(o, args)
- local parent
- local children
- if args then
- if args.parent then parent=args.parent end
- if args.children then children=args.children else children= {} end
- if parent then if parent.init then o=parent.init(o, args) end end
- else
- children={}
- end
- local instance={['children']=children, ['parent']=parent}
- function o:getChildren()
- return instance.children
- end
- function o:getChild(name)
- if instance.children[name] then return instance.children[name] else error('Unknown Child') end
- end
- function o:getParent()
- if instance.parent then return instance.Parent end
- end
- function o:switchParent(parent)
- instance.parent = parent
- end
- function o:addChild(child)
- child:switchParent(self)
- end
- function o.dest()
- for k, v in pairs(instance.children) do
- v:Destroy()
- end
- end
- return o
- end
- Tile=Instance:new()
- function Tile.init(o, args)
- o=Instance.init(o, args)
- o.x=args.x
- o.y=args.y
- o.img=args.img
- o.quad=args.quad
- return o
- end
- Layer=Instance:new()
- Layers={}
- function distance(a, b)
- return math.sqrt(math.pow(math.abs(a.x-b.x), 2)+math.pow(math.abs(a.y-b.y), 2))
- end
- function genWorleyTable(width, height, numPoints)
- local grid={}
- local scaleGrid={}
- for x=1, width*3 do
- scaleGrid[x]={}
- for y=1, height*3 do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Creating Worley Table' percent=(((x-1)*height*3)+y)/(width*3*height*3) coroutine.yield() end
- scaleGrid[x][y]=0
- end
- end
- local pts={}
- local points={}
- for t=1, numPoints do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Creating Worley Table Points' percent=t/numPoints coroutine.yield() end
- table.insert(pts, {['x']=math.random(0, width-1), ['y']=math.random(0, height-1)})
- end
- for a=1, 3 do
- for b=1, 3 do
- for k, v in pairs(pts) do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Duplicating Worley Table Points' percent=(((a-1)*3*numPoints)+((b-1)*numPoints)+k)/(9*numPoints) coroutine.yield() end
- table.insert(points, {['x']=(a-1)*width+v.x, ['y']=(b-1)*height+v.y})
- end
- end
- end
- for k, v in pairs(scaleGrid) do
- for p, t in pairs(v) do
- local y=height*3*width*3
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Creating Worley Noise' percent=((k*#v)+p)/(#scaleGrid*#v) coroutine.yield() end
- for i, o in pairs(points) do
- y=math.min(y, distance(o, {['x']=k, ['y']=p}))
- end
- scaleGrid[k][p]=y
- end
- end
- for x=1, width do
- grid[x]={}
- for y=1, height do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Duplicating Worley Noise' percent=((x-1)*height)+y/width*height coroutine.yield() end
- grid[x][y]=scaleGrid[x+width][y+height]
- end
- end
- return grid, scaleGrid
- end
- function Layer.init(o, args)
- o=Instance.init(o, args)
- o.x=args.x
- o.y=args.y
- o.tx=args.tx
- o.ty=args.ty
- o.tiles={}
- for x=1, o.x do
- o.tiles[x]={}
- for y=1, o.y do
- o.tiles[x][y]=Tile:new({}, {['x']=o.tx, ['y']=o.ty})
- o:addChild(o.tiles[x][y])
- end
- end
- table.insert(Layers, o)
- return o
- end
- local success=love.window.setMode(0, 0, {fullscreen=true})
- cloudFile=love.graphics.newImage('clouds.png')
- platformFile=love.graphics.newImage('tileset.png')
- platformQuads={}
- pq=platformQuads
- cloudQuads={}
- cq=cloudQuads
- for x=1, 9 do
- for y=1, 9 do
- table.insert(platformQuads, love.graphics.newQuad((x-1)*16+x, (y-1)*16+y, 16, 16, platformFile:getDimensions()))
- end
- end
- for x=1, 9 do
- for y=1, 10 do
- table.insert(cloudQuads, love.graphics.newQuad((x-1)*16+x, (y-1)*16+y, 16, 16, cloudFile:getDimensions()))
- end
- end
- width, height = love.graphics.getDimensions()
- function cloudType(x, y, layer)
- local u, d, l, r, ul, ur, dl, dr
- if y~=1 then u=layer[x][y-1] else u=layer[x][math.ceil(height/16)] end
- if y~=math.ceil(height/16) then d=layer[x][y+1] else d=layer[x][1] end
- if x~=1 then l=layer[x-1][y] else l=layer[math.ceil(width/16)][y] end
- if x~=math.ceil(width/16) then r=layer[x+1][y] else r=layer[1][y] end
- if y ~= 1 then
- if x ~= 1 then
- ul=layer[x - 1][y - 1]
- else
- ul=layer[math.ceil(width / 16)][y - 1]
- end
- else
- if x ~= 1 then
- ul=layer[x - 1][math.ceil(height / 16)]
- else
- ul=layer[math.ceil(width / 16)][math.ceil(height / 16)]
- end
- end
- if y ~= math.ceil(height / 16) then
- if x ~= 1 then
- dl=layer[x - 1][y + 1]
- else
- dl=layer[math.ceil(width / 16)][y + 1]
- end
- else
- if x ~= 1 then
- dl=layer[x - 1][1]
- else
- dl=layer[math.ceil(width / 16)][1]
- end
- end
- if y ~= 1 then
- if x ~= math.ceil(width / 16) then
- ur=layer[x + 1][y - 1]
- else
- ur=layer[1][y - 1]
- end
- else
- if x ~= math.ceil(width / 16) then
- ur=layer[x + 1][math.ceil(height / 16)]
- else
- ur=layer[1][math.ceil(height / 16)]
- end
- end
- if y ~= math.ceil(height / 16) then
- if x ~= math.ceil(width / 16) then
- dr=layer[x + 1][y + 1]
- else
- dr=layer[1][y + 1]
- end
- else
- if x ~= math.ceil(width / 16) then
- dr=layer[x + 1][1]
- else
- dr=layer[1][1]
- end
- end
- return u, d, l, r, ul, ur, dl, dr
- end
- function CloudType(x, y, layer)
- local u, d, l, r, ul, ur, dl, dr = cloudType(x, y, layer)
- if not u and not l and not d and not r then
- return cq[81]
- else
- if u and not l and not d and not r then
- return cq[42]
- elseif not u and l and not d and not r then
- return cq[43]
- elseif not u and not l and d and not r then
- return cq[41]
- elseif not u and not l and not r and l then
- return cq[44]
- elseif u and l and not d and not r then
- if ul then
- local t=math.random(1, 4)
- if t==1 then return cq[12] elseif t==2 then return cq[16] elseif t==3 then return cq[32] else return cq[34] end
- else
- return cq[58]
- end
- elseif u and r and not d and not l then
- if ur then
- local t=math.random(1, 4)
- if t==1 then return cq[2] elseif t==2 then return cq[6] elseif t==3 then return cq[22] else return cq[24] end
- else
- return cq[59]
- end
- elseif d and l and not u and not r then
- if dl then
- local t=math.random(1, 4)
- if t==1 then return cq[11] elseif t==2 then return cq[15] elseif t==3 then return cq[31] else return cq[33] end
- else
- return cq[57]
- end
- elseif d and r and not u and not l then
- if dr then
- local t=math.random(1, 4)
- if t==1 then return cq[1] elseif t==2 then return cq[5] elseif t==3 then return cq[21] else return cq[23] end
- else
- return cq[60]
- end
- elseif u and d and not l and not r then
- local t=math.random(1, 2)
- if t==1 then return cq[46] else return cq[56] end
- elseif l and r and not u and not d then
- local t=math.random(1, 2)
- if t==1 then return cq[45] else return cq[55] end
- elseif l and r and u and not d then
- if not ul and not ur then
- return cq[61]
- elseif ul and not ur then
- return cq[65]
- elseif not ul and ur then
- return cq[63]
- else
- local t=math.random(1, 4)
- if t==1 then return cq[20] elseif t==2 then return cq[36] elseif t==3 then return cq[38] else return cq[40] end
- end
- elseif l and r and d and not u then
- if not dl and not dr then
- return cq[62]
- elseif dl and not dr then
- return cq[74]
- elseif not dl and dr then
- return cq[76]
- else
- local t=math.random(1, 4)
- if t==1 then return cq[9] elseif t==2 then return cq[25] elseif t==3 then return cq[27] else return cq[29] end
- end
- elseif u and d and l and not r then
- if not ul and not dl then
- return cq[71]
- elseif ul and not dl then
- return cq[64]
- elseif not ul and dl then
- return cq[66]
- else
- local t=math.random(1, 4)
- if t==1 then return cq[19] elseif t==2 then return cq[35] elseif t==3 then return cq[37] else return cq[39] end
- end
- elseif u and d and r and not l then
- if not ur and not dr then
- return cq[72]
- end
- if ur and not dr then
- return cq[75]
- end
- if not ur and dr then
- return cq[73]
- end
- if ur and dr then
- local t=math.random(1, 4)
- if t==1 then return cq[10] elseif t==2 then return cq[26] elseif t==3 then return cq[28] else return cq[30] end
- end
- elseif u and d and r and l then
- if not ur and not ul and not dl and not dr then
- local t=math.random(1, 4)
- if t==1 then return cq[67] elseif t==2 then return cq[68] elseif t==3 then return cq[77] else return cq[78] end
- elseif ur and not ul and not dr and not dl then
- return cq[52]
- elseif not ur and ul and not dr and not dl then
- return cq[51]
- elseif not ur and not ul and dr and not dl then
- return cq[53]
- elseif not ur and not ul and not dr and dl then
- return cq[54]
- elseif ur and ul and not dr and not dl then
- return cq[50]
- elseif ur and not ul and dr and not dl then
- return cq[49]
- elseif not ur and not ul and dr and dl then
- return cq[47]
- elseif not ur and ul and not dr and dl then
- return cq[48]
- elseif not ur and ul and dr and not dl then
- return cq[82]
- elseif ur and not ul and not dr and dl then
- return cq[83]
- elseif ur and ul and dr and not dl then
- return cq[8]
- elseif ur and ul and not dr and dl then
- return cq[18]
- elseif ur and not ul and dr and dl then
- return cq[7]
- elseif not ur and ul and dr and dl then
- return cq[17]
- elseif ur and ul and dr and dl then
- local t=math.random(1, 4)
- if t==1 then return cq[3] elseif t==2 then return cq[4] elseif t==3 then return cq[13] else return cq[14] end
- end
- end
- end
- return cq[81]
- end
- yoffset=0
- yoffset2=0
- xoffset=0
- xoffset2=0
- yspeed=(math.random()-0.5)*2
- xspeed=(math.random()-0.5)*2
- frame=1/60
- currtime=os.time()
- currtime2=os.clock()
- msg=''
- percent=0
- fps=0
- fps2=0
- firstCo=coroutine.create(function () Layer1=Layer:new({['x']=math.ceil(width/16), ['y']=math.ceil(height/16), ['tx']=16, ['ty']=16})
- for x, v in pairs(Layer1.tiles) do
- for y, t in pairs(v) do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Creating Background Tiles' percent=(((x-1)*#v)+y)/(#Layer1.tiles*#v) coroutine.yield() end
- t.img=cloudFile
- t.quad=cq[math.random(84, 90)]
- end
- end
- Layer2= Layer:new({ ['x'] = math.ceil(width / 16), ['y'] = math.ceil(height / 16), ['tx'] = 16, ['ty'] = 16 })
- Layer2b=genWorleyTable(math.ceil(width/16), math.ceil(height/16), (width/32*2+height/32*2))
- Layer2c={}
- for x, v in pairs(Layer2b) do
- Layer2c[x]={}
- for y, t in pairs(v) do
- Layer2.tiles[x][y].img=cloudFile
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Creating Boolean Table from Worley Noise' percent=(((x-1)*#v)+y)/(#Layer2b*#v) coroutine.yield() end
- if t>5 then
- if t==6 then
- if math.random(1, 10)==1 then Layer2c[x][y]=true
- else Layer2c[x][y]=false end
- else Layer2c[x][y]=false end
- else Layer2c[x][y]=true end
- end
- end
- for x, v in pairs(Layer2b) do
- for y, t in pairs(v) do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Smoothing Clouds' percent=(((x-1)*#v)+y)/(#Layer2b*#v) coroutine.yield() end
- if Layer2c[x][y] then Layer2.tiles[x][y].quad=CloudType(x, y, Layer2c) else Layer2.tiles[x][y].quad=cq[81] end
- end
- end
- --[[
- Layer3=Layer:new({ ['x'] = math.ceil(width / 16)*3, ['y'] = math.ceil(height / 16)*3, ['tx'] = 16, ['ty'] = 16 })
- for x=1, 3 do
- for y=1, 3 do
- for x1=1, math.ceil(width/16) do
- for y1=1, math.ceil(height/16) do
- if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Duplicating Cloud Table' percent=(((x-1)*3*math.ceil(width/16)*math.ceil(height/16))+((y-1)*math.ceil(width/16)*math.ceil(height/16))+((x1-1)*math.ceil(height/16))+y1)/(9*math.ceil(width/16)*math.ceil(height/16)) coroutine.yield() end
- Layer3.tiles[x1+math.ceil(width/16)*(x-1)][y1+math.ceil(height/16)*(y-1)]=Layer2.tiles[x1][y1]
- end
- end
- end
- end
- --]]
- --[[
- Layer4=Layer:new({ ['x'] = math.ceil(width / 16)*3^2, ['y'] = math.ceil(height / 16)*3^2, ['tx'] = 16, ['ty'] = 16 })
- for x=1, 3 do
- for y=1, 3 do
- for x1=1, math.ceil(width/16)*3 do
- for y1=1, math.ceil(height/16)*3 do
- Layer4.tiles[x1+math.ceil(width/16)*(x-1)*3][y1+math.ceil(height/16)*3*(y-1)]=Layer3.tiles[x1][y1]
- end
- end
- end
- end
- ]]--
- love.graphics.setColor(1, 1, 1, 1)
- skyCanvas=love.graphics.newCanvas()
- love.graphics.setCanvas(skyCanvas)
- love.graphics.clear()
- love.graphics.setBlendMode("alpha")
- for k, v in pairs(Layers) do
- if k~=2 and k~=3 and k~=4 then
- if type(v)~='function' then
- for u, x in pairs(v.tiles) do
- for i, y in pairs(x) do
- --if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Generating Sky Picture' percent=(((u-1)*#x)+i)/(#v.tiles*#x) coroutine.yield() end
- love.graphics.setCanvas(skyCanvas)
- love.graphics.setColor(1, 1, 1, 1)
- love.graphics.draw(y.img, y.quad, v.tx*(u-1), v.ty*(i-1))
- end
- end
- end
- end
- end
- coroutine.yield()
- love.graphics.setColor(1, 1, 1, 1)
- cloudCanvas=love.graphics.newCanvas()
- love.graphics.setCanvas(cloudCanvas)
- love.graphics.clear()
- love.graphics.setBlendMode("alpha")
- for u, x in pairs(Layer2.tiles) do
- for i, y in pairs(x) do
- --if os.clock()>=currtime2+frame then currtime2=os.clock() msg='Generating Cloud Picture' percent=(((u-1)*#x)+i)/(#Layer3.tiles*#x) coroutine.yield() end
- love.graphics.setCanvas(cloudCanvas)
- love.graphics.setColor(1, 1, 1, 1)
- love.graphics.draw(y.img, y.quad, Layer2.tx*(u-1), Layer2.ty*(i-1))
- end
- end
- coroutine.yield()
- love.graphics.setCanvas()
- t=cloudCanvas:newImageData()
- cloudCanvas2=love.graphics.newImage(t)
- print('finally finshed', t, cloudCanvas2)
- coroutine.yield('finished')
- end)
- end
- function love.update()
- if coroutine.status(firstCo)=='suspended' or coroutine.status(firstCo)=='running' then
- coroutine.resume(firstCo)
- else
- yoffset=yoffset+yspeed
- yoffset=yoffset+yspeed*2
- xoffset=xoffset+xspeed
- xoffset2=xoffset2+xspeed*2
- if yoffset>height then yoffset=yoffset-height end
- if yoffset<-height then yoffset=yoffset+height end
- if xoffset>width then xoffset=xoffset-width end
- if xoffset<-width then xoffset=xoffset+width end
- if yoffset2>height then yoffset2=yoffset2-height end
- if yoffset2<-height then yoffset2=yoffset2+height end
- if xoffset2>width then xoffset2=xoffset2-width end
- if xoffset2<-width then xoffset2=xoffset2+width end
- end
- end
- function love.draw()
- love.graphics.setCanvas()
- if coroutine.status(firstCo)=='suspended' or coroutine.status(firstCo)=='running' then
- love.graphics.setCanvas()
- love.graphics.print(msg..' ' .. percent*100 .. '%')
- love.graphics.setColor(1, 1, 1, 1)
- else
- --[[ PARALAX MAPPING [HIGHLY LAGGY]
- for u, x in pairs(Layer4.tiles) do
- for i, y in pairs(x) do
- love.graphics.draw(y.img,
- y.quad,
- Layer4.tx/2*(u-math.ceil(width/8) -1)+xoffset2,
- Layer4.ty/2*(i-math.ceil(height/8)-1)+yoffset2, 0, 0.5, 0.5)
- end
- end
- ]]--
- love.graphics.setColor(1, 1, 1, 1)
- love.graphics.setCanvas()
- love.graphics.setBlendMode('alpha')
- love.graphics.draw(skyCanvas)
- love.graphics.draw(cloudCanvas, width/2, height/2)
- love.graphics.draw(cloudCanvas2, -width/2, -height/2)
- --[[
- love.graphics.draw(cloudCanvas2, xoffset, yoffset)
- love.graphics.draw(cloudCanvas2, xoffset, yoffset+height)
- love.graphics.draw(cloudCanvas2, xoffset, yoffset-height)
- love.graphics.draw(cloudCanvas2, xoffset+width, yoffset)
- love.graphics.draw(cloudCanvas2, xoffset+width, yoffset+height)
- love.graphics.draw(cloudCanvas2, xoffset+width, yoffset-height)
- love.graphics.draw(cloudCanvas2, xoffset-width, yoffset)
- love.graphics.draw(cloudCanvas2, xoffset-width, yoffset+height)
- love.graphics.draw(cloudCanvas2, xoffset-width, yoffset-height)
- --]]
- if currtime==os.time() then fps=fps+1 else fps2=fps fps=0 currtime=os.time() end
- love.graphics.setBlendMode('alpha')
- love.graphics.setColor(1, 0, 0, 1)
- love.graphics.print('FPS '..fps2)
- love.graphics.setColor(1, 1, 1, 1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement