Log In  

I'll preface this by saying that I am a (very) novice programmer who is really enjoying creating games with Pico-8.

I think that this question is more of a structural one. I don't know how to handle a break in game action so that I can do a simple animation when - say - my main character / spaceship is destroyed.

Lets say that I just want to do something that I imagine is pretty straight forward - say use CLS() with different colours (CLS(1), CLS(2), CLS(3) ... etc.) so that the screen flashes six or seven times when my spaceship is destroyed.

I know how to create the animation that I want through code, but I don't know where to put it / how to structure the _update() or the _draw() to "pause" the game so that the animation can run and then the game can pick up from where it was before.

I'm not sure that I've explained myself all that well here but if anybody has any guidance, I'd appreciate it.

D.

P#37809 2017-02-25 11:18 ( Edited 2017-03-01 08:52)

I'm actually have basically the same question at the moment. I'm working on a remake of Atari Combat, and I've hit a speed bump when it comes to the hit animation.

In the original, when a tank gets hit, there's an animation where it spins in place for a bit, and all other action stops until the animation plays out.

I'm not really clear how to pause the normal lifecycle and where to hook in to make that happen.

I can paste the WIP cart if it helps.

P#37811 2017-02-25 11:39 ( Edited 2017-02-25 16:39)

you can just keep track of your game status:

gs_run=0
gs_blown=1

gamestate=gs_run
x,y=0,60
count=0

function _update60()
    if (gamestate==gs_run) then
        x=(x+1)%128     
        if (btnp(5)) then
            x=0
            gamestate=gs_blown
            count=10 --10 frames
        end
    elseif (gamestate==gs_blown) then
        count-=1
        if (count==0) gamestate=gs_run
    end
end

function _draw()
    if (gamestate==gs_run) then
        cls()
        print('\142',x,y)   
    elseif (gamestate==gs_blown) then
        cls(rnd(15))
    end
end
P#37813 2017-02-25 12:15 ( Edited 2017-04-15 18:32)

Hey - thanks for the replies. The game state approach worked for me.

I just added a fourth "mode" to my game states and had an "update_explosion" function and an "draw_explosion" function and then, after the animation, rolled back to "game on" mode.

Thanks again for the help!

D.

P#37835 2017-02-25 20:30 ( Edited 2017-02-26 01:31)

I eventually solved it with a coroutine that triggers on hit, and then having _update skip normal updates as long as the coroutine is unfinished.

P#37958 2017-03-01 03:52 ( Edited 2017-03-01 08:52)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 20:43:57 | 0.006s | Q:15