[Help] HardonCollider + Advanced Tiled Loader
Posted: Sun Sep 09, 2012 5:58 am
They aren't working together? I looked at the other problem but it's not close to my problem.
Any help?
Map Code.
Game Code.
Any help?
Code: Select all
maps = {}
local tx = 0
local ty = 0
local scale = 1
local loader = require "AdvTiledLoader.Loader"
loader.path = "Maps/"
solid = {}
local i = 0
local map = loader.load("btest.tmx")
function maps.load()
collider = HC(150, on_collide)
tileLayer = map.layers["Ground"]
love.graphics.setBackgroundColor(255,255,255)
for x, y, tile in map("Ground"):iterate() do
if tile and tile.properties.solid then
ctile = collider:addRectangle(x, y, 32, 32)
collider:addToGroup("tiles", ctile)
collider:setPassive(ctile)
solid[#solid+1] = {x=x, y=y, tile=tile}
i = i + 1
end
end
end
function maps.update(dt)
player = collider:addRectangle(x, y, 32, 32)
collider:update(dt)
end
function on_collide(dt, shape_a, shape_b)
x = 250
end
function maps.draw()
ftx, fty = math.floor(tx), math.floor(ty)
love.graphics.push()
love.graphics.scale(scale)
love.graphics.translate(ftx, fty)
map:autoDrawRange(tx, ty, scale, 50)
map:draw()
--map:setDrawRange(0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.pop()
end
Code: Select all
game = {}
local socket = require "socket"
local entity
local t
local updaterate = 0.1
x, y = 420, 240
local cobble = {}
function game.load()
udp = socket.udp()
udp:settimeout(0)
udp:setpeername(address, port)
entity = nickname
local dg = string.format("%s %s $", entity, 'joined')
udp:send(dg)
local dg = string.format("%s %s %d %d", entity, 'at', 420, 240)
udp:send(dg)
t = 0
love.graphics.setColor(255,255,255)
end
function on_collide(dt, shape_a, shape_b, mtv_x, mtv_y)
print("COLLIDED")
end
function game.update(dt)
collider = HC(100, on_collide)
t = t + dt
if love.keyboard.isDown('w') then y = y - ( 20 * dt ) end
if love.keyboard.isDown('s') then y = y + ( 20 * dt ) end
if love.keyboard.isDown('a') then x = x - ( 20 * dt ) end
if love.keyboard.isDown('d') then x = x + ( 20 * dt ) end
if love.keyboard.isDown('rctrl') then
for k, v in pairs(solid) do
print(k, v.x, v.y, v.tile)
end
end
if t > updaterate then
local dg = string.format("%s %s %f %f", entity, 'at', x, y)
udp:send(dg)
local dg = string.format("%s %s $", entity, 'update')
udp:send(dg)
t = t - updaterate
end
repeat
data, msg = udp:receive()
if data then
ent, cmd, parms = data:match("^(%S*) (%S*) (.*)")
if cmd == 'at' then
local x, y = parms:match("^(%-?[%d.e]*) (%-?[%d.e]*)$")
assert(x and y)
x, y = tonumber(x), tonumber(y)
world[ent] = {x=x, y=y}
else
print("Unknown Command: ", cmd)
end
elseif msg ~= 'timeout' then
alert.load()
gamestate = "alert"
alt = { msg = "Lost Connection", x = 1, y = 264, font = "Fonts/clubland.ttf", size = 72 }
end
until not data
end
function game.quit()
local dg = string.format("%s %s $", entity, 'left')
udp:send(dg)
end
function game.draw()
love.graphics.setColor(0,0,0)
for k,v in pairs(world) do
love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill", v.x, v.y, 32, 32)
end
end