1
\$\begingroup\$

I have some difficulties to understand how to correctly use GetTickCount() as I have some problems in my little game. I have to place on a case a space ship. This one will shoot with a certain frequence some missiles.

Edit: It works good now, I edit the code below. However there is an other problem, I don't know why there is only one shooting space ship.

I hope someone has an explanation for that.


MyGameEngine::MyGameEngine(...) : tickTime(0) {} // for the constructor... DWORD prev_frame_tick; DWORD curr_frame_tick = GetTickCount(); // function called everytime (loop) void MyGameEngine::idle() { prev_frame_tick = curr_frame_tick; curr_frame_tick = GetTickCount(); tickTime += curr_frame_tick - prev_frame_tick; int i; // SPACE SHIP for (i = 0; i < ship->size(); i++) { // verify if tickTime > freqShoot : if true return new missile with correct positions Missile* m = ship->at(i)->tick(tickTime); if (m != NULL) { missiles->push_back(m); std::cout << "new miss" << std::endl; // I have to put this, however nothing on screen tickTime = 0; } } // MISSILES ANIMATION for (i = 0; i < missiles->size(); i++) { missiles->at(i)->tick(); if (missiles->at(i)->getBordDroitX() > 1.0f) { missiles->erase(missiles->begin() + i); } } } 

Missile* Ship::tick(DWORD t) { Missile* m = NULL; if (t > freqTir) { m = new Missile(posX, posY, width, height, numCase); } return m; } 
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Looks to me its some kind of timer function that returns the time elapsed since the start of program.

As for how to shoot missiles at set intervals, you do this:

give your object a cooldown property; On update step:

cooldown -= dt; if (cooldown <= 0) { shootMissile(); cooldown = missileCooldown; } 
\$\endgroup\$
1
  • \$\begingroup\$ I edit my post, thank you anyway for your suggestion \$\endgroup\$ Commented Dec 18, 2014 at 3:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.