main.lua
Code: Select all
require("cloudGen.lua")
cloudDraw = false
newcloud = 0
function love.load()
load_clouds()
island = love.graphics.newImage("SkyIsland.png",500,300)
tree = love.graphics.newImage("Tree.png",100,150)
bench = love.graphics.newImage("Bench.png",100,50)
end
function love.draw()
draw_clouds()
love.graphics.draw(island,100,200)
love.graphics.draw(tree,150,205)
love.graphics.setBackgroundColor(240, 248, 255)
end
function love.update()
newcloud = newcloud + 1
if newcloud >= 60 then
newcloud = 0
needCloud = true
end
end
Code: Select all
needCloud = false
clouds = {}
pendingClouds = {}
function load_clouds()
if needCloud == true then
needCloud = false
local cloud = love.graphics.newImage("Cloud.png",100,50)
local cloudTable = {}
table.insert(pendingClouds,cloudTable)
table.insert(cloudTable,cloud)
for i, v in pairs(pendingClouds) do
X = 500
Y = math.random(50,300)
table.insert(cloudTable,X)
table.insert(cloudTable,Y)
end
for i = 1,#pendingClouds do
table.insert(clouds,pendingClouds[i])
table.remove(pendingClouds,i)
end
end
end
function draw_clouds()
for i, v in pairs(clouds) do
love.draw(v.cloud,v.X,v.Y)--The "stack overflow" error says it's this line
v.X = v.X - 0.003
end
end