• Advertisement

Archived

This topic is now archived and is closed to further replies.

MultiTasking - I need help!

This topic is 6693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement