gdritter repos animaltransiro / c831fbd
Change tile size + fix tile-aligned movement Getty Ritter 6 years ago
7 changed file(s) with 32 addition(s) and 12 deletion(s). Collapse all Expand all
11 return {
22 speed = 2,
3 tileSize = 20,
4 boardWidth = 39,
5 boardHeight = 29
3 tileSize = 24,
4 halfTile = 12,
5 quarterTile = 6,
6 boardWidth = 32,
7 boardHeight = 24,
68 }
1818 function Entity:checkCollision(dx, dy)
1919 local bx = math.floor((self.x + dx) / consts.tileSize)
2020 local by = math.floor((self.y + dy) / consts.tileSize)
21 local alignX = ((self.x + dx) % consts.tileSize) == 0
22 local alignY = ((self.y + dy) % consts.tileSize) == 0
2123
2224 local a = self.board:lookup(bx, by)
2325 local b = self.board:lookup(bx + 1, by)
2527 local d = self.board:lookup(bx + 1, by + 1)
2628
2729 if not (a and b and c and d) then return false end
28 return a.pass and b.pass and c.pass and d.pass
30
31 if alignX and alignY then
32 return a.pass
33 elseif alignX then
34 return a.pass and c.pass
35 elseif alignY then
36 return a.pass and b.pass
37 else
38 return a.pass and b.pass and c.pass and d.pass
39 end
40
2941 end
3042
3143 function Entity:move(board)
4658 -- nothing
4759
4860 elseif self.dy ~= 0 then
49 local xm = self.x % 10
50 if 0 < xm and xm < 5 and self:checkCollision(-1, 0) then
61 local xm = self.x % consts.halfTile
62 if 0 < xm and xm < consts.quarterTile and self:checkCollision(-1, 0) then
5163 self.x = self.x - 1
52 elseif xm >= 5 and self:checkCollision(1, 0) then
64 elseif xm >= consts.quarterTile and self:checkCollision(1, 0) then
5365 self.x = self.x + 1
5466 end
5567
5668 elseif self.dx ~= 0 then
57 local ym = self.y % 10
58 if 0 < ym and ym < 5 and self:checkCollision(0, -1) then
69 local ym = self.y % consts.halfTile
70 if 0 < ym and ym < consts.quarterTile and self:checkCollision(0, -1) then
5971 self.y = self.y - 1
60 elseif ym >= 5 and self:checkCollision(0, 1) then
72 elseif ym >= consts.quarterTile and self:checkCollision(0, 1) then
6173 self.y = self.y + 1
6274 end
6375 end
6476 end
77 print(self.x, self.y)
6578 end
6679
6780 function Entity:draw()
1010 function love.load()
1111 state.t = 0
1212 state.board = board.Board:new()
13 state.char = entity.Entity:new(state.board, 60, 60, tile.getTile('character'))
13 state.char = entity.Entity:new(state.board, 3 * 24, 3 * 24, tile.getTile('character'))
1414
1515 state.board:set(2, 3, tile.getTile('water'))
1616 state.board:set(2, 4, tile.getTile('water'))
4848 state.board:lookup(x, y):draw(x, y)
4949 end
5050 end
51
5152 state.char:draw()
5253 end
1 local consts = require 'constants'
2
13 local Tile = {}
24 Tile.__index = Tile
35
1416 end
1517
1618 function Tile:draw(x, y)
17 love.graphics.draw(self.sprite, x * 20, y * 20)
19 love.graphics.draw(self.sprite,
20 x * consts.tileSize,
21 y * consts.tileSize)
1822 end
1923
2024 function Tile:drawPx(x, y)
Binary diff not shown
Binary diff not shown
Binary diff not shown