make get_pos more generic

This commit is contained in:
Gwenhael Le Moine 2011-07-04 09:12:58 +02:00
parent 5553ee3706
commit 630842effe

12
star.c
View file

@ -313,16 +313,16 @@ int count_gifts( struct state *s )
return n; return n;
} }
/* Write the position of the currently moving actor into pos /* Write the position of actor into pos
*/ */
void get_pos( struct state *s, int* pos ) void get_pos( struct state *s, int* pos, cell actor )
{ {
int p; int p;
p = (int)( strchr( s->board, s->moving ) - s->board ); p = (int)( strchr( s->board, actor ) - s->board );
pos[ 1 ] = p / LEVEL_WIDTH; pos[ 1 ] = p / LEVEL_WIDTH; /* y */
pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); /* x */
} }
/* Returns the content of cell( x, y ) of the current level /* Returns the content of cell( x, y ) of the current level
@ -372,7 +372,7 @@ void make_a_move( struct state *s, direction where )
{ {
int dx = 0, dy = 0, tmpx, tmpy, *item_coord; int dx = 0, dy = 0, tmpx, tmpy, *item_coord;
item_coord = malloc( sizeof( int ) * 2 ); item_coord = malloc( sizeof( int ) * 2 );
get_pos( s, item_coord ); get_pos( s, item_coord, s->moving );
tmpx = item_coord[ 0 ]; tmpx = item_coord[ 0 ];
tmpy = item_coord[ 1 ]; tmpy = item_coord[ 1 ];