gdritter repos animaltransiro / 85c6313
Refine movement strategies Getty Ritter 6 years ago
1 changed file(s) with 14 addition(s) and 5 deletion(s). Collapse all Expand all
2525 function love.load()
2626 end
2727
28 function check_collision()
29 local bx = math.floor((state.char.x + state.char.dx) / consts.tileSize)
30 local by = math.floor((state.char.y + state.char.dy) / consts.tileSize)
28 function check_collision(thing, dx, dy)
29 local bx = math.floor((thing.x + dx) / consts.tileSize)
30 local by = math.floor((thing.y + dy) / consts.tileSize)
3131 return state.board:lookup(bx, by).pass and
3232 state.board:lookup(bx + 1, by).pass and
3333 state.board:lookup(bx, by + 1).pass and
3535 end
3636
3737 function love.update()
38 local movement = true
3839 state.t = (state.t + 1) % 10
39 if check_collision() then
40 if check_collision(state.char, state.char.dx, state.char.dy) then
41 state.char.x = state.char.x + state.char.dx
4042 state.char.y = state.char.y + state.char.dy
43 elseif check_collision(state.char, state.char.dx, 0) then
4144 state.char.x = state.char.x + state.char.dx
45 elseif check_collision(state.char, 0, state.char.dy) then
46 state.char.y = state.char.y + state.char.dy
47 else
48 movement = false
49 end
4250
43 if state.char.dx ~= 0 and state.char.dx ~= 0 then
51 if movement then
52 if state.char.dx ~= 0 and state.char.dy ~= 0 then
4453 -- nothing
4554 elseif state.char.dy ~= 0 then
4655 local xm = state.char.x % 10