Log In  

Okay. I have created randomly generated flashes. However, how can I make the flashes themselves into a randomly generated event? (I am trying to achieve a thunderstorm effect that roles through at random points in the gameplay.)

flash = false
timer = 0

function _draw()
                cls()
                if flash then
                        rectfill (0,0,127,127,7)
end

function _update()

                timer -= 1

                if timer <= 0 then
                            timer = 120
                end 
                if  flr(rnd(100)) <= 10 then
                            flash = true
                else
                            flash = false
                end
        end
end
P#44974 2017-10-07 22:47 ( Edited 2017-10-09 15:56)

If that's what's in your cart, you have a big typo. Change it to this instead:

flash = false
timer = 0

function _draw()
                cls()
                if flash then
                        rectfill (0,0,127,127,7)
                --by not putting an END here, _update was being defined inside of _draw instead of as its own function. ... I would think it would still work though.. But I haven't tested that before.
                end
end

function _update()

                timer -= 1

                if timer <= 0 then
                            timer = 120
                end 
                if  flr(rnd(100)) <= 10 then
                            flash = true
                else
                            flash = false
                end
end

If it still doesn't work, please upload the whole cart somewhere (here or just out the code up using pastebin.com).

Also you probably want to change "timer = 120" to something a little higher..

P#44991 2017-10-08 10:03 ( Edited 2017-10-08 14:06)

Cart #45014 | 2017-10-09 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

The flashing works. (Thank you, for that.) It's trying to make flashing event (the lightning storm) occur at lengthy intervals that I am having trouble with.

The flashing is randomized, which makes it more natural. But I am trying to make it last for only... 30 seconds, let's say. AND I am trying to make the lightning storm occur randomly throughout the gameplay.

Also, how can I make it so that the flashing follows the player? I'm assuming I need to implement code were the camera is.

P#45015 2017-10-09 11:47 ( Edited 2017-10-09 15:49)

Well as far as having the rain only last 30 seconds, You'd need to have some sort of declining counter that gets called during your update process. I THINK update (Not counting Update60) runs at 30 frames per second, So a counter like RainTime=900 being incremented by -=1 each update should work. And as long as it stays above 0, Do your flash routines. When it's <=0, It should skip that routine.

For ease of future expandability (Say you want MORE time than 30 seconds.. LESS?) Maybe have the RainTime set to n*30 where "n" is the amount of seconds.

P#45016 2017-10-09 11:56 ( Edited 2017-10-09 15:59)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 06:55:54 | 0.017s | Q:19