Code: Select all
HC = require 'hardoncollider'
function on_collide_2(dt, shape_a, shape_b)
local other
if shape_a == player_1 then
other = shape_b
elseif shape_b == player_1 then
other = shape_a
else
return
end
if other == ground then
on_ground = true
print("JLKSFJ")
end
end
function on_collide(dt, shape_a, shape_b)
local other
if shape_a == player_2 then
other = shape_b
elseif shape_b == player_2 then
other = shape_a
else -- no shape is the ball. exit
return
end
if other == ground then
on_ground_2 = true
-- print("JLKSFJ")
end
end
function love.load()
Collider = HC(100, on_collide, on_collide_2)
grav = 0
grav_2 = 0
on_ground = false
on_ground_2 = false
player_1 = Collider:addRectangle(500, 251, 20, 100)
player_2 = Collider:addRectangle(770, 250, 20, 100)
ground = Collider:addRectangle(20, 400, 800, 100)
end
function love.update(dt)
Collider:update(dt)
if on_ground == false then
grav = (9.8 * dt^2)*500
else
grav = 0
end
if on_ground_2 == false then
grav_2 = (9.8 * dt^2)*500
else
grav_2 = 0
end
player_1:move(0, grav)
player_2:move(0, grav_2)
end
function love.draw()
player_1:draw('fill')
player_2:draw('fill')
end