Can't get out of a loop in a function?
Posted: Fri May 22, 2020 6:45 pm
First post, please be gentle
I Wrote a function, that I WOULD LIKE it to do the following:
When player sprite runs to certain x, y.
Player sprite will not move for 1.5 second.
During this 1.5 sec, showing a turning coin.
After this 1.5, roll a random number, if greater than N, player sprite continue to move its original direction.
In love.draw function:
In love.update function:
My issue seems to be, after the number checking, the player sprite does not continue to move. I am not sure if I am closing the loop properly at this point. If I remove rollingTimer and such, it works fine, just no sprite pause, and continue to move right away.
I Wrote a function, that I WOULD LIKE it to do the following:
When player sprite runs to certain x, y.
Player sprite will not move for 1.5 second.
During this 1.5 sec, showing a turning coin.
After this 1.5, roll a random number, if greater than N, player sprite continue to move its original direction.
Code: Select all
function resolveTrap(dt, player)
for i, t in ipairs(traps) do
if distanceBetween(t.x + t.width/2, t.y + t.height/2, player.body:getX(), player.body:getY()) <= 25 and player.clear == false then
trapDiff = t.difficulty
local directionOrigin = player.direction
player.direction = 0
gameMode = 3
rollingTimer = rollingTimer + dt
if rollingTimer >= 1.5 then
skillOut = math.random(0, player.skill01)
if skillOut > t.difficulty then
player.direction = directionOrigin
player.clear = true
elseif skillOut <= t.difficulty then
player.direction = -directionOrigin
end
end
gameMode = 2
end
end
end
Code: Select all
if h01.direction == 0 then
rollingNumber.animation:draw(sprites.coin_sheet, 100, 600, nil, nil, nil, 20.5, 21)
end
Code: Select all
if rollingTimer > 2 then
rollingTimer = 0
end