wowowowowowowo so much stuff
This commit is contained in:
parent
fe21cb61e3
commit
2f40eaf000
249 changed files with 391 additions and 20 deletions
25
entity.lua
25
entity.lua
|
|
@ -2,7 +2,8 @@ Entity = class("Entity")
|
|||
|
||||
function Entity:initialize(t)
|
||||
self.x, self.y = t.x, t.y
|
||||
self.size = {x = t.sizeX, y = t.sizeY}
|
||||
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
|
||||
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
|
||||
self.color = Color:new(t.color)
|
||||
self.collision = t.collision --"none", "moveable", "unmoveable"
|
||||
self.sprite = t.sprite
|
||||
|
|
@ -11,12 +12,18 @@ end
|
|||
|
||||
function Entity:atGridPos(x, y)
|
||||
-- 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
|
||||
local size = self:getGridSize()
|
||||
if x >= self.x and y >= self.y and x < self.x + size.x and y < self.y + size.y then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Entity:getDrawBox()
|
||||
local drawPos = self:getDrawPos()
|
||||
return {x = drawPos.x, y = drawPos.y, w = self.spriteSize.w * drawScale, h = self.spriteSize.h * drawScale}
|
||||
end
|
||||
|
||||
function Entity:getGridPos()
|
||||
return {x = self.x, y = self.y}
|
||||
end
|
||||
|
|
@ -24,11 +31,15 @@ end
|
|||
function Entity:getDrawPos()
|
||||
local gridPos = self:getGridPos()
|
||||
return {
|
||||
x = (gridPos.x - 1) * width / gridWidth,
|
||||
y = (gridPos.y - 1) * height / gridHeight
|
||||
x = (gridPos.x - 1) * width / gridWidth + self:sha(),
|
||||
y = (gridPos.y - 1) * height / gridHeight + self:sha()
|
||||
}
|
||||
end
|
||||
|
||||
function Entity:getGridSize()
|
||||
return {x = self.size.w, y = self.size.h}
|
||||
end
|
||||
|
||||
function Entity:tick()
|
||||
|
||||
end
|
||||
|
|
@ -36,12 +47,12 @@ 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)
|
||||
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
|
||||
end
|
||||
|
||||
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
|
||||
if self:getGridPos()[axis] <= pos[axis] and self:getGridPos()[axis] + self:getGridSize()[axis] > pos[axis] then
|
||||
print("true!!")
|
||||
return true
|
||||
end
|
||||
|
|
@ -62,5 +73,5 @@ end
|
|||
|
||||
|
||||
function Entity:sha()
|
||||
return math.random(-self.shaAmount, self.shaAmount) * .5
|
||||
return math.random(-worldSha, worldSha) * .5
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue