Thread: How to create Letter Invaders typing game in c language?

  1. #1
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24

    How to create Letter Invaders typing game in c language?

    I have been assigned this project ,but my knowledge of C language goes as far as basics of Array, Loops, String, Conditional statement, and some. I really need help and I believe I will get it from you guys.Please Help.

    I have figured out the sleep(); function, and how to make a single char fall with clrscr(); & loop.Its pretty dumb and basic.

    insert
    Code:
    void main()
    {    int a,b,c;
        clrscr();
        for(a=1;a<=46;a++)
        {       clrscr();
            for(c=0;c<=a;c++)
            {    printf("\n");
            }
            printf("\t\t\t*");
            sleep(1);
        }
        getch();
    }



    Basically, I need expert help. I tried to download source code from fooledya.com, but its a zip file, and whole code is scattered and I don't know how to assemble it.

    Any help will be appreciated.Thank You.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    You didn't describe the game yet. Is the purpose to type the letter (for example, "*") before it reaches the bottom of the screen?

  3. #3
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Yes exactly.Here is an image of a game similar to what I have to create.How to create Letter Invaders typing game in c language?-word-invaders-1-jpgHow to create Letter Invaders typing game in c language?-typing_tutor_iii_2-png


    There is score at top, player name on top-right, and as displayed above.words being typed turn red, after correct typing, an arrow shoots from the city-like structure at the bottom, & word\char disappears.If it falls, that part of city vanishes.
    We have to save city by typing correct word/ Alphabet/ Digit and that is how the game is played. There are many more features, but I'm concerned more about basic game right now.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    1) if your project is due any time soon, don't be gone for days at a stretch. Once your thread gets pushed down, it won't be seen by many.

    2) int main(), and return 0, not void main(). That's a bit insulting.

    3) make a menu, which has a large do ... while(choice != 2), where #2 is to quit playing, and end the program.

    main calls menu(). menu calls input(), which gets players name, reads the file of words into an char array[Number][20?], and gives the user a choice to play or quit the game

    4) print the header: score name of the game, players name, at the top.
    Save the x and y of the score since it has to be updated frequently.

    5) printCity() prints the city skyline, from a city[79] array that you create from the character set (ascii is another term used for it), above the value 127. 196 and 220 are two to consider.

    6) Save the x and y where you want the words printed. They should line up in ranks and files, not look haphazard. All words appear at a certain vertical row (varying horizontal location), then move downward from there. The speed will increase (sleep time will shorten), as the game progresses.

    Using 3-5 word "zones" might help.

    This is a Windows game?

  5. #5
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Thanks a lot for answering...sorry for void main() I'm still in the basics...I got the idea of you said..How to create the structure and base of it...

    now I just need some info, so can you just name some function names and other things that I can just Google and learn about?

    I've gotten as far as gotoxy(), insline() n some (pitiful, I know, but I had to be honest)..


    And its a DOS-based game...have to create a game like the game "Letter Invaders" of typing tutor software.. ..Thank you so much again!

    Also, what are zones,how to define printcity(), how to call main() and all..
    Last edited by beginner_babe; 12-19-2013 at 07:30 AM.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Is it a text-based game where you can define everything as text characters? If so, you could use PDCurses to program the text-console. This library also has DOS-support.

    If you need graphics then you should use a library which supports your platform. One possibility for DOS is Allegro (older versions, anyway). Such libraries supply enough functions for you to draw text and lines, etc. to the screen.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What compiler and operating system is this for?

    By zones, I mean specific columns where the words line up, and "march" down toward the user.

    Code:
    Note: All words start on the row immediately below this one
    -->  hotel        India      Zulu       alpha         bravo         sierra
    
         Charlie      Romeo      tango      uniform       Mike          Juliet  
    
    
                    (Words descend in this area)
    
    
    
    The words stop here, where the user's area (top of the skyline of the city, starts).
    
    //You never call main(). The compiler does that for you, at the start of your game.
    Just use:
    #include <stdio.h> and other include files here
    
    prototypes of other functions, go here
    
    
    
    int main() 
    {
       //your code in here
    
    
    
       return 0;
    }
    Obviously, you will need some words to use. They should not be sorted, and they should be short or medium in word length.
    You will need to include time.h so we can time when the words should descend to the next lower row.

    The functions I named (except main()), are not functions you can look up with Google, etc. They are functions that you code up. If you have ANY time at all, please click on the "C Tutorial" link at the top (near the middle), of this web page, and run through it. I'm quite afraid that even with help, you don't know enough to finish this.
    Last edited by Adak; 12-19-2013 at 10:04 AM.

  8. #8
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Thank you so much!! I've already started on the C Tutorials.... I just need some function names...mainly cause I dont know many, and dont know the syntax to use it....like, FILE syntax, Structure syntax & proper understanding of it & all......

    Can you name some websites like cprogramming.com where I can view some progs that might be helpful to me? I learn better from examples..

    And thanks again, appreciate the time & help..

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Are you working with a partner or a group on this project?

    The reason I ask is, these games can be quite time consuming to program if you aren't familiar with them. Also, I don't know that you can find a game code like this to study. Maybe you can find an old space invaders type program - I don't know. Something to study would do you good.

    This is a console (text) based program for Windows, right?

    I will put together a little snippet of something similar that you can study over. It's not a game, but it does show some logic and syntax you should find useful to study, for your game. I hope you have a LOT of time to work on this.

    Keep working on those C tutorials, and I'll post up my snippet on Sunday. It's not to early to start thinking about how you want to divide your game up into working blocks (functions hopefully for the larger ones).
    Last edited by Adak; 12-21-2013 at 01:46 PM.

  10. #10
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If this is a windows console game, then here's an example of the kind of thing you want to do:
    Code:
    #include <windows.h>
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <ctype.h>
    
    HANDLE g_consOut;
    
    void cls() {
        COORD topLeft = {0, 0};
        DWORD cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO csbi; 
        if (!GetConsoleScreenBufferInfo(g_consOut, &csbi))
            return;
        DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        if (!FillConsoleOutputCharacter(g_consOut, ' ', dwConSize,
                topLeft, &cCharsWritten))
            return;
        if (!GetConsoleScreenBufferInfo(g_consOut, &csbi))
            return;
        if (!FillConsoleOutputAttribute(g_consOut, csbi.wAttributes,
                dwConSize, topLeft, &cCharsWritten))
            return;
        SetConsoleCursorPosition(g_consOut, topLeft);
    }
    
    void setPos(int x, int y) {
        COORD pos = {x, y};
        SetConsoleCursorPosition(g_consOut, pos);
    }
    
    void writech(int col, int row, char c) {
        setPos(col, row);
        WriteConsole(g_consOut, &c, 1, NULL, NULL);
    }
    
    int main() {
        enum {reps = 10, bottom = 15, width = 80, sleep_time = 200};
        srand((unsigned)time(NULL));
        g_consOut = GetStdHandle(STD_OUTPUT_HANDLE);
        cls();
        for (int n = 0; n < reps; n++) {
            char c = rand() % ('z'-'a') + 'a';
            int col = rand() % width;
            int i;
            for (i = 0; i < bottom; i++) {
                writech(col, i, c);
                Sleep(sleep_time);
                writech(col, i, ' ');
                if (_kbhit()) {
                    char cc = _getch();
                    if (tolower(cc) == c)
                        break;
                }
            }
            if (i == bottom) // letter got to bottom
                break;
        }
        cls();
        return 0;
    }
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  11. #11
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    I meant from funprogramming.com

  12. #12
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Nope, on my own.It is due by 13-15th of January.I will study games like space-invaders....I've lready worked out the intro, main menu and end...they need a little graphics and all, but I guess I can get someone to help me with that..all I need is game screen now...and thnxx again 4 helping me so much.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is a snippet you can study, for console mode. Has a menu, and prints half a skyline. Shows how to create more. I took out the descending words, since oogabooga has a better example already up.

    Code:
    #include <stdio.h>
    #include <time.h>
    #include <windows.h>
    
    #define MAX 25
    #define LASTY 30 //separates words from the skyline below
    //LASTY, words should destroy the skyline they contact.
    
    #define VRT 179
    #define HRZ 196
    #define TLC 218
    #define TRC 191
    #define BLC 192
    #define BRC 217
    #define LHC 180
    #define RHC 195
    
    void menu(char *words[MAX]); 
    void Gotoxy(short x, short y);
    int skyline(void);
    
    int main() {
       char *words[MAX]={
          "Golf","Bravo","Kilo","Alfa","Delta",
          "Echo","India","Whiskey","Romeo","Tango",
          "Zulu","Juliet","Mike","Sierra","Victor",
          "Hotel","Lima","Quebec","Papa","Tango",
          "X-Ray","Oscar","Uniform","Charlie","Foxtrot"
       };
    
       menu(words);
    
       printf("\n");
       return 0;
    }
    /* corners are numbers 1--A--2
                           |  |  |
           E: straight     D--F--B
              connector    |  |  |
                           4--C--3
    T's: A-E, 4-Way: F  
    
    
    Lay out the skyline you want in the char array s[] below. Refer to the above
    diagram to use the right char. The switch statement will transfer these one
    char "drawing" chars, into one of the defines at the top of the program.
    
    */
    
    int skyline(void) {
       int i,j,x=1,y=LASTY+1;
       unsigned char s[7][78]=
       {
        {"                                                                             "},  
        {" 1--2              1--2      1---2 1--2                                      "},
        {" |  |    1---2  1--B  |      |   | |  | 1-2                                  "},
        {" D--B 1--B   |  |  |  |  1---B   | |  | | |                                  "},
        {" |  | |  |   |  |  |  |  |   |   | |  | | |                                  "},
        {" |  | |  |   |  |  |  |  |   |   | |  | | |                                  "},  
        {" |  4-3  |   4--3  |  4--3   |   4-3  4-3 |                                  "}
       };
       for(i=0;i<7;i++) {
          for(j=0;j<78;j++) {
             switch(s[i][j]) {
               case '1': s[i][j]=TLC; break;
               case '2': s[i][j]=TRC; break;
               case '3': s[i][j]=BRC; break;
               case '4': s[i][j]=BLC; break;
               case 'B': s[i][j]=LHC; break;
               case 'D': s[i][j]=RHC; break;
    
             }
         } 
       }
          
       Gotoxy(x,y);
       for(i=0;i<7;i++) {
          printf("%s\n",s[i]);
       }
       getchar();
       return 0;
    }
    void menu(char *words[MAX]) {
       int i;
       printf(" Welcome to the Main Menu\n");
       do {
          printf("\n\tEnter '1' to play Word Invaders,  \n\tor '2' to Quit: ");
          fflush(stdout);
          scanf(" %d",&i);
          
          if(i==1) {  //play the game
             //intro: briefly, how to play the game
             //print score at top, keep the position so you 
             //can get back and update it quickly
             skyline();
             //begin descending words and keyboarding, etc.
          }else if(i==2)
             break;
       }while(i<1 || i>2);
    } 
    void Gotoxy(short x, short y) {
       COORD c={x,y}; 
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
    }

  14. #14
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Thanks a lot for taking the time to reply all that oogabooga... Really appreciate it...but when I executed the program in Turbo C , in both .c & .cpp extensions,..I m getting 35 errors.....
    Last edited by beginner_babe; 12-22-2013 at 09:03 AM.

  15. #15
    Registered User beginner_babe's Avatar
    Join Date
    Dec 2013
    Posts
    24
    Thank You so much Adak for taking the time to reply & help me....I ran your code & got 5 errors & 3 warnings,..one of the errors being "Unable to open include file WINDOWS.H" & "Unidentified symbol STD_OUTPUT_HANDLE",..same one for c,.. I would have solved it myself but I cant even understand what its all about...I m gonna try n understand it once I can get it all together..
    Thnx again.
    Last edited by beginner_babe; 12-22-2013 at 09:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Typing Tutor game?
    By santuno in forum C Programming
    Replies: 8
    Last Post: 07-25-2009, 02:09 AM
  2. Create some animation using C language??
    By neo_lam in forum C Programming
    Replies: 3
    Last Post: 11-21-2006, 07:20 AM
  3. Need help on my Space Invaders Game
    By zz3ta in forum Game Programming
    Replies: 6
    Last Post: 01-04-2004, 04:32 PM
  4. Typing Tutor Game
    By sowhat82 in forum Game Programming
    Replies: 3
    Last Post: 02-17-2003, 03:57 PM
  5. Galaxian or Space invaders for my next game (read this)
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2001, 09:28 PM