0

I'm stuck creating a window that fits my map. Allegro 4.2 shows just 70% of my map; I've tried changing the size of the windows but it stops working at my map size, and I've also tried FULLSCREEN in set_gfx_mode. This is the code that I'm using:

BITMAP* buffer;
BITMAP* rock;

char map[30][30] {-- -the map-- -};

void draw_map() {
  int row, col;
  for(row = 0; row < 30; row++) {
    for(col = 0; col < 30; col++) {
      if(mapa[row][col] == 'X') {
        draw_sprite(buffer, rock, col * 30, row * 30) ;
      }
    }
  }
}

void onscreen() {
  blit(buffer, screen, 0, 0, 0, 0, 640, 480);
}

int main() {
  //allegro default code
  set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  buffer = create_bitmap(640, 480);
  rock = load_bitmap("rock.bmp", NULL);
  while(!key[KEY_ESC]) {
    draw_map();
    onscreen();
  }
}
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
joaortizro
  • 11
  • 1
  • 2

2 Answers2

0

What I understand is that you have a map that is bigger than the screen, and you try to fit it on the screen. There are at least two possible solutions for this:

  1. Check the total size of the pixels of the map to see if it is just TOO large to fit in memory or uses an unsupported resolution, make the changes and then change the window to that size.
  2. Implement a camera system that allows scrolling so that you can have that fixed window size and just scroll the map to fit just one part of it on the screen.

An implementation of solution two is very case specific so I can not show you any example code, but a tip is that you write all the map to a buffer the size of it and then, using the camera X and Y just blit a part of that map to the display bitmap. Good Luck!

rlam12
  • 603
  • 5
  • 16
0

Your map IS bigger than the screen. You draw the rocks with this:

draw_sprite(buffer, rock, col * 30, row * 30) ;

which implies that each tile of your map is 30x30 pixels.

Since your map is declared as:

char map[30][30]

You need a 30*30 by 30*30 = 900 by 900 pixels to hold it, but your buffer is only 640,480.

So either make your map smaller (char map [21][16] with your current buffer), or the buffer bigger (900 by 900 with your current map).

schmop
  • 1,440
  • 1
  • 12
  • 21