question about "wait(...)" function

Posted By: dmBlack

question about "wait(...)" function - 11/06/09 13:13

Hi there,

I am working on this 2d panel based game. What I want to do is to control the frequency of attacks of enemies. I was thinking of using wait(x) where x is the amount of seconds to wait until a new attack is possible. Like this:

...
if (enemy_active == 1) { }
if (enemy_active == 0)
{
enemy_active == 1;
attackPlayer(); //do needed stuff
wait(-5);
enemy_active == 0;
}
...

Is that ok? Will the wait(x) slow down my code? I am asking that because the player will have a faster attack rate, like 2 seconds between attacks, and each attack player does grants a chance of being attacked by nearby enemies. Iīve read somewhere that the wait() function allows the other functions to resume their execution while waiting, so I donīt know if that is a problem or not...

Thanks
Posted By: Ottawa

Re: question about "wait(...)" function - 11/06/09 14:21

Hi!


Because you want your game to flow with the action
use something like

While (!panelxyz) {wait (1);}
or
while (panelxyz != condition) {wait (1);}

This type of code waits until the action as been done
and you don't have to count.
Posted By: boyax

Re: question about "wait(...)" function - 11/06/09 15:12

try to look at this function/macro: wait_for()
Posted By: dmBlack

Re: question about "wait(...)" function - 11/06/09 15:19

Thanks guys!!
Iīve just tested here during my lunch break and that way works fine. My way also works but needs improvement.
This wait_for() is interesting and I wasnīt aware of it...
Posted By: Ottawa

Re: question about "wait(...)" function - 11/06/09 18:31

Hi!

@dmBlack : Anytime wink

@boyax : I'll try that one soon.

Ottawa wink
© 2024 lite-C Forums