views:

509

answers:

5

I'm working on a very simple game (essentially an ice sliding puzzle), for now the whole things in one file and the only level is completely blank of any form of obstacle. It throws up a few errors. My current annoyance is an expected primary expression error, can anyone tell me how to fix it (it throws up at line 99)?

Here's the whole thing,

#include <allegro.h>

BITMAP* buffer;

int x = 15;
int y = 11;

int tempX = 15;
int tempY = 11;

//This will be our background, 1 = clouds, 2 = brick, 3 = floor
int map[24][32] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

//This will contain all the objects, 100 = player
int objMap[24][32] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

void setupGame(){

     buffer = create_bitmap( 640, 480);

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( map[i][t] == 1) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 128, 255, 255));
            else if( map[i][t] == 2) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 255, 128, 0));
            else if( map[i][t] == 3) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 0, 0, 255));

           }       

    }

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( objMap[i][t] == 100) circlefill( buffer, (t * 20) + 10, (i * 20) + 10, 10, makecol( 255, 255, 0));

           }       

    }

    draw_sprite( screen, buffer, 0, 0);

}

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){  // these lines are the ones            
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

     acquire_screen();

     rectfill( buffer, tempX * 20, tempY * 20, (tempX + 1) * 20, (tempY + 1) * 20, makecol( 255, 0, 0));

     circlefill( buffer, (x * 20) + 10, (y * 20) + 10, 10, makecol( 255, 255, 0));

     draw_sprite( screen, buffer, 0, 0);
     release_screen();

     rest(20);
}

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    setupGame();

    while( !key[KEY_ESC]){

           modePlayer();

    }

    return 0;

}

END_OF_MAIN();

and here's the section that breaks;

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){              
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

it's the for lines it doesn't like.

thanks if you can help.

A: 

If your going to reference a line number in your code, at least document in the codeblock where that line is.

eduffy
This should be a comment on the original question, but I don't think it deserves -2!
Greg
+4  A: 

The for() statment takes three parts separated by ';'

for(<init>;<test>;<post>)
{
}

Any of these three parts can be empty but the ';' must be there.

You are also missing the object you should be indexing from in the test portion of each for() statement.

for(; map[BLA][BLA] == <VALUE>;<INC>)
Martin York
+2  A: 

This might help:

void movePlayer(){

    tempX = x;
    tempY = y;

    if (key[KEY_UP] && map[y - 1][x] == 3)
        for ( ; [y - 1][x] == 3; --y){              
        }

    else if(key[KEY_DOWN] && map[y + 1][x] == 3)
        for ( ; [y + 1][x] == 3; ++y){
        }

    else if(key[KEY_RIGHT] && map[y][x + 1] == 3)
        for ( ; [y][x + 1] == 3; ++x){
        }

    else if(key[KEY_LEFT] && map[y][x - 1] == 3)
        for ( ; [y][x - 1] == 3; --x){
        }
Eduardo León
combine this with ates' answer and it's perfect, thanks :D
+5  A: 

What is going on here?

[y - 1][x] == 3

Did you mean:

 map[y - 1][x] == 3
Ates Goral
combine this with eduardo's answer and it's perfect, thanks :D
+1  A: 

Your "for" loops are missing a section. Usually there are three parts: an initialization, a condition, and post-iteration operation. From what I can tell, you have the last two, but no initialization. The compiler is currently interpreting your first "for" loop, for example, as:

  1. Check 3 against [y-1][x]
  2. While 0 != (result of decrement y)...
  3. Do whatever

What I think you mean to happen is:

  1. Assume everything is initialized
  2. While 3 == [y-1][x]...
  3. Do whatever, and decrement y after each iteration

If so, this should look like:

for (; [y-1][x]==3; --y)
{
    // do whatever
}

This applies to all your "for" loops.

Another issue is that you aren't using an array variable, but are just using index offsets. Do you mean to say "map[y-1][x]"?

Brian