Okay, I am trying to make somethink like a shooter. And i try to make an explosion were random pixels spawn, and fly in random directions everytime an enemy or the wall gets hit. That works fine. Now i want these random pixel to bounce from the wall so the dont "fly" out of the screen. I use this to make this happen:
Code: Select all
if #ex ~= nil and ex[e] ~=nil and ex[e][p] ~= nil then
if ex[e][p].start_y < 0 then -- Top
ex[e][p].speed_y = ex[e][p].speed_y*-1
elseif ex[e][p].start_y > 240 then -- Bottom
ex[e][p].speed_y = ex[e][p].speed_y*-1
elseif ex[e][p].start_x < 0 then -- Left
ex[e][p].speed_x = ex[e][p].speed_x*-1
elseif ex[e][p].start_x > 400 then -- Right
ex[e][p].speed_x = ex[e][p].speed_x*-1
end
end
-- EDIT:
-- i already tried:
-- ex[e][p].speed_x = -ex[e][p].speed_x
-- but this just has the same affect
Without that code, everything is fine, so i assume it's that code. I am looking at this for days now, and cant get why this should affect the spawnposition. mabe thare is an easy solution i just can't see so i am asking here for help.
I attach a .love file where this code is "activated". The files where the magic happend are "colliosion" and "boom"<- there is the code in.