diff options
Diffstat (limited to 'cloud.lua')
-rw-r--r-- | cloud.lua | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -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 |