basic stuff w movemet n collision done
This commit is contained in:
parent
bffa27ec01
commit
662de9407a
4 changed files with 30 additions and 18 deletions
18
entity.lua
18
entity.lua
|
|
@ -2,16 +2,16 @@ Entity = class("Entity")
|
|||
|
||||
function Entity:initialize(t)
|
||||
self.x, self.y = t.x, t.y
|
||||
self.gridSize = {x = t.sizeX, y = t.sizeY}
|
||||
self.size = {x = t.sizeX, y = t.sizeY}
|
||||
self.color = Color:new(t.color)
|
||||
self.collision = t.collision --either "none", "moveable", "unmoveable"
|
||||
self.collision = t.collision --"none", "moveable", "unmoveable"
|
||||
self.sprite = t.sprite
|
||||
self.shaAmount = t.sha or 1
|
||||
end
|
||||
|
||||
function Entity:atGridPos(x, y)
|
||||
if x >= self.x and x <= self.x + self.gridSize.x and
|
||||
y >= self.y and y <= self.gridSize.y then
|
||||
-- print(x, y, self.x, self.y, self.x + self.size.x, self.y + self.size.y)
|
||||
if x >= self.x and y >= self.y and x < self.x + self.size.y and y < self.y + self.size.y then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
|
@ -29,14 +29,20 @@ function Entity:getDrawPos()
|
|||
}
|
||||
end
|
||||
|
||||
function Entity:tick()
|
||||
|
||||
end
|
||||
|
||||
function Entity:draw()
|
||||
love.graphics.setColor(self.color:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(self.sprite, p.x + self:sha(), p.y + self:sha(), 0, drawScale, drawScale)
|
||||
end
|
||||
|
||||
function Entity:isAlignedWithPlayerMovement(axis, pos)
|
||||
if self:getGridPos()[axis] == pos then
|
||||
function Entity:isAlignedWithPlayerMovement(axis, pos, direction)
|
||||
-- print(axis, pos[axis], self:getGridPos()[axis], self:getGridPos()[axis] + self.size[axis])
|
||||
if self:getGridPos()[axis] <= pos[axis] and self:getGridPos()[axis] + self.size[axis] > pos[axis] then
|
||||
print("true!!")
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue