Do continuous keyboard-handling; calculate tile collision from center
Getty Ritter
7 years ago
29 | 29 |
for y = 0, consts.boardHeight - 1 do
|
30 | 30 |
-- if the character is in this space, draw it first
|
31 | 31 |
-- XXX: extend this to mobile entities in general
|
32 | |
local sX, sY = state.char:gameCoords()
|
| 32 |
local sX, sY = state.char:gameTopCoords()
|
33 | 33 |
if sX == x and sY == y then
|
34 | 34 |
state.char:draw()
|
35 | 35 |
end
|
51 | 51 |
end
|
52 | 52 |
|
53 | 53 |
function Entity:getFocus(board)
|
54 | |
local bx = math.floor(self.x / consts.tileSize)
|
55 | |
local by = math.floor(self.y / consts.tileSize)
|
| 54 |
local gx, gy = self:gameCoords()
|
56 | 55 |
|
57 | |
return board:lookupEntity(bx + self.direction[1],
|
58 | |
by + self.direction[2])
|
| 56 |
return board:lookupEntity(gx + self.direction[1],
|
| 57 |
gy + self.direction[2])
|
59 | 58 |
end
|
60 | 59 |
|
61 | 60 |
function Entity:move(board)
|
|
133 | 132 |
end
|
134 | 133 |
|
135 | 134 |
function Entity:gameCoords()
|
136 | |
return math.floor(self.x / consts.tileSize), math.floor(self.y / consts.tileSize)
|
| 135 |
return math.floor((self.x + consts.halfTile) / consts.tileSize),
|
| 136 |
math.floor((self.y + consts.halfTile) / consts.tileSize)
|
| 137 |
end
|
| 138 |
|
| 139 |
function Entity:gameTopCoords()
|
| 140 |
return math.floor(self.x / consts.tileSize),
|
| 141 |
math.floor(self.y / consts.tileSize)
|
137 | 142 |
end
|
138 | 143 |
|
139 | 144 |
return {
|
5 | 5 |
local event = require 'event'
|
6 | 6 |
local menu = require 'menu'
|
7 | 7 |
local draw = require 'draw'
|
| 8 |
|
8 | 9 |
local state = {
|
9 | 10 |
loadMap = function(self, name)
|
10 | 11 |
self.board = board.loadBoard(name)
|
11 | |
end
|
| 12 |
end,
|
| 13 |
keys = {},
|
12 | 14 |
}
|
13 | 15 |
|
14 | 16 |
local sprites = {}
|
|
39 | 41 |
|
40 | 42 |
function love.update()
|
41 | 43 |
state.t = state.t + 1
|
| 44 |
state.char.dx = 0
|
| 45 |
state.char.dy = 0
|
| 46 |
for key, enabled in pairs(state.keys) do
|
| 47 |
if enabled and event.keys.pressed[key] then
|
| 48 |
event.keys.pressed[key](state)
|
| 49 |
end
|
| 50 |
end
|
42 | 51 |
state.char:move()
|
43 | 52 |
end
|
44 | 53 |
|
|
51 | 60 |
if state.message then
|
52 | 61 |
state.message = nil
|
53 | 62 |
else
|
54 | |
return event.keys.pressed[key] and
|
55 | |
event.keys.pressed[key](state)
|
| 63 |
state.keys[key] = true
|
56 | 64 |
end
|
57 | 65 |
end
|
58 | 66 |
|
59 | 67 |
function love.keyreleased(key)
|
60 | |
return event.keys.released[key] and
|
61 | |
event.keys.released[key](state)
|
| 68 |
state.keys[key] = nil
|
62 | 69 |
end
|
63 | 70 |
|
64 | 71 |
function love.draw()
|