🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

MultiTasking - I need help!

Started by
2 comments, last by BenB 24 years, 9 months ago
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.

Advertisement
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!

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
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

This topic is closed to new replies.

Advertisement