summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-01-20 12:29:40 +0100
committerAki <nthirtyone@gmail.com>2017-01-20 12:29:40 +0100
commit4b2f70d89a53ab03361a51cf970cede2e53cb3f6 (patch)
tree78db7802d2b343b889f8942d5e1aa9efc4e7cf8f
parentcc48afb0a20d01c8f4098c195239f2ca51fac495 (diff)
downloadroflnauts-4b2f70d89a53ab03361a51cf970cede2e53cb3f6.zip
roflnauts-4b2f70d89a53ab03361a51cf970cede2e53cb3f6.tar.gz
roflnauts-4b2f70d89a53ab03361a51cf970cede2e53cb3f6.tar.bz2
Clean-ups in Player-Animated relations
-rw-r--r--animated.lua12
-rw-r--r--player.lua11
2 files changed, 11 insertions, 12 deletions
diff --git a/animated.lua b/animated.lua
index 236b68d..49fcbfa 100644
--- a/animated.lua
+++ b/animated.lua
@@ -11,6 +11,11 @@ Animated = {
}
Animated.__index = Animated
+-- Cleans up reference to sprite on deletion.
+function Animated:delete()
+ self.sprite = nil
+end
+
-- Sets an Image as a sprite.
function Animated:setSprite(image)
self.sprite = image
@@ -38,9 +43,12 @@ end
-- Drawing self to LOVE2D buffer.
function Animated:draw(...)
- love.graphics.draw(self:getSprite(), self:getQuad(), ...)
+ local s, q = self:getSprite(), self:getQuad()
+ if s and q then
+ love.graphics.setColor(255,255,255,255)
+ love.graphics.draw(s, q, ...)
+ end
end
-
-- Animation updating.
function Animated:update(dt)
self.delay = self.delay - dt
diff --git a/player.lua b/player.lua
index 66eb818..b6d4e3f 100644
--- a/player.lua
+++ b/player.lua
@@ -52,7 +52,6 @@ function Player:new (game, world, x, y, name)
-- Meta
local o = {}
setmetatable(o, self)
- self.__index = self
-- Physics
local group = -1-#game.Nauts
o.body = love.physics.newBody(world, x, y, "dynamic")
@@ -79,12 +78,6 @@ function Player:new (game, world, x, y, name)
return o
end
--- Destructor of `Player`
-function Player:delete()
- -- body deletion is handled by world deletion
- self.sprite = nil
-end
-
-- Control set managment
function Player:assignControlSet(set)
self.controlset = set
@@ -303,9 +296,7 @@ function Player: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)
- Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15)
- --love.graphics.draw(self:getSprite(), self:getQuad(), draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15)
+ Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15)
-- debug draw
if debug then
for _,fixture in pairs(self.body:getFixtureList()) do