From 0ef657d12d523f3805422bfc1cb840e1a481af03 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 02:28:52 +0200 Subject: Some actual functionality added to CloudGen --- not/CloudGenerator.lua | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index da5ddb2..fb1b617 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -28,6 +28,8 @@ function CloudGenerator:new (world) self.atlas = "assets/clouds.png" self.quads = animations self.count = 18 + self.interval = 6 + self.timer = 0 end function CloudGenerator:createCloud (x, y, style) @@ -39,27 +41,27 @@ function CloudGenerator:createCloud (x, y, style) return cloud end +-- TODO: CloudGen's randomization methods are too static (not configurable). function CloudGenerator:getRandomPosition (inside) - return 20, 20 + local x, y + local map = self.world.map + if not inside then + x = map.center.x - map.width*1.2 + love.math.random(-50, 20) + else + x = love.math.random(map.center.x - map.width / 2, map.center.x + map.width / 2) + end + y = love.math.random(map.center.y - map.height / 2, map.center.y + map.height / 2) + return x, y end function CloudGenerator:getRandomStyle () - return "default" -end - ---[[ -function CloudGenerator:randomize (outside) - local m = self.map - if outside then - x = m.center.x-m.width*1.2+love.math.random(-50,20) - else - x = love.math.random(m.center.x-m.width/2,m.center.x+m.width/2) + local num = love.math.random(1, 3) + local style = "default" + if num > 1 then + style = style .. tostring(num) end - y = love.math.random(m.center.y-m.height/2, m.center.y+m.height/2) - t = love.math.random(1,3) - v = love.math.random(8,18) + return style end -]] function CloudGenerator:run (count, inside) local count = count or 1 @@ -72,7 +74,11 @@ end function CloudGenerator:update (dt) local count = self.world:getCloudsCount() - self:run() + self.timer = self.timer - dt + if self.timer < 0 then + self.timer = self.timer + self.interval + self:run() + end end return CloudGenerator -- cgit v1.1