summaryrefslogtreecommitdiffhomepage
path: root/not/Cloud.lua
blob: 4851042f09aeebc1e5167a1cb057e5f4a08f5fd4 (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
--- `Cloud`
-- Moving decorations with limited lifespan.
Cloud = require "not.Decoration":extends()

function Cloud:new (x, y, world, imagePath)
	Cloud.__super.new(self, x, y, world, imagePath)
	self.velocity_x = 0
	self.velocity_y = 0
	self.boundary_x = 0
	self.boundary_y = 0
end

function Cloud:setVelocity (x, y)
	self.velocity_x = x
	self.velocity_y = y
end

function Cloud:setBoundary (x, y)
	self.boundary_x = x
	self.boundary_y = y
end

function Cloud:setStyle (style)
	self:setAnimation(style)
end

function Cloud:getStyle ()
	return self:getAnimation()
end

function Cloud:testPosition ()
	if self.x > self.boundary_x or self.y > self.boundary_y then
		return true
	end
end

-- Cloud will get deleted if this function returns true.
function Cloud:update (dt)
	Cloud.__super.update(self, dt)
	self.x = self.x + self.velocity_x * dt
	self.y = self.y + self.velocity_y * dt
	return self:testPosition()
end

return Cloud