fix renderer
This commit is contained in:
parent
3ceb07f4d1
commit
886679816b
3 changed files with 42 additions and 56 deletions
18
entity.lua
18
entity.lua
|
|
@ -2,13 +2,19 @@ Entity = class("Entity")
|
|||
|
||||
function Entity:initialize(t)
|
||||
self.x, self.y = t.x, t.y
|
||||
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
|
||||
-- sprites keyed by channel ("red"/"green"/"blue"). Single-color entities pass
|
||||
-- t.sprite + t.color and get one entry; multi-channel ones (doors) pass
|
||||
-- t.sprites directly. The renderer draws only the channels the player has, so
|
||||
-- no entity decides its own visibility (see Room:draw).
|
||||
self.sprites = t.sprites or { [t.color] = t.sprite }
|
||||
local repSprite = t.sprite or (t.sprites and select(2, next(t.sprites)))
|
||||
self.spriteSize = {w = repSprite:getWidth(), h = repSprite:getHeight()}
|
||||
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
|
||||
self.cellShape = t.cellShape or self:cellShapeFromBox(self.size)
|
||||
self.name = t.name
|
||||
self.color = Color:new(t.color)
|
||||
self.collision = t.collision --"none", "moveable", "unmoveable"
|
||||
self.sprite = t.sprite
|
||||
self.sprite = repSprite
|
||||
self.shaAmount = t.sha or 1
|
||||
self.onBump = t.onBump or function(self) return true end
|
||||
self.tick = t.tick or function(self) return true end
|
||||
|
|
@ -108,10 +114,12 @@ function Entity:tick()
|
|||
return self.tick()
|
||||
end
|
||||
|
||||
function Entity:draw()
|
||||
love.graphics.setColor(self.color:set())
|
||||
function Entity:draw(channel)
|
||||
local sprite = self.sprites[channel]
|
||||
if not sprite then return end
|
||||
love.graphics.setColor(gColor[channel]:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(self.sprite, p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||
love.graphics.draw(sprite, p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||
end
|
||||
|
||||
function Entity:canMove()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue