From ed16d208863944f64ce42298132597345cb749bb Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:37:07 +0200 Subject: Clouds are now counted, their number is limited and can be configured --- config/maps/default.lua | 3 ++- not/CloudGenerator.lua | 13 +++++++------ not/World.lua | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config/maps/default.lua b/config/maps/default.lua index 8bb5ebc..6acc577 100644 --- a/config/maps/default.lua +++ b/config/maps/default.lua @@ -15,7 +15,8 @@ return create = { { clouds = "assets/clouds.png", - animations = "clouds-default" + animations = "clouds-default", + count = 8 }, { ratio = 0, 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 -- cgit v1.1