Jump to content

  • Log In with Google      Sign In   
  • Create Account

what a stupid question !!!


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 spillsome   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 October 2001 - 05:55 AM

i''m the newbie among the newbies and i have very basic question about game programming. Suppose you have a class CAlien with a Render() function. You also have a game loop and within the game loop you call the Render() function of all the CAlien objects. Ok, now Suppose one of the alien got hit by a missile. I want the alien to act differently as soon as he got hit by the missile. How can I do that ? Does the Render() function have to be changed to do something else ? Can somebody explain to me how to do it thanks. Spill "not the great" some.

Sponsor:

#2 Drazgal   Members   -  Reputation: 368

Like
Likes
Like

Posted 11 October 2001 - 07:44 AM

Try having different modes for the alien, ie Alive, Dead, Hurt etc, (hint use enum in C++) and set the mode when it changes. Then when you call render() check what mode the alien is in and act accordingly.

http://kickme.to/BallisticPrograms

#3 spillsome   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 October 2001 - 06:54 PM

thanks
somebody told me that i should use function pointer.
Do you think it is a good idea ?

#4 merlin9x9   Members   -  Reputation: 174

Like
Likes
Like

Posted 11 October 2001 - 07:26 PM

The reason you''d use a function pointer is to avoid having to test for which state the entity is in inside of your Render function.

For example, let''s say that you have your render function implemented something like this to handle your entities different visual states:
  
void CAlien::Render()
{
switch(state)
{
case SHOOTING:
// draw stuff

break;

case ATTACKING:
// draw stuff

break;

case DYING:
// draw stuff

break;
}
}


For every frame, the Render function will have to test the value of state, possibly trodding to lots of different possiblities. This takes time, of course.

Instead, you could have a different function for each visual state. For example, CAlien::RenderShooting, CAlien::RenderAttacking, and CAlien::Dying. Then you use a function pointer that points to the appropriate drawing functions. So, when you set the entity''s state, just set that pointer to the address of the drawing function you need. Then, instead of calling a drawing function directly, just call it through the function pointer. This eliminates the need for all the tests, but is a little tricker.




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