27int create_empty_map(
MAP **map,
char *name,
int XSIZE,
int YSIZE,
int TILEW,
int TILEH,
int nbmaxobjects,
int nbmaxgroup,
int nbmaxanims,
int nbtiles,
int nbanims )
32 nbmaxobjects = nbmaxgroup = nbmaxanims = nbtiles = nbanims = 1 ;
33 nbmaxgroup = nbmaxobjects ;
42 Malloc( ( *map ) -> grid,
CELL, XSIZE * YSIZE );
45 Malloc( ( *map ) -> name,
char, ustrsizez( name ) );
47 ustrcpy( ( *map ) -> name, name );
49 if ( !( *map ) -> grid || !( *map ) -> name )
52 ( *map ) -> XSIZE = XSIZE ;
53 ( *map ) -> YSIZE = YSIZE ;
55 for ( x = 0 ; x < XSIZE ; x++ )
57 for ( y = 0 ; y < YSIZE ; y++ )
66 ( *map ) -> TILEW = TILEW;
67 ( *map ) -> TILEH = TILEH;
68 ( *map ) -> bgcolor = makeacol( 0, 0, 0, 255 );
69 ( *map ) -> wirecolor = makeacol( 255, 255, 255, 255 );
73 ( *map ) -> mousemap = create_bitmap( ( *map ) -> TILEW, ( *map ) -> TILEH );
74 ( *map ) -> colortile = create_bitmap( ( *map ) -> TILEW, ( *map ) -> TILEH );
76 clear_to_color( ( *map ) -> mousemap, makecol( 255, 255, 255 ) );
77 clear_to_color( ( *map ) -> colortile, ( *map ) -> bgcolor );
80 line( ( *map ) -> mousemap, 0, ( TILEH >> 1 ) - 2, ( TILEW >> 1 ) - 3, 0, makecol( 255, 0, 0 ) );
81 floodfill( ( *map ) -> mousemap, 1, 1, makecol( 255, 0, 0 ) );
83 line( ( *map ) -> mousemap, ( TILEW >> 1 ) - 3, TILEH - 1, 0, ( TILEH >> 1 ) + 1, makecol( 0, 255, 0 ) );
84 floodfill( ( *map ) -> mousemap, 1, TILEH - 2, makecol( 0, 255, 0 ) );
86 line( ( *map ) -> mousemap, ( TILEW >> 1 ) + 2, TILEH - 1, TILEW - 1, ( TILEH >> 1 ) + 1, makecol( 0, 0, 255 ) );
87 floodfill( ( *map ) -> mousemap, TILEW - 2, TILEH - 1, makecol( 0, 0, 255 ) );
89 line( ( *map ) -> mousemap, ( TILEW >> 1 ) + 2, 0, TILEW - 1, ( TILEH >> 1 ) - 2, makecol( 255, 255, 0 ) );
90 floodfill( ( *map ) -> mousemap, TILEW - 1, 0, makecol( 255, 255, 0 ) );
93 line( ( *map ) -> colortile, 0, ( TILEH >> 1 ) - 2, ( TILEW >> 1 ) - 3, 0, makecol( 255, 0, 255 ) );
94 floodfill( ( *map ) -> colortile, 1, 1, makecol( 255, 0, 255 ) );
96 line( ( *map ) -> colortile, ( TILEW >> 1 ) - 3, TILEH - 1, 0, ( TILEH >> 1 ) + 1, makecol( 255, 0, 255 ) );
97 floodfill( ( *map ) -> colortile, 1, TILEH - 2, makecol( 255, 0, 255 ) );
99 line( ( *map ) -> colortile, ( TILEW >> 1 ) + 2, TILEH - 1, TILEW - 1, ( TILEH >> 1 ) + 1, makecol( 255, 0, 255 ) );
100 floodfill( ( *map ) -> colortile, TILEW - 2, TILEH - 1, makecol( 255, 0, 255 ) );
102 line( ( *map ) -> colortile, ( TILEW >> 1 ) + 2, 0, TILEW - 1, ( TILEH >> 1 ) - 2, makecol( 255, 0, 255 ) );
103 floodfill( ( *map ) -> colortile, TILEW - 1, 0, makecol( 255, 0, 255 ) );
105 ( *map ) -> ptanchorX = ( *map ) -> X = 0 ;
106 ( *map ) -> ptanchorY = ( *map ) -> Y = 0 ;
124 if ( !map || x >= map -> XSIZE || y >= map -> YSIZE )
130 map -> grid[ x + y * map -> XSIZE ] . tilenumber = value ;
138 map -> grid[ x + y * map -> XSIZE ] . ability = value ;
146 map -> grid[ x + y * map -> XSIZE ] . music = value ;
154 map -> grid[ x + y * map -> XSIZE ] . objectnumber = value ;
176 if ( !map || x >= map -> XSIZE || y >= map -> YSIZE )
181 return map -> grid[ x + y * map -> XSIZE ] . tilenumber ;
184 return map -> grid[ x + y * map -> XSIZE ] . objectnumber ;
187 return map -> grid[ x + y * map -> XSIZE ] . music ;
190 return map -> grid[ x + y * map -> XSIZE ] . ability ;
207int ScreenToMap(
int mx,
int my,
int *Tilex,
int *Tiley, BITMAP *mousemap )
211 int RegionX, RegionY,
212 RegionDX = 0, RegionDY = 0,
213 MouseMapX, MouseMapY,
214 MouseMapWidth, MouseMapHeight, c;
216 MouseMapWidth = mousemap -> w;
217 MouseMapHeight = mousemap -> h;
220 RegionX = ( mx / MouseMapWidth );
221 RegionY = ( my / MouseMapHeight ) << 1;
226 MouseMapX = mx % MouseMapWidth;
227 MouseMapY = my % MouseMapHeight;
230 c = getpixel( mousemap, MouseMapX, MouseMapY );
232 if ( c == makecol( 255, 0, 0 ) )
238 if ( c == makecol( 255, 255, 0 ) )
244 if ( c == makecol( 255, 255, 255 ) )
250 if ( c == makecol( 0, 255, 0 ) )
256 if ( c == makecol( 0, 0, 255 ) )
262 *Tilex = ( RegionDX + RegionX );
263 *Tiley = ( RegionDY + RegionY );
286 ( *map ) -> X = x % ( *map ) ->TILEW;
287 ( *map ) -> Y = y % ( *map ) ->TILEH;
288 ( *map ) -> ptanchorY = y / ( ( *map ) ->TILEH >> 1 );
289 ( *map ) -> ptanchorY = ( *map ) -> ptanchorY >> 1;
290 ( *map ) -> ptanchorY = ( *map ) -> ptanchorY << 1;
291 ( *map ) -> ptanchorX = ( x + ( ( *map ) -> ptanchorY & 1 ) * ( ( *map ) ->TILEW >> 1 ) ) / ( *map ) ->TILEW;
310 ( *map ) -> ptanchorX = tx;
311 ( *map ) -> ptanchorY = ty;
329int draw_map(
MAP *map, BITMAP *bmp,
int destx,
int desty,
int mode )
338 tw = 1 + ( ( bmp -> w - destx ) / map -> TILEW ) ;
339 th = 3 + ( ( bmp -> h - desty ) / ( map -> TILEH >> 1 ) ) ;
341 TW2 = map -> TILEW>>1 ;
342 TH2 = map -> TILEH>>1 ;
344 mvx = destx - TW2 - map -> X;
345 mvy = desty - TH2 - map -> Y;
347 for ( a = 0 ; a <= tw ; a++ )
349 for ( b = 0 ; b <= th ; b++ )
353 x = ( a * map -> TILEW + ( ( b & 1 ) * TW2 ) ) - ( map -> TILEW >> 1 ) + mvx;
354 y = ( b * TH2 ) + mvy;
356 if ( ( a + map -> ptanchorX ) < map->
XSIZE && ( b + map -> ptanchorY ) < map->
YSIZE )
359 if ( map -> grid [ a + map -> ptanchorX + ( b + map -> ptanchorY ) * map->
XSIZE ] . tilenumber == FALSE )
362 masked_blit( map -> colortile, bmp, 0, 0, x, y, map -> colortile -> w, map -> colortile -> h );
370 triangle( bmp, x, y + ( map -> TILEH >> 1 ), x + map-> TILEW, y + ( map->
TILEH >> 1 ), x + ( map -> TILEW >> 1 ), y, makecol( 255, 255, 0 ) );
371 triangle( bmp, x, y + ( map -> TILEH >> 1 ), x + map-> TILEW, y + ( map->
TILEH >> 1 ), x + ( map -> TILEW >> 1 ), y + map -> TILEH, makecol( 255, 0, 255 ) );
378 line( bmp, x + ( map -> TILEW >> 1 ) - 2, y, x, y + ( map -> TILEH >> 1 ) - 1, map -> wirecolor );
379 line( bmp, x + ( map -> TILEW >> 1 ) - 2, y + map -> TILEH - 1, x, y + ( map -> TILEH >> 1 ), map -> wirecolor );
380 line( bmp, x + ( map -> TILEW >> 1 ) + 1, y + map -> TILEH - 1, x + map -> TILEW - 1, y + ( map -> TILEH >> 1 ), map -> wirecolor );
381 line( bmp, x + ( map -> TILEW >> 1 ) + 1, y, x + map -> TILEW - 1, y + ( map -> TILEH >> 1 ) - 1, map -> wirecolor );
419 char temp_name[1024];
423 int it = 0, it1 = 0 ;
425 loaded = pack_fopen( filename,
"rb" );
433 it = pack_igetl( loaded );
435 pack_fread( temp_name, it, loaded );
438 temp_map . XSIZE = pack_igetl( loaded );
439 temp_map . YSIZE = pack_igetl( loaded );
440 temp_map . TILEW = pack_igetl( loaded );
441 temp_map . TILEH = pack_igetl( loaded );
442 temp_map . ptanchorX = pack_igetl( loaded );
443 temp_map . ptanchorY = pack_igetl( loaded );
444 temp_map . X = pack_igetl( loaded );
445 temp_map . Y = pack_igetl( loaded );
446 temp_map . bgcolor = pack_igetl( loaded );
447 temp_map . wirecolor = pack_igetl( loaded );
450 temp_map . XSIZE, temp_map . YSIZE,
451 temp_map . TILEW, temp_map . TILEH,
452 2000, 2000, 2000, 2000,2000 );
453 (*map ) -> XSIZE = temp_map . XSIZE ;
454 (*map ) -> YSIZE = temp_map . YSIZE ;
455 (*map ) -> TILEW = temp_map . TILEW ;
456 (*map ) -> TILEH = temp_map . TILEH ;
457 (*map ) -> ptanchorX = temp_map . ptanchorX ;
458 (*map ) -> ptanchorY = temp_map . ptanchorY ;
459 (*map ) -> X = temp_map . X ;
460 (*map ) -> Y = temp_map . Y ;
461 (*map ) ->
bgcolor = temp_map . bgcolor ;
462 (*map ) ->
wirecolor = temp_map . wirecolor ;
466 for( it = 0 ; it < (*map ) -> XSIZE ; it ++ )
468 for( it1 = 0 ; it1 < (*map ) -> YSIZE ; it1 ++ )
470 (*map ) -> grid[ it + it1 * (*map ) -> XSIZE ] . tilenumber = pack_igetl( loaded );
471 (*map ) -> grid[ it + it1 * (*map ) -> XSIZE ] . ability = pack_igetl( loaded );
472 (*map ) -> grid[ it + it1 * (*map ) -> XSIZE ] . objectnumber = pack_igetl( loaded );
473 (*map ) -> grid[ it + it1 * (*map ) -> XSIZE ] . music = pack_igetl( loaded );
480 pack_fclose( loaded );
499 int it = 0, it1 = 0 ;
501 saved = pack_fopen( filename,
"wb" );
504 pack_iputl( ustrsizez( map -> name ), saved );
505 pack_fwrite( map -> name, ustrsizez( map -> name ), saved );
508 pack_iputl( map -> XSIZE, saved );
509 pack_iputl( map -> YSIZE, saved );
510 pack_iputl( map -> TILEW, saved );
511 pack_iputl( map -> TILEH, saved );
512 pack_iputl( map -> ptanchorX, saved );
513 pack_iputl( map -> ptanchorY, saved );
514 pack_iputl( map -> X, saved );
515 pack_iputl( map -> Y, saved );
516 pack_iputl( map -> bgcolor, saved );
517 pack_iputl( map -> wirecolor, saved );
520 for( it = 0 ; it < map -> XSIZE ; it ++ )
522 for( it1 = 0 ; it1 < map -> YSIZE ; it1 ++ )
524 pack_iputl( map -> grid[ it + it1 * map -> XSIZE ] . tilenumber, saved );
525 pack_iputl( map -> grid[ it + it1 * map -> XSIZE ] . ability, saved );
526 pack_iputl( map -> grid[ it + it1 * map -> XSIZE ] . objectnumber, saved );
527 pack_iputl( map -> grid[ it + it1 * map -> XSIZE ] . music, saved );
534 pack_fclose( saved );
554 Free( ( *map ) -> grid );
558 Free( ( *map ) -> name );
560 if( (*map) -> colortile )
561 destroy_bitmap( ( *map ) -> colortile );
562 if( (*map) -> mousemap )
563 destroy_bitmap( ( *map ) -> mousemap );
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define Free(__ptr)
Free Handler to get errors.
int wirecolor
color of wire
int TILEH
size Y of tiles of the map (in pixel)
int YSIZE
size Y of the grid (nbYcell)
int XSIZE
size X of the grid (nbXcell)
int bgcolor
color of the bg
int save_map(MAP *map, char *filename)
Save the map to filename.
int get_value(MAP *map, int type, int x, int y)
Get a the tilenumber of a cell item.
int load_map(MAP **map, char *filename)
Load the map from filename.
int camera_to_map(MAP **map, int tx, int ty, int x, int y)
Center Map on given map coordinate, with x & y offset.
#define N_OBJECT
FLAG of object type.
int camera_to_scr(MAP **map, int x, int y)
Center Map on given screen coordinate.
int set_value(MAP *map, int type, int x, int y, int value)
Set the value of a cell in a map.
#define N_MUSIC
FLAG of music type.
#define N_TILE
FLAG of tile type.
#define N_ABILITY
FLAG of ability type.
int draw_map(MAP *map, BITMAP *bmp, int destx, int desty, int mode)
Draw a MAP *map on the BITMAP *bmp.
int ScreenToMap(int mx, int my, int *Tilex, int *Tiley, BITMAP *mousemap)
Convert screen coordinate to map coordinate.
int free_map(MAP **map)
Free the map.
int create_empty_map(MAP **map, char *name, int XSIZE, int YSIZE, int TILEW, int TILEH, int nbmaxobjects, int nbmaxgroup, int nbmaxanims, int nbtiles, int nbanims)
Create an empty map.
MAP with objects, tiles, skins.
Map loading, saving, with objects, animations, ...