Jump to content
  • Advertisement
Sign in to follow this  
sjf

Blinking Ghost

This topic is 4873 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

This is a question related to timing and in relation to a pacman / ghost scenario. When pacman eats a power / energy pill the ghosts change color to blue for about 10 seconds. Then they flash (blue and white) for another 6 seconds. The below codes, seems to do the job, but it is ^@#%ing ugly, IMHO! Can anyone offer me advice to a simpler solution (with a 50:50 duty cycle when flashing). This seems way too much code for such a simple task.
   if (now_second - flee_second > 16000)
   {
      fleeing = false;
      flash[0] = flash[1] = 0.0f; flash[2] = 0.8f; /* Return to blue. */
   }
   else if (now_second - flee_second > 10000) /* Last six seconds. */
   {
      if (now_second - flash_second > 100)
      {
         flash_second = now_second;

         if (toggle == false)
         {
            flash[0] = flash[1] = flash[2] = 1.0f; // white
         }
         else
         {
            flash[0] = flash[1] = 0.0f; flash[2] = 0.8f; // blue
         }

         toggle = !toggle;
      }
   }

Share this post


Link to post
Share on other sites
Advertisement
C or C++?

Either way I'd recommend some sort of mini finite state automata rather than a big if/else if/.../else.

IMO easier to do in C++ though

Share this post


Link to post
Share on other sites
holy, what is flash[n]? could you please just explain a bit better what all the variables in ur code sample do and what the 0.0f and 0.8f means? how does this correspond to a colour?

[Edited by - _Phalanx_ on June 17, 2005 4:54:45 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage

I'd recommend some sort of mini finite state automata rather than a big if/else if/.../else.


You're actually complicating things much more!!

By the way, how do you think one codes a finite state automata... With LEX or some other software, which in the end is going to be transformed into if and else statements...

Share this post


Link to post
Share on other sites
Quote:
Original post by _Phalanx_
holy, what is flash[n]?


It represents the color (R, G, B)...

Share this post


Link to post
Share on other sites
Quote:
Original post by Ali_B
Quote:
Original post by Nitage

I'd recommend some sort of mini finite state automata rather than a big if/else if/.../else.


You're actually complicating things much more!!

By the way, how do you think one codes a finite state automata... With LEX or some other software, which in the end is going to be transformed into if and else statements...


No, you're complicating things much more by suggesting an overly complex implementation of a such a small finite state automata.

Share this post


Link to post
Share on other sites
I asked recently for something similar. I wanted to "pulse" a color to black and back again over a chosen time. This is the code I now use. No reason why this can't be from blue to white. You need a timer unit to make it work properly - or at least to be able to pulse over any desired time.


#define M_PI 3.14159265358979323846


float targetColorG=0.85f; // target green color
float targetColorB=1.0f; // target blue color
float moveTime=1.0f; // 1 second pulse cycle
float totalTime=0.0f; // time currently accumulated for pulse

.
.
.

// add time step to total time and reset if over
totalTime+=g_timer.timeStep;
if ( totalTime > moveTime ) {
totalTime=0.0f;
}
// calculate current green and blue components based on current time in the pule cycle
currColorG = targetColorG * (float)((0.75 - cos((2 * M_PI) * (totalTime / moveTime)) * 0.25));
currColorB = targetColorB * (float)((0.75 - cos((2 * M_PI) * (totalTime / moveTime)) * 0.25));
// apply color for next set of draws
glColor3f(0.0f,currColorG,currColorB);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!