Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » mappy and collision removal

This thread is locked; no one can reply to it. rss feed Print
mappy and collision removal
rxtype
Member #8,352
February 2007

hey, ive searched the forums and found a lot of questions and answers relating to mappy, but i couldnt find anything that solves my problem.

i have a map made with mappy, with 3 different block types.
1- land, walkable.
2- grass, collision, non walkable. BUT can be removed so that it is walkable.
3- rock, collision, non walkable.

here is a sample map
333333333
121212121
333333333

the player starts off on the left side and needs to make it across to the right side.
and in order to do that, the player needs to remove the grass by hitting a key (SPACE for example) so that he can make his way across.

now my problem arise, how do i code it so that SPACE removes the grass and changes it to a normal block 1(land)?

thanks

Jeff Bernard
Member #6,698
December 2005
avatar

You've got an array on intetegers, right? (I've never used Mappy). Just change the value:

if (tile_that_is_faced_is(2) // if you are facing the grass tile
    && key[KEY_SPACE]) // if you press the space key
{
       map[that_tile] = 1; // change it to land
       update_map_graphics(that_tile, 1); // if you need run a special function to change that tile
}

--
I thought I was wrong once, but I was mistaken.

rxtype
Member #8,352
February 2007

nope, its not on an array, the map is actually loaded as a .fmp file..

William Labbett
Member #4,486
March 2004
avatar

I can't really help but perhaps the .fmp file format wasn't really meant to be writable. You either need to find out how to change the info in the .fmp which might require some help from whoever wrote mappy or write your own level editor which for the type of thing you're doing is dead easy :-

For example you could have a little bitmap. Choose a colour for each tile type you have. Load the bitmap. Declare a 2D array tiles[MAP_WIDTH][MAP_HEIGHT] then read the bitmap and write the array :

1enum tile_types{ LAND, GRASS, ROCKS };
2 
3 
4....
5for(x = 0; x < MAP_WIDTH; ++x)
6 for(y = 0; y < MAP_HEIGHT; ++y)
7 {
8 colour = getpixel(level_bitmap, x, y);
9
10 tiles[x][y] = get_tile_type(colour);
11 }
12....
13 
14int get_tile_type(colour)
15{
16 if(colour == makecol(............)) /* colour for land */
17 return LAND;
18 else if(colour == makecol(........)) /* colour for grass */
19 return GRASS;
20 else if(colour == makecol(....)) /* colour for ROCKS */
21 return ROCKS;
22}

then you've got an array with the type of tile in and you can change it's
elements by doing what Jeff said.

Sorry if that's patronising - maybe you're keen to make use of Mappy in which case you need to learn about the .fmp format so that you can copy the map info into an array like above.

rxtype
Member #8,352
February 2007

ok!
i figured it out, i had to use the method MapSetBlock, but now i have another question, which method am i suppose to use to retrieve a block id??
because i need to know if the block is grass or rock to determine if its removeable.

Go to: