Jump to content

  • Log In with Google      Sign In   
  • Create Account


MultiTasking - I need help!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 BenB   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 1999 - 03:29 AM

Hello!
Excuse me for my bad English, I'm from Israel.
I'm building a spaceship game, and I have added the option to Shoot. I didn't wanted the shooting to be fast, so I have added the function Sleep(1) in the loop. But now, everytime that my SpaceShip shoots, I can't move until it gets to the screen end.
What can I do?
Thanks,
Ben

Sponsor:

#2 WhiteHouse   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 1999 - 01:32 AM

Emediatly remove that Sleep(1) statement!
That makes your whole program to stop for X milliseconds.

Instead insert something like this pseudocode into your gameloop:

int iLastTick;
int iCurrentTick;
int iSecondsBetweenShots = 1;

iCurrentTick = GetCurrentTickFromClock();

if (((iCurrentTick-iLastTick) >= iSecondsBetweenShots) && (IsPressed(Key[SHOOT]))
{
Shoot();
}

iLastTick = iCurrentTick;

----------------------------
I use a variant of this and it works great.
This pseudocode can also be used for animations and other timed events.


#3 BenB   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 1999 - 02:17 AM

Thank you, it works!!
I have another problem - I want to make a function that checks if the bullet hited the Enemy Ship. What can I do?
I can't do only

if (BulletX == EnemyX) && (BulletY == EnemyY)
Because that will check only if it hited to the most upper left point. What can I do?
Please Help me!
Thank you!


#4 STG   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 1999 - 03:29 AM

this is the simplest and quickest way

If you know the width and height of your sprite (you must surly) then to check all you need to do is check if shootx >= shipx and shootx <= shipx + ship width and shooty >= shipy and shooty <= shipy + ship height






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS