summaryrefslogtreecommitdiffhomepage
path: root/not/Cloud.lua
blob: 3bc5377a3684173b8980cfca9276c7dbb41e1fef (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
--- `Cloud`
-- That white thing moving in the background.
-- TODO: extends variables names to be readable.
Cloud = {
	t = 1,  -- type (sprite number)
	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
	}
}

-- `Cloud` is a child of `Decoration`.
require "not.Decoration"
Cloud.__index = Cloud
setmetatable(Cloud, Decoration)

-- Constructor of `Cloud`.
function Cloud:new (x, y, t, v)
	local o = setmetatable({}, self)
	o:init(x, y, t, v)
	-- Load spritesheet statically.
	if self:getImage() == nil then
		self:setImage(Sprite.newImage("assets/clouds.png"))
	end
	return o
end

-- Initializer of `Cloud`.
function Cloud:init (x, y, t, v)
	Decoration.init(self, x, y, 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)
	Decoration.update(self, dt)
	self.x = self.x + self.v*dt
	return self.x
end