- Code: Select all
-------------------
--Screen--Manager--
-------------------
screens = { menu = 1,
playing = 2,
gameover = 3 }
currentscreen = 2
paints = { }
timers = { }
enterKeys = { }
arrowUps = { }
arrowDowns = { }
arrowLefts = { }
arrowRights = { }
-------------------
------Globals------
-------------------
w, h = 318, 212
function on.resize(ww, hh)
w, h = ww, hh
end
local fenetre=platform.window
----------------------
--TheGame--Variables--
----------------------
p, m = 1, -1
cubes = { ["1"] = { w / 2 - 40 , h / 2 - 40 , m , m},
["2"] = { w / 2 - 40 , h / 2 + 20 , m , p},
["3"] = { w / 2 + 20 , h / 2 - 40 , p , m},
["4"] = { w / 2 + 20 , h / 2 + 20 , p , p} }
boule = { w / 2 - 10 , h / 2 - 10 }
terrains = { {w / 10 , h / 12 , w - w / 10 , h - h / 12} , {w / 5 , h / 5 , w - w / 5 , h - h / 5} }
timer.start(0.01)
paints[screens.playing] = function(gc)
gc: setColorRGB(0, 0, 255)
gc: setPen("medium","dashed")
gc: drawRect(terrains[1][1], terrains[1][2] , -w + 2*terrains[1][3] , -h + 2*terrains[1][4])
gc: setPen("thin","smooth")
for k,v in pairs(cubes) do
gc: drawRect(v[1],v[2],20,20)
end
gc: setColorRGB(255, 0, 0)
gc: setPen("medium","dashed")
gc: drawRect(terrains[2][1], terrains[2][2] , -w + 2*terrains[2][3] , -h + 2*terrains[2][4])
gc: setPen("thin","smooth")
gc: drawArc(boule[1], boule[2], 20, 20, 0, 360)
end
timers[screens.playing] = function ()
for k,v in pairs(cubes) do
v[1] = v[1] + v[3]
v[2] = v[2] + v[4]
end
for k,v in pairs(cubes) do
if v[1] <= terrains[1][1] then
v[3] = p
elseif v[1] >= terrains[1][3] - 20 then
v[3] = m
end
if v[2] <= terrains[1][2] then
v[4] = p
elseif v[2] >= terrains[1][4] - 20 then
v[4] = m
end
end
fenetre:invalidate()
end
function on.paint(gc)
paints[currentscreen](gc)
end
function on.timer()
timers[currentscreen]()
end
Sauf que maintenant, j'aimerais que quand les carrés rentrent en collision, ils soient repoussées comme quand ils touchent une paroi

Je me suis méchamment creusé, la tête, mais je trouve pas comment faire, à part utiliser des class() mais je sais pas faire

Merci à ceux qui me viendront en aide!
