Source code of my game https://github.com/AdrianN17/Jellystastic
The source of the problem is the detection of collisions in the love.update(dt) function, I use a lot of iterator for all of my actors
Also I edit the love.run function with this code: (sorry I forget the source thread)
Code: Select all
function love.run()
if love.math then
love.math.setRandomSeed(os.time())
end
if love.load then love.load(arg) end
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt = 0
-- Main loop time.
while true do
-- Process events.
local startT = love.timer.getTime()
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Update dt, as we'll be passing it to update
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
-- Call update and draw
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics and love.graphics.isActive() then
love.graphics.clear(love.graphics.getBackgroundColor())
love.graphics.origin()
if love.draw then love.draw() end
love.graphics.present()
end
if love.timer then
local endT = love.timer.getTime()
love.timer.sleep( 1/60 - (endT - startT))
end
end
Code: Select all
for _,col in pairs(base.entidades.colli) do
if col.l==base.entidades.l and col.ox>x and col.ox<x+h and col.oy>y and col.oy<y+w then
local dx,dy,colli=0,0,false
colli,dx,dy=base.entidades.player.body:collidesWith(col.body)--player pared
--base.entidades.player.ox
if col.type=="col" and colli then
if dy<0 and dx==0 then
base.entidades.player.ground=true
base.entidades.player.body:move(0,dy/2)
base.entidades.player.melee:move(0,dy/2)
base.entidades.player.point:move(0,dy/2)
base.entidades.player.vy=0
elseif dy>0 and dx==0 then
base.entidades.player.vy=base.entidades.player.vy/2
base.entidades.player.body:move(0,dy*1.2)
base.entidades.player.melee:move(0,dy*1.2)
base.entidades.player.point:move(0,dy*1.2)
elseif dx~=0 then
if dx<0 then
base.entidades.player.moveleft=false
base.entidades.player.body:move(math.min(dx*1.2,5),0)
base.entidades.player.melee:move(math.min(dx*1.2,5),0)
base.entidades.player.point:move(math.min(dx*1.2,5),0)
elseif dx>0 then
base.entidades.player.moveright=false
base.entidades.player.body:move(math.max(dx*1.2,-5),0)
base.entidades.player.melee:move(math.max(dx*1.2,-5),0)
base.entidades.player.point:move(math.max(dx*1.2,-5),0)
end
end
elseif not base.entidades.player.ignore2 and col.type=="plat" and colli then
if dy<0 then
base.entidades.player.ground=true
base.entidades.player.isplatformer=true
base.entidades.player.vy=0
base.entidades.player.body:move(dx,dy/10)
base.entidades.player.melee:move(dx,dy/10)
base.entidades.player.point:move(dx,dy/10)
end
end
end
for _, bu in pairs(base.entidades.bullet) do
if col.l==bu.l then
local dx,dy,colli=0,0,false
colli,dx,dy=bu.body:collidesWith(col.body)--collision bala pared
if colli and col.type =="col" then
if bu.damage==4 then
base.entidades:removeextra(col,"colli")
HC.remove(col.body)
base.entidades:addextra(Explosion(bu.ox,bu.oy,bu.l),"explosion")
end
bu.hp=bu.hp-1
end
end
end
...
Example :
Code: Select all
--x,y,h,w = camera position and dimensions
if col.ox>x and col.ox<x+h and col.oy>y and col.oy<y+w then
-- some stuff
Additional, I used two maps in memory in my game (stage 1 - stage 2), because I save the register of the destruction tiled.
Code: Select all
base.init(self,"assets/level/nivel_1_1_1.lua","assets/level/nivel_1_1_2.lua")