Sign in to follow this  

Single Error.

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think I have a map working now, but it's giving me an error, that's wierd and I cant find it. Help please.
#include <iostream>
#include <SDL/SDL.h>
using namespace std;
SDL_Surface *screen;
SDL_Surface *grass;
SDL_Surface *water;
SDL_Surface *wall;
SDL_Surface *tree;
int map[10][10] = {{4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
                   {4, 1, 1, 1, 1, 1, 1, 1, 1, 4}, //error here: Syntax Error before { token
                   {4, 1, 2, 2, 1, 1, 2, 2, 1, 4},
                   {4, 1, 3, 3, 3, 3, 3, 3, 1, 4},
                   {4, 1, 2, 2, 1, 1, 2, 2, 1, 4},
                   {4, 1, 1, 1, 1, 1, 1, 1, 1, 4},
                   {4, 1, 3, 3, 3, 3, 3, 3, 1, 4},
                   {4, 1, 1, 1, 4, 4, 1, 1, 1, 4},
                   {4, 1, 1, 1, 1, 1, 1, 1, 1, 4},
                   {4, 4, 4, 4, 4, 4, 4, 4, 4, 4}};
int xpos = 0;
int ypos = 0;
int InitImages() {
  grass = SDL_LoadBMP("grass.bmp");
  water = SDL_LoadBMP("water.bmp");
  wall = SDL_LoadBMP("wall.bmp");
  tree = SDL_LoadBMP("tree.bmp");
  return 0;
}
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *destrect);
void drawIMG(SDL_Surface *img, int x, int y) {
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, screen, &dest);
}
void drawMap() {
  for(int y=0; y<9; y++) {
    xpos = 0;
    for(int x=0; x<9; x++) {
      if(x == 9) {
        ypos =+ 32;
      }
      if(map[x][y] == 1) {
        drawIMG(grass, xpos, ypos);
        SDL_Flip(screen);
      }
      if(map[x][y] == 2) {
        drawIMG(water, xpos, ypos);
        SDL_Flip(screen);
      }
      if(map[x][y] == 3) {
        drawIMG(wall, xpos, ypos);
        SDL_Flip(screen);
      }
      if(map[x][y] == 4) {
        drawIMG(tree, xpos, ypos);
        SDL_Flip(screen);
      }
      xpos =+ 32;
    }
  }
}
int main(int argc, char *argv[]) {
  if(SDL_Init(SDL_INIT_VIDEO) < 0) {
    cout<<"Unable to init SDL."<<endl;
    SDL_GetError();
  }
  atexit(SDL_Quit);
  screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
  if(screen == NULL) {
    cout<<"Unable to set video mode."<<endl;
    SDL_GetError();
  }
  InitImages();
  int done=0;
  while(done == 0)
  {
    SDL_Event event;

    while ( SDL_PollEvent(&event) )
    {
      if ( event.type == SDL_QUIT )  {  done = 1;  }

      if ( event.type == SDL_KEYDOWN )
      {
        if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
      }
    }
    drawMap();
  }
  return 0;
}




Share this post


Link to post
Share on other sites
It looks like you're missing a set of {}'s.


int map[10][10] = {{4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 1, 2, 2, 1, 1, 2, 2, 1, 4},
{4, 1, 3, 3, 3, 3, 3, 3, 1, 4},
{4, 1, 2, 2, 1, 1, 2, 2, 1, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 1, 3, 3, 3, 3, 3, 3, 1, 4},
{4, 1, 1, 1, 4, 4, 1, 1, 1, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4}};

Share this post


Link to post
Share on other sites
hey,
i believe that where you have "=+" (in 2 places i think) it should be "+=".
i just tried that and it will cause the number to stay "=" the right side instead of add it by the right side (if you use "=+") :)

that should fix ya problem :)

Share this post


Link to post
Share on other sites
Yea, I saw that and changed it, and now it's giving me 8 tiles across, with 4 or so of them constantly changing..

edit: Still cant find the prob...

[Edited by - Meta Adam on January 16, 2005 11:23:12 PM]

Share this post


Link to post
Share on other sites
ok, see this:
if (x == 9) {
ypos += 32;
}
it never happens because your loop goes from 0 (int x = 0) to *8* (x<9)
it never gets to 9. this should fix the problem of only 1 row (im assuming this is the 8 tiles being drawn).
also, i see you have 10 tiles per row...that means your loops should go like so:
(int x = 0; x<=9; ++x)
(int y = 0; y<=9; ++y)
in the same places as they are now.
changing these loops should also fix the first problem with only 8 tiles showing.

let me know how it works now :)

Share this post


Link to post
Share on other sites
w00t I'm getting the right graphics now, I had to switch x and y values, on the check maps like if(map[y][x] == 4) instead of x, y. But instead of it only outputting the map once It does it again right under it. So I changed the drawMap function to int type, and have it return 1, but that didnt work.

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this