summaryrefslogtreecommitdiffhomepage
path: root/not/Cloud.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-05 18:32:34 +0200
committerAki <nthirtyone@gmail.com>2017-09-05 18:32:34 +0200
commitdc6fd557ed955fc5f177608c186768e29c7778c6 (patch)
treee20caaafef5a49108efc6f005652ee8dd532c701 /not/Cloud.lua
parent69eebe12baa0804cacf7285d1fdc20f42334dc27 (diff)
downloadroflnauts-dc6fd557ed955fc5f177608c186768e29c7778c6.zip
roflnauts-dc6fd557ed955fc5f177608c186768e29c7778c6.tar.gz
roflnauts-dc6fd557ed955fc5f177608c186768e29c7778c6.tar.bz2
Cloud clean-up, moving methods from World to CloudGenerator
Diffstat (limited to 'not/Cloud.lua')
-rw-r--r--not/Cloud.lua84
1 files changed, 34 insertions, 50 deletions
diff --git a/not/Cloud.lua b/not/Cloud.lua
index 25169c0..4851042 100644
--- a/not/Cloud.lua
+++ b/not/Cloud.lua
@@ -1,61 +1,45 @@
-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)
+-- 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
--- 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
+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:setVelocity (velocity)
- self.v = velocity
+
+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
--- Update of `Cloud`, returns x for world to delete cloud after reaching right corner.
+-- Cloud will get deleted if this function returns true.
function Cloud:update (dt)
Cloud.__super.update(self, dt)
- self.x = self.x + self.v*dt
- return self.x
+ self.x = self.x + self.velocity_x * dt
+ self.y = self.y + self.velocity_y * dt
+ return self:testPosition()
end
return Cloud