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 |
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..
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.
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.
[Please log in to post a comment]