i can load in a map (draw it, update it, the whole thing) and i can collide my player with predefined rectangles with bump, but i'm not sure how to go about combining the two.
beginning of main.lua (i'll update this post with the .love file if it's requested). sorry for the messy code!
Code: Select all
local bump = require 'libs/bump'
local sti = require 'libs/sti'
require 'player'
local world = bump.newWorld(32) --new world with 32x32 tiles
local block = {name = "block", --this is the predefined rectangle i was talking about
x = 64,
y = 64,
w = 128,
h = 128
}
function love.load()
map = sti.new('maps/map1')
collision = map:getCollisionMap("solids") --the collision map i would like to collide with
player_load()
world:add(p, p.x, p.y, p.w, p.h) --player hitbox and stuff
world:add(block, block.x, block.y, block.w, block.h) --adding in the rectangle's hitbox
end
Code: Select all
if p.dx ~= 0 or p.dy ~= 0 then
local future_l, future_t = p.x + p.dx, p.y + p.dy
local cols, len = world:check(p, future_l, future_t)
if len == 0 then
p.x, p.y = future_l, future_t
world:move(p, future_l, future_t)
else
local col, tl, tt, sl, st
while len > 0 do
col = cols[1]
if col.other.name == "block" then
tl,tt,_,_,sl,st = col:getSlide()
p.x, p.y = tl, tt
world:move(p, tl, tt)
cols, len = world:check(p, sl, st)
end
if len == 0 then
p.x, p.y = sl, st
world:move(p, sl, st)
end
end
end
end