Thread: Game Text

  1. #1
    Registered User Kuplex's Avatar
    Join Date
    Dec 2001
    Posts
    18

    Question Game Text

    What's a simple way to make text appear like it does in video games? You know, one letter at a time at a variably set speed. I like the way it displays the text. Any pointers cuz I think my mind's gone blank or something!
    Kuplex
    "The only thing you can count on is uncertainty."

    Must I explain myself futher?

  2. #2
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    time.h?
    do loop?
    Yoshi

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    1

    Talking csc

    howcan we input picture(jpg format in to a window using c++

  4. #4
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Uhhh.....I got an idea (if your using dos: This will only output 'Hello'):


    #include <iostream.h>
    #include <conio.h>
    #include <dos.h>

    int main()
    {

    cout<<"H";
    delay(500);//you may need to raise 500 higher.......

    cout<<"e";
    delay(500);

    cout<<"l";
    delay(500);

    cout<<"l";
    delay(500);

    cout<<"o";
    getch();
    return 0;

    }





    well, as you can see, i used the delay function. It stops the whole code for how much milliseconds (delay(//right here); ) You set it for. if that doesn't help just sya so
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  5. #5
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    oh, and b4 everything starts, put a

    clrscr();


    function so you can watch your creation over and over and over and over and over...........
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  6. #6
    Unregistered
    Guest
    #include <windows.h>
    #include <conio.h> //conio_mingw.h
    HANDLE so = GetStdHandle (STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO info = {100, 0};
    INT add, play, sel, xm, ym, xa, ya, x, p, n, i, j;
    CHAR f [7] [6], spc [81], c;

    VOID init ()
    {
    xa = x = 9;
    add = ya = 1;
    spc [80] = play = sel = ym = p = 0;
    for (i = 0; i < 80; i++) spc [i] = ' ';
    for (i = 0; i < 7; i += 2)
    for (j = 0; j < 6; j++) f [i] [j] = 1;
    SetConsoleCursorPosition (so, (COORD) {0, 24});
    for (i = 0; i < 25; i++) _cputs (spc);
    SetConsoleCursorPosition (so, (COORD) {31, 10});
    _cputs ("Press UP to start!");
    }

    INT main ()
    {
    SetConsoleCursorInfo (so, &info);
    SetConsoleTextAttribute (so, 15 + (1 << 4));
    for (init (); c != 27; Sleep (200))
    {
    if (kbhit ())
    {
    for (c = getch (); kbhit (); c = getch ());
    if (c == 'K') if (x-- == 9) x = 9;
    if (c == 'M') if (x++ == 63) x = 63;
    if (c == 'H' && play && !ym) xm = x + 3;
    if (c == 'H' && play && !ym) ym = 20;
    if (c == 'H' && !play && !sel) sel = play = 1;
    if (c == 'H' && !play && sel) init ();
    }
    if (play)
    {
    SetConsoleCursorPosition (so, (COORD) {0, 1});
    if ((xa += add) == 29 || xa == 8) ya++;
    if (xa == 29 || xa == 8) add = add > 0 ? -1 : 1;
    if (xa == 29) xa--;
    if (xa == 8) xa++;
    if (ya == 15)
    {
    play = n = 0;
    for (i = 0; i < 7; i++)
    for (j = 0; j < 6; j++) if (f [i] [j]) n++;
    for (i = 0; i < 22; i++) _cputs (spc);
    SetConsoleCursorPosition (so, (COORD) {33, 10});
    _cprintf ("%u%s", n, " UFOS LEFT");
    continue;
    }
    if (ym-- < 3) ym = 0;
    for (i = 0; i < 19; i++) _cputs (spc);
    SetConsoleCursorPosition (so, (COORD) {xm, ym});
    if ((i = ym - ya) >= 0 && i < 7 &&
    (j = xm - xa) > 0 && f [i] [--j / 7] &&
    ++j < 41 && f [i] [++j / 7])
    f [i] [j / 7] = ym = 0;
    if (ym) _cputs ("|");
    p = !p;
    for (i = ya; i < ya + 7; i++)
    for (j = xa; j < xa + 42; j += 7)
    if (f [i - ya] [(j - xa) / 7] &&
    SetConsoleCursorPosition (so, (COORD) {j, i}))
    p ? _cputs (" (^-^) ") : _cputs (" (^O^) ");
    SetConsoleCursorPosition (so, (COORD) {x, 21});
    _cprintf ("%s%s", " ", " _A_ ");
    SetConsoleCursorPosition (so, (COORD) {x, 22});
    _cputs (" [___] ");
    }
    }
    }

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    here is a really ez way:

    Code:
    #include <iostream>
    using std::cout;
    #include <windows.h>
    
    int main()
    {
    	int x=/*Whatever Ammount Of Miliseconds you want*/;
    	
    	cout << "H";
    	Sleep(x);
    	cout << "E";
    	Sleep(x);
    	cout << "L";
    	Sleep(x);
    	cout << "L";
    	Sleep(x);
    	cout << "O";
    	// And so on
    
    	return 0;
    }

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Post Try this...

    Also, you could try doing a counter (as this slows the computer down enough to a wait). The problem is that the counter is slower or faster based on the computer speed. An example of the code is below.


    ------------------

    for (int i = 0; i < 300000; i++);
    cout<< "H";
    for (int i = 0; i < 300000; i++);
    cout<< "E";
    for (int i = 0; i < 300000; i++);
    cout<< "L";
    for (int i = 0; i < 300000; i++);
    cout<< "L";
    for (int i = 0; i < 300000; i++);
    cout<< "O";

    ------------------


    It is easiest to create a function (Wait(int Time) or whatever) where you can put in a length to pause for. This may help, since I have never tried the other methods posted here. It is what I have used so far, the only thing is the problem with slower or faster computers, as it will take longer to count up to 300000 on a slower computer.

    Hope this helps!


    Kyoto Oshiro
    http://www.angelfire.com/realm2/horizon/files.html
    Horizon Games

  9. #9
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    well i have never used sleep() cause i don't have windows.h and the delay() aint working even though i have dos.h but wouldn't it be easier just to do something like this:

    //include stuff

    void poof(char letter) { // Make a function out of it
    delay(500);
    cout << letter;
    }

    int main() {
    poof(H);
    poof(E);
    poof(L);
    poof(L);
    poof(O);

    return 0;
    }

  10. #10
    Unregistered
    Guest
    Yes, why not, and it can be even easier:

    #include <windows.h>
    #include <stdio.h>
    char s [7] = "HELLO\0", i = 0;

    int main ()
    {
    for (; s [i]; Sleep (900)) putchar (s [i++]);
    }

  11. #11
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Code:
    #include <stdio.h>
    #include <time.h>
    
    ...
    
    int printSlowly(char *str)
    {
     int i = 50;
     while(*str)
     {
      printf("%c",*str);
      *str++;
      sleep(i);
     }
     return 0;
    }
    usage: printSlowly("Hello, my love!");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with my text adventure game.
    By Haggarduser in forum Game Programming
    Replies: 15
    Last Post: 10-26-2007, 01:53 AM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  5. My Pre-Alpha Version Rpg Text Game
    By knight543 in forum C++ Programming
    Replies: 1
    Last Post: 04-06-2002, 06:02 AM