summaryrefslogtreecommitdiffhomepage
path: root/ground.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-01-20 13:09:32 +0100
committerAki <nthirtyone@gmail.com>2017-01-20 13:09:32 +0100
commit4d3ccfdd00bdbcd144dd8d283e1d0d4e150bd9f1 (patch)
tree8b12f6f6ea6d1b6bf3261c4f7b8dd8b3b9657079 /ground.lua
parent29a527f4dbfeae138b71ce2dd8a82aa40560c522 (diff)
downloadroflnauts-4d3ccfdd00bdbcd144dd8d283e1d0d4e150bd9f1.zip
roflnauts-4d3ccfdd00bdbcd144dd8d283e1d0d4e150bd9f1.tar.gz
roflnauts-4d3ccfdd00bdbcd144dd8d283e1d0d4e150bd9f1.tar.bz2
Metatable of Animated for Decoration and Ground
Diffstat (limited to 'ground.lua')
-rw-r--r--ground.lua17
1 files changed, 6 insertions, 11 deletions
diff --git a/ground.lua b/ground.lua
index cd2b607..50ded4f 100644
--- a/ground.lua
+++ b/ground.lua
@@ -3,6 +3,7 @@
-- Collision category: [1]
-- WHOLE CODE HAS FLAG OF "need a cleanup"
+require "animated"
-- Metatable of `Ground`
-- nils initialized in constructor
@@ -11,13 +12,14 @@ Ground = {
shape = nil,
fixture = nil,
world = nil,
- sprite = nil
}
+Ground.__index = Ground
+setmetatable(Ground, Animated)
+
-- Constructor of `Ground`
function Ground:new (game, world, x, y, shape, sprite)
local o = {}
setmetatable(o, self)
- self.__index = self
o.body = love.physics.newBody(world, x, y)
-- MULTIPLE SHAPES NEED TO BE REWRITED!
o.shape = {}
@@ -37,17 +39,11 @@ function Ground:new (game, world, x, y, shape, sprite)
end
end
-- END HERE
- o.sprite = love.graphics.newImage(sprite)
+ o:setSprite(love.graphics.newImage(sprite))
o.world = game
return o
end
--- Destructor of `Ground`
-function Ground:delete ()
- -- body deletion is handled by world deletion
- self.sprite = nil
-end
-
-- Position
function Ground:getPosition()
return self.body:getPosition()
@@ -65,8 +61,7 @@ function Ground:draw (offset_x, offset_y, scale, debug)
local draw_x = (math.floor(x) + offset_x) * scale
local draw_y = (math.floor(y) + offset_y) * scale
-- sprite draw
- love.graphics.setColor(255,255,255,255)
- love.graphics.draw(self.sprite, draw_x, draw_y, 0, scale, scale)
+ Animated.draw(self, draw_x, draw_y, 0, scale, scale)
-- debug draw
if debug then
love.graphics.setColor(255, 69, 0, 140)