I don't know what I'm doing wrong, but Hardon Collider is not detecting collision. Well, in other words, I'm not using it correctly, even though I just read this and this.
Code: Select all
lick = require "lick"
lick.reset = true
HC = require "HardonCollider"
TILE_SIZE = 25
MAP_WIDTH = 26
MAP_HEIGHT = 24
N_MAPS = 1
function love.load()
-- Load all map images
map_loader = require("AdvTiledLoader.Loader")
map_loader.path = "maps/"
maps = {}
for i = 1, N_MAPS do
maps[i] = map_loader.load("map" .. i .. ".tmx")
end
-- Set up the collider
collider = HC(100, on_collide)
player_rect = collider:addRectangle(400, 400, TILE_SIZE, TILE_SIZE)
solid_tiles = get_solid_tiles(maps[1])
end
function love.update(dt)
player_rect:moveTo(love.mouse.getPosition())
collider:update(dt)
end
function love.draw()
love.graphics.push()
love.graphics.translate(250, 0)
maps[1]:draw()
love.graphics.pop()
--love.graphics.rectangle("fill", player.x, player.y, TILE_SIZE, TILE_SIZE)
player_rect:draw("fill")
end
function on_collide(dt, shape_a, shape_b, mtv_x, mtv_y)
print("Hey")
end
function get_solid_tiles(map)
local collidable_tiles = {}
local layer = map.tl["ground"]
for tileX = 1, map.width do
for tileY = 1, map.height do
local tile
if layer.tileData[tileY] then
tile = map.tiles[layer.tileData[tileY][tileX]]
end
if tile and tile.properties.solid then
local ctile = collider:addRectangle((tileX - 1) * 16, (tileY - 1) * 16, 16, 16)
ctile.type = "tile"
collider:addToGroup("tiles", ctile)
collider:setPassive(ctile)
table.insert(collidable_tiles, ctile)
end
end
end
return collidable_tiles
end
Immediately, I figured out the issue had to be the solid tiles. So, I printed out #solid_tiles, and got 0.
My tileset has the property "solid" and the layer is called "ground", so everything should be working fine.
Any idea of what I missed? Thank you. (Also, the map is being drawn correctly, and I am making it so that the player hits the gray tiles).