Log In  

I wrestled with timers last night trying to get my bad guys to shoot bullets on an interval. The problem was with half seconds or less.

Getting a guy to fire every 3 seconds is straight forward, 3*30=90frames

I was trying to create a sequence of bullets so one guy fires every 3 seconds, the next 3.25, the next 3.5 and so on down the line to create a "bullet wave"

My problem is calculating the number of frames for those half seconds. I'm dealing with "human" inputs for configuring the sequence. Something like badGuyShoot(3), badGuyShoot(3.25), badGuyShoot(3.5) and so on...

I'm not sure how to get the decimal part in order to calculate how many frames to use for that time.

3*30=90frames
.25=7.5f so round to 8f

Total frames to get (close to) 3.25 seconds is 98...but how do I get that number? I tried to see if there was a way to parse off the decimal and then use that as a separate number but no luck.

Any thoughts or approaches that you've used are appreciated. Any code or links you can share is even better. Maybe I'm just thinking about it the wrong way too...need some other eyeballs and brains to help.

P#20530 2016-05-13 09:52 ( Edited 2016-05-13 16:59)

Well shit...after just writing that, I guess I could just make the decimals a separate parameter, huh? Feels kind of hacky but would work.

So instead of badGuyShoot(3.25) it would be badGuyShoot(3,25) and then divide to get a decimal, then calculate.

Hmmm...

...but I'm still interested in hearing your insight and thoughts. I'm sure there's a better way than that, even.

P#20531 2016-05-13 09:53 ( Edited 2016-05-13 13:53)

I feel you are better off using frame counts and avoiding seconds entirely. The timing in seconds won't be accurate anyway, and it's likely going to cause other problems later.

Your next best bet is to decouple your simulation from the framerate, but that gets more complicated. I'm not sure I'd bother with that for a Pico8 game.

P#20533 2016-05-13 10:05 ( Edited 2016-05-13 14:05)

Cool, thanks...kinda figured I was heading that route anyway. Thanks for confirming.

P#20542 2016-05-13 12:59 ( Edited 2016-05-13 16:59)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 11:30:46 | 0.006s | Q:11