summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
Diffstat (limited to 'not')
-rw-r--r--not/CloudGenerator.lua13
-rw-r--r--not/World.lua4
2 files changed, 10 insertions, 7 deletions
diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua
index 3285938..e9d8ed7 100644
--- a/not/CloudGenerator.lua
+++ b/not/CloudGenerator.lua
@@ -4,16 +4,16 @@ CloudGenerator = require "not.Object":extends()
require "not.Cloud"
--- TODO: Allow map config to modify cloud styles: maximum cloud count, animations and atlas.
-function CloudGenerator:new (atlas, animations, world)
+function CloudGenerator:new (atlas, animations, count, world)
self.world = world
self.atlas = atlas
self.quads = animations
- self.count = 18
+ self.count = count
self.interval = 6
self.timer = 0
end
+-- TODO: This was a bad idea. Move Cloud creation back to World, pass created Cloud here for configuration.
function CloudGenerator:createCloud (x, y, style)
local cloud = Cloud(x, y, self.world, self.atlas)
cloud:setAnimationsList(self.quads)
@@ -46,7 +46,7 @@ function CloudGenerator:getRandomStyle ()
end
function CloudGenerator:run (count, inside)
- local count = count or 1
+ count = count or 1
for i=1,count do
local x, y = self:getRandomPosition(inside)
local style = self:getRandomStyle()
@@ -56,10 +56,11 @@ end
function CloudGenerator:update (dt)
local count = self.world:getCloudsCount()
- self.timer = self.timer - dt
- if self.timer < 0 then
+ if self.timer < 0 and self.count > count then
self.timer = self.timer + self.interval
self:run()
+ else
+ self.timer = self.timer - dt
end
end
diff --git a/not/World.lua b/not/World.lua
index e0febb7..853d75b 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -101,7 +101,9 @@ function World:buildMap ()
if type(animations) == "string" then
animations = require("config.animations." .. animations)
end
- self:insertEntity(CloudGenerator(op.clouds, animations, self)):run(6, true)
+ local cg = CloudGenerator(op.clouds, animations, op.count, self)
+ self:insertEntity(cg)
+ cg:run(op.count, true)
end
end
end