summaryrefslogtreecommitdiffhomepage
path: root/not/CloudGenerator.lua
blob: da5ddb29c7207156ad4b7e1554081b61dca3995f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--- Generates clouds over time with randomized positions and styles.
-- Also used as factory for Clouds.
CloudGenerator = require "not.Object":extends()

require "not.Cloud"

local animations = { 
	default = {
		[1] = love.graphics.newQuad(  1,  1, 158,47, 478,49),
		frames = 1,
		repeated = true
	},
	default2 = {
		[1] = love.graphics.newQuad(160,  1, 158,47, 478,49),
		frames = 1,
		repeated = true
	},
	default3 = {
		[1] = love.graphics.newQuad(319,  1, 158,47, 478,49),
		frames = 1,
		repeated = true
	}
}

-- 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, 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)
	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)
	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)
end
]]

function CloudGenerator:run (count, inside)
	local count = count or 1
	for i=1,count do
		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