summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-05 20:05:45 +0200
committerAki <nthirtyone@gmail.com>2017-09-05 20:05:45 +0200
commitda2c0d100a0b55e627ecdf5eaf5b8af78dd97c1c (patch)
tree13f559025d2bda88a9ee55f88a72c10443810bae
parent463f23bfd4510c95d2290fe0aa5b0ea2998d5786 (diff)
downloadroflnauts-da2c0d100a0b55e627ecdf5eaf5b8af78dd97c1c.zip
roflnauts-da2c0d100a0b55e627ecdf5eaf5b8af78dd97c1c.tar.gz
roflnauts-da2c0d100a0b55e627ecdf5eaf5b8af78dd97c1c.tar.bz2
Fresh take on cloud-related random methods
-rw-r--r--not/CloudGenerator.lua32
1 files changed, 24 insertions, 8 deletions
diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua
index a26cc77..404be1b 100644
--- a/not/CloudGenerator.lua
+++ b/not/CloudGenerator.lua
@@ -4,7 +4,6 @@ CloudGenerator = require "not.Object":extends()
require "not.Cloud"
--- TODO: Allow map config to modify cloud styles.
local animations = {
default = {
[1] = love.graphics.newQuad( 1, 1, 158,47, 478,49),
@@ -23,27 +22,33 @@ local animations = {
}
}
+-- TODO: Allow map config to modify cloud styles: maximum cloud count, animations and atlas.
function CloudGenerator:new (world)
self.world = world
self.atlas = "assets/clouds.png"
self.quads = animations
+ self.count = 18
end
-function CloudGenerator:createCloud (x, y)
+function CloudGenerator:createCloud (x, y, style)
local cloud = Cloud(x, y, self.world, self.atlas)
cloud:setAnimationsList(self.quads)
+ cloud:setAnimation(style)
cloud:setVelocity(13, 0)
cloud:setBoundary(340, 320)
return cloud
end
+function CloudGenerator:getRandomPosition (inside)
+ return 20, 20
+end
+
+function CloudGenerator:getRandomStyle ()
+ return "default"
+end
+
+--[[
function CloudGenerator:randomize (outside)
- if outside == nil then
- outside = true
- else
- outside = outside
- end
- local x,y,t,v
local m = self.map
if outside then
x = m.center.x-m.width*1.2+love.math.random(-50,20)
@@ -54,9 +59,20 @@ function CloudGenerator:randomize (outside)
t = love.math.random(1,3)
v = love.math.random(8,18)
end
+]]
+
+function CloudGenerator:run (count, inside)
+ local count = count or 1
+ for i=1,count then
+ local x, y = self:getRandomPosition(inside)
+ local style = self:getRandomStyle()
+ self.world:insertCloud(self:createCloud(x, y, style))
+ end
+end
function CloudGenerator:update (dt)
local count = self.world:getCloudsCount()
+ self:run()
end
return CloudGenerator