help w/ invaderz game

This is a discussion on help w/ invaderz game within the C++ Programming forums, part of the General Programming Boards category; I am making an invaderz game (nooone take my idea!!!!) im trying to make the top guy move (he wont ...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    help w/ invaderz game

    I am making an invaderz game (nooone take my idea!!!!) im trying to make the top guy move (he wont ) here is the code:

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

    int x = 10;
    int y = 24;
    int bx = 1;
    int by = 5;
    int bux;
    int buy;
    int lorr = 0;
    int bull = 0;
    int tmer = 0;

    int main()
    {
    while(1)
    {
    gotoxy(x, y);
    putch('^');
    gotoxy(bx, by);
    putch('-');
    if (tmer == 10)
    {
    clrscr();
    if (bx == 1)
    bull = 0;
    if (bx == 80)
    bull = 1;
    if (bull == 1)
    bx = bx - 1;
    if (bull == 0)
    bx = bx + 1;
    tmer = 0;
    }
    if (kbhit)
    {
    char movement = getch();

    if (movement == 27)
    break;
    }
    delay(1);
    tmer = tmer + 1;
    }
    return 0;
    }


    please dont be shy!
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    heh, i solved the problem (use the switch case structure) but i cant get it to read the escape button, anyone know how to make the switch case structure read the button 'ESC'?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    ESC's ASCII code's 27, but I don't know if that'll help w/o seeing your code...

  4. #4
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    but I don't know if that'll help w/o seeing your code...
    You just have to change the


    if (kbhit)
    {
    char movement = getch();

    if (movement == 27)
    break;
    }


    to


    if (kbhit)
    {
    switch(movement)
    {
    case /*the code for ESC*/:
    //Dunno how to exit the program
    break;
    }
    }


    theres the code for you

    P.S. you have to declare movement b4 using the switch case structure
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    It's still not working when you put 27 in instead of /*the code for ESC*/? What is it doing?

  6. #6
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    I want it to exit the prog when you hit the ESC key
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    it appears that the conditions never change for the following
    and therefore bx and by never change.....
    do a print out of these and see...



    Code:
    	                if (tmer == 10) 
    		{ 
    			clrscr(); 
    			if (bx == 1) 
    				bull = 0; 
    			if (bx == 80) 
    				bull = 1; 
    			if (bull == 1) 
    				bx = bx - 1; 
    			if (bull == 0) 
    				bx = bx + 1; 
    			tmer = 0; 
    		}
    zMan

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Originally posted by bluehead
    I want it to exit the prog when you hit the ESC key


    Code:
    if (kbhit) 
    { 
           switch(movement) 
           { 
                 case 27: 
                      return 0;
                      break; 
           } 
    }
    that should exit.
    (sorry about my crappy spacing [u cant use tab key in here)
    Last edited by Okiesmokie; 02-25-2002 at 05:45 PM.

  9. #9
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    nope, doesn't work, either that or its not reading the case structure...
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  10. #10
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    lol if(kbhit()) not if(kbhit)

  11. #11
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    heh me bad
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    kbhit

    I hope this helps... I have built a couple of console games using kbhit()....



    when using kbhit()


    you have to using something like this....


    while( 1 )
    {

    while( !kbhit() ) //kbhit waits for noone
    {
    PerformGameFunctions();
    }

    int key = getch();

    switch( key ){ exit... move screen items.. exit...whatever.....

    case 72: myship.x += SPEED; break;
    case 75: myship.x -= SPEED; break;

    };


    }


    you can also look into GetAsyncKeyState( VK_? )

    I am not sure if it will work in a non-windows program... though..
    but I think it should...
    zMan

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    69

    exit

    It's pretty easy

    Code:
    while(kbhit())
    {
    int x = getch();
    cout<<"Code "<<x;
    switch(x)
    {
    case 27:
    exit(0);  
    break;
    }
    The exit(0) exits the program the cout will print out the code so you can add more options like code 80 is down code 72 is up code 75 is left and code 77 is right

  14. #14
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    heh, n/m the prob was that i did

    if (khbit)
    {
    //bla bla
    }

    Instead of

    if (khbit())
    {
    //bla bla
    }

    hehe you get the idea
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 01:48 AM
  3. C++ Game of Life Program
    By rayrayj52 in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 04:58 PM
  4. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 11:35 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-25-2002, 12:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21