summaryrefslogtreecommitdiffhomepage
path: root/not/Cloud.lua
blob: 25169c0ed9586ffae3e862135c71044a14d1698a (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
require "not.Decoration"

--- `Cloud`
-- That white thing moving in the background.
-- TODO: extends variables names to be readable.
Cloud = Decoration:extends()
Cloud.t = 1  -- type (sprite number)
Cloud.v = 13 -- velocity

-- TODO: allow maps to use other quads and sprites for clouds
-- TODO: you know this isn't right, don't you?
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
	}
}

-- Constructor of `Cloud`.
function Cloud:new (x, y, t, v, world)
	if self:getImage() == nil then
		self:setImage(Sprite.newImage("assets/clouds.png"))
	end
	Cloud.__super.new(self, x, y, world, nil)
	self:setAnimationsList(animations)
	self:setVelocity(v)
	self:setType(t)
end

-- Setters for cloud type and velocity.
function Cloud:setType (type)
	local animation = "default"
	if type > 1 then
		animation = animation .. type
	end
	self:setAnimation(animation)
	self.t = type
end
function Cloud:setVelocity (velocity)
	self.v = velocity
end

-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner.
function Cloud:update (dt)
	Cloud.__super.update(self, dt)
	self.x = self.x + self.v*dt
	return self.x
end

return Cloud