Adventures in Game Development -- Day 8




Today I learned a pretty cool function in C++. Unfortunately, this cool function isn't as awesome as it could be as it isn't cross-platform.

The function is the the "sleep function". To use it, you simply type "Sleep()" (capitalization is important) along with a number in between the paranthesis. The number between the parenthsis determines how long the code "sleeps" before it begins again.

I used this function in WEP Cracking: The Game to better simulate downloading a copy of BackTrack Linux. Here's some example code:




    getline (cin, cInstall);
 
    if((cInstall == "download") || (cInstall == "DOWNLOAD") || (cInstall == "Download"))
    {
          cout << "Beginning download" << endl;
          cout << "1 2 3 4 5" << endl;
          Sleep(150);
          cout << "6 7 8 9 10" << endl;
          Sleep(150);
          cout << "11 12 13 14 15" << endl;
          Sleep(150);
          cout << "16 17 18 19 20" << endl;
          Sleep(150);
          cout << "21 22 23 24 25" << endl;
          Sleep(150);
          cout << "26 27 28 29 30" << endl;
          Sleep(150);
          cout << "31 32 33 34 35" << endl;
          Sleep(150);
          cout << "36 37 38 39 40" << endl;
          Sleep(150);
          cout << "41 42 43 44 45" << endl;
          Sleep(150);
          cout << "46 47 48 49 50" << endl;
          Sleep(150);
          cout << "51 52 53 54 55" << endl;
          Sleep(150);
          cout << "56 57 58 59 60" << endl;
          Sleep(150);
          cout << "61 62 63 64 65" << endl;
          Sleep(150);
          cout << "66 67 68 69 70" << endl;
          Sleep(150);
          cout << "71 72 73 74 75" << endl;
          Sleep(150);
          cout << "76 77 78 79 80" << endl;
          Sleep(150);
          cout << "81 82 83 84 85" << endl;
          Sleep(150);
          cout << "86 87 88 89 90" << endl;
          Sleep(150);
          cout << "91 92 93 94 95" << endl;
          Sleep(150);
          cout << "96 97 98 99" << endl;
          Sleep(150);
          cout << "100%" << endl;
          Sleep(150);
          cout << "Download complete." << endl;


Now for the bad...

This function requires the windows header file, which means it is not cross-platform. This is enough for me to NOT use it in the final product. I have it in there now because I was learning about it, but before I'm finished, I'll be swapping it with a cross-platform alternative.

It really sucks because "Sleep()" is quick, easy, and fills a specific need. Hopefully the alternative I find is just as easy.

15 comments:

baka1236 said...

it's a pity that it's not cross-platform :(

atleast you're thinking about everyone when you made the game

Ivan said...

too bad it's not cross platform.
What alternative methods would be available(cross platform, or not)?

Xenototh said...

And the painful fact of life in that what is easy and nice doesn't work for what you want to do. Bleh.

Miyamoto Karyuu said...

uhm, interesting.. i have the "sleep function" in my brain constantly..ahah xD

Jesse Crows said...

good progress!

Come At Me Bro said...

This is great!

H A R R Y G O A Z said...

Have a SUPER weekend !

Michael Arsenault said...

Good stuff bro!

Admin said...

How can I program with C++ on a mac?

Rumiko said...

Aww shame, wish I had a clue so I could help you!

Skaerf said...

Ugh, my head hurts.. I need to learn this

baka1236 said...

i started learning C, its really really fun.

after i learn C i think i'll take up C++

happyhacker said...

@Admin,
Eclipse or xcode.

Functions and looping are helpful.

happyhacker said...

something like this may be less work:

for(int i = 0; i < 100; i++){
cout << i << "%\n";
Sleep(150);
}

nowbuddy said...

really specific, but good job making a story about programming i completely read

Post a Comment