Thread: What is wrong with this?

  1. #1
    Help
    Guest

    What is wrong with this?

    Hello, I am new to C and C++ and want to get into game
    programming so I found this tutorial at SDL's website called "Help! How Do I Move An Image?". The problem is it is python and I want to learn how to program games in C or C++.
    This is what I have so far
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
          int screen[8] = { 1, 1, 1, 1, 2, 2, 2, 2 }; //the map array
             int x,y,a;
             int playerpos; //players position
    
              playerpos = 3; //set players starting point to the fourth element in the array
               screen[playerpos] = 8; // make the hero a mighty 8 :)
    
              for( x = 0; x < 8; x++ ) // loop to see if this works
              {
               printf(" %d ", screen[x]);
              } //loop worked now we try to move 8
    
              y = playerpos; //copy playerpos to a variable
               playerpos = y - 1; // move playerpos to the left
                screen[playerpos] = 8; //shape shifting isnt allowed
                 printf("\n"); //new line to compare
    
                 for( a = 0; a < 8; a++ );
                 {
                  printf(" %d ", screen[a]);
                 }
    
          system("PAUSE");
          return 0;
    }
    This is what I get:
    1 1 1 8 2 2 2 2
    37814176
    Press any key to continue . . .
    8 was supposed to move left but it didnt .
    Thanks to all who apply in advance.

  2. #2
    Help
    Guest
    Thank you very much

  3. #3
    Help
    Guest
    I have one other problem now. After reading the faq I decided to add movement to my very advance game, so I used preludes "An alternative solution to this problem is the Win32 API"
    here is my code now:
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <limits.h>
    #include <windows.h>
    
    int main()
    {
          HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
          SetConsoleTextAttribute(hCon, FOREGROUND_RED | BACKGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
          int background[8] = { 1, 1, 1, 1, 2, 2, 2, 2 };
          int screen[8] = { 1, 1, 1, 1, 2, 2, 2, 2 }; //the map array
             int x,y,a,b;
             int playerpos; //players position
                short esc = 0; //something prelude did in the $$$ know clue
    
              playerpos = 3; //set players starting point to the fourth element in the array
               screen[playerpos] = 8; // make the hero a mighty 8 :)
    
              for( x = 0; x < 8; x++ ) // loop to see if this works
              {
               printf(" %d ", screen[x]);
              } //loop worked now we try to move 8
    
    
          while ( !esc )
          {
            esc = GetAsyncKeyState ( VK_ESCAPE );
    
            if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX )
    
             puts ( " you cant jump yet " );
    
             else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX )
    
              puts ( " going through the ground is cheating :) " );
    
              else if ( GetAsyncKeyState ( VK_LEFT ) & SHRT_MAX )
    
               screen[playerpos] = background[playerpos]; //copy the correct number to the array
               y = playerpos; //copy playerpos to a variable
                playerpos = y - 1; // move playerpos to the left
                 screen[playerpos] = 8; //shape shifting isnt allowed
                  printf("\n"); //new line to compare
                 for( a = 0; a < 8; a++ ) //the new loop begins
                 {
                  printf(" %d ", screen[a]);
                 } //new loop ends
    
                 else if ( GetAsyncKeyState ( VK_RIGHT ) & SHRT_MAX )
    
                   screen[playerpos] = background[playerpos]; //copy the correct number to the array
                    y = playerpos; //copy playerpos to a variable
                     playerpos = y - 1; // move playerpos to the left
                     screen[playerpos] = 8; //shape shifting isnt allowed
                      printf("\n"); //new line to compare
                      for( a = 0; a < 8; a++ ) //the new loop begins
                      {
                       printf(" %d ", screen[a]);
                      } //new loop ends
          }
         return EXIT_SUCCESS;
    }
    Thanks again to all who apply it gives me a parse error before the 2nd to the last else if or line 49.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM