Thread: How do I tell what character is in a space?

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

    Unhappy How do I tell what character is in a space?

    Okay, here is a wierd one that I can't figure out. I am making a simple racing game. When the player pushes the arrows on the number pad, the "car" (actually a single character symbol) moves in the appropriate direction. The thing is, I want to be able to check if they have crashed into a wall, driven over a powerup, or anything else. To do this, I was thinking of going to the location they wish to drive into, checking it to see what symbol is there, and returning a result. If it is a wall, the result would be 1, to mean they have crashed, etc. The only thing is I don't know how to check the space to see what character is there. May sound complicated and wierd, most likely because of how I typed it. I put a bit of example source code below if that helps. Any ideas would be great. Thanks in advance!

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

    int PlayerX, // X location of car
    PlayerY, // Y location of car
    Symbol = '!';// Car symbol

    const char Wall = '#', // What a wall looks like
    Powerup = '*'; // A powerup

    char Move; // The number the player presses

    Move = getch(); // Getting their movement

    if (Move == '8') // This will move them forward
    {
    PlayerY--; // This will move them up one space
    gotoxy(PlayerX, PlayerY);

    //This is where I need help. How do I check to see what
    //character is in the space they wish to enter?

    } // Move Forward


    ...BLA BLA BLA continues on with other movement options

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

    If it is unclear please tell me, because I really would like this to work. Another quick question. How do I keep a timer running in the background, to see how much time they have taken to finish the race in comparision to others and such. I want it to keep running no matter what they do. I am not sure how to though. Any help appreciated. Thanks everyone who looks at this problem for me!


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

  2. #2
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    When the program starts, create a two-deminsional array to track what is at each location. The array indexes should coorespond with the x,y coordinates of the screen.

    then when moving the car get what is already in that location:

    char array[MAX_X][MAX_Y];

    x = PlayerX;
    y = PlayerY;

    // adjust PlayerX and PlayerY according to the input

    newLocation = array[PlayerX][PlayerY];
    if(newLocation == ' ')
    {
    array[PlayerX][PlayerY] = array[x][y];
    array[x][y] = ' ';

    gotoxy(PlayerX, PlayerY);

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

    Lightbulb

    Oh, okay, I see what you are saying sigma. Thanks for your help!


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. pipe
    By smart girl in forum C Programming
    Replies: 4
    Last Post: 04-30-2006, 09:17 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Suggest another way or how can my code be improved
    By peterchen in forum C Programming
    Replies: 6
    Last Post: 01-23-2006, 04:37 PM
  5. Problem with loop stopping at wrong time
    By Baron in forum C Programming
    Replies: 11
    Last Post: 12-14-2005, 08:35 PM