summaryrefslogtreecommitdiffhomepage
path: root/cloud.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-15 23:06:51 +0200
committerAki <nthirtyone@gmail.com>2016-05-15 23:06:51 +0200
commit32a4ebfa5a8af65bd763dfaeef0a0217e94cceeb (patch)
treebd50f40939a52ae320f109274ca389da57c34ee3 /cloud.lua
parentcc6312dbeaaa16bea9819e27e85b93a00b92c6e0 (diff)
downloadroflnauts-32a4ebfa5a8af65bd763dfaeef0a0217e94cceeb.zip
roflnauts-32a4ebfa5a8af65bd763dfaeef0a0217e94cceeb.tar.gz
roflnauts-32a4ebfa5a8af65bd763dfaeef0a0217e94cceeb.tar.bz2
Clouds :cloud: :cloud: :cloud:
Diffstat (limited to 'cloud.lua')
-rw-r--r--cloud.lua21
1 files changed, 12 insertions, 9 deletions
diff --git a/cloud.lua b/cloud.lua
index d745ba7..c039c95 100644
--- a/cloud.lua
+++ b/cloud.lua
@@ -5,19 +5,20 @@
-- Metatable of `Cloud`
Cloud = {
- x = 0,
- y = 0,
- t = 1, -- Type of the cloud (quad number)
+ x = 0, -- position horizontal
+ y = 0, -- position vertical
+ t = 1, -- type (sprite number)
+ v = 6, -- velocity
sprite = love.graphics.newImage("assets/clouds.png"),
quads = {
- [1] = love.graphics.newQuad( 1,159, 158,47, 480,49),
- [2] = love.graphics.newQuad(161,319, 158,47, 480,49),
- [3] = love.graphics.newQuad(321,479, 158,47, 480,49)
+ [1] = love.graphics.newQuad( 1, 1, 158,47, 480,49),
+ [2] = love.graphics.newQuad(161, 1, 158,47, 480,49),
+ [3] = love.graphics.newQuad(321, 1, 158,47, 480,49)
}
}
-- Constructor of `Cloud`
-function Cloud:new(x, y, t)
+function Cloud:new(x, y, t, v)
-- Meta
local o = {}
setmetatable(o, self)
@@ -26,12 +27,13 @@ function Cloud:new(x, y, t)
o.x = x or self.x
o.y = y or self.y
o.t = t or self.t
+ o.v = v or self.v
return o
end
-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner
function Cloud:update(dt)
- self.x = self.x + 5*dt
+ self.x = self.x + self.v*dt
return self.x
end
@@ -40,8 +42,9 @@ function Cloud:draw(offset_x, offset_y, scale)
-- defaults
local offset_x = offset_x or 0
local offset_y = offset_y or 0
+ local scale = scale or 1
local debug = debug or false
-- draw
love.graphics.setColor(255,255,255,255)
- love.graphics.draw(self.sprite, self.quads[t], (self.x+offset_x)*scale, (self.y+offset_y)*scale, 0, scale, scale)
+ love.graphics.draw(self.sprite, self.quads[self.t], (self.x+offset_x)*scale, (self.y+offset_y)*scale, 0, scale, scale)
end \ No newline at end of file