gdritter repos animaltransiro / f0c2586
Do continuous keyboard-handling; calculate tile collision from center Getty Ritter 6 years ago
3 changed file(s) with 23 addition(s) and 11 deletion(s). Collapse all Expand all
2929 for y = 0, consts.boardHeight - 1 do
3030 -- if the character is in this space, draw it first
3131 -- XXX: extend this to mobile entities in general
32 local sX, sY = state.char:gameCoords()
32 local sX, sY = state.char:gameTopCoords()
3333 if sX == x and sY == y then
3434 state.char:draw()
3535 end
5151 end
5252
5353 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()
5655
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])
5958 end
6059
6160 function Entity:move(board)
133132 end
134133
135134 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)
137142 end
138143
139144 return {
55 local event = require 'event'
66 local menu = require 'menu'
77 local draw = require 'draw'
8
89 local state = {
910 loadMap = function(self, name)
1011 self.board = board.loadBoard(name)
11 end
12 end,
13 keys = {},
1214 }
1315
1416 local sprites = {}
3941
4042 function love.update()
4143 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
4251 state.char:move()
4352 end
4453
5160 if state.message then
5261 state.message = nil
5362 else
54 return event.keys.pressed[key] and
55 event.keys.pressed[key](state)
63 state.keys[key] = true
5664 end
5765 end
5866
5967 function love.keyreleased(key)
60 return event.keys.released[key] and
61 event.keys.released[key](state)
68 state.keys[key] = nil
6269 end
6370
6471 function love.draw()