/* ----------------------------------------------------------------------------- Function: Parameters: Returns: returns true if move ok Notes: ----------------------------------------------------------------------------- */ PRIVATE _boolean PL_TryMove( player_t *self, LevelData_t *lvl ) { int xl, yl, xh, yh, x, y; int d, n; xl = POS2TILE( Player.position.origin[ 0 ] - PLAYERSIZE ); yl = POS2TILE( Player.position.origin[ 1 ] - PLAYERSIZE ); xh = POS2TILE( Player.position.origin[ 0 ] + PLAYERSIZE ); yh = POS2TILE( Player.position.origin[ 1 ] + PLAYERSIZE ); // Cheching for solid walls: for( y = yl ; y <= yh ; ++y ) for( x = xl ; x <= xh ; ++x ) { if( lvl->tilemap[ x ][ y ] & SOLID_TILE ) return 0; if( lvl->tilemap[ x ][ y ] & DOOR_TILE && Door_Opened( &lvl->Doors, x, y) != DOOR_FULLOPEN ) { // iphone hack to allow player to move halfway into door tiles // if the player bounds doesn't cross the middle of the tile, let the move continue if ( abs( Player.position.origin[0] - TILE2POS( x ) ) <= 0x9000 && abs( Player.position.origin[1] - TILE2POS( y ) ) <= 0x9000 ) { return 0; } } } // check for actors for( n = 0 ; n < NumGuards ; ++n ) { if( Guards[ n ].state >= st_die1 ) continue; d = self->position.origin[ 0 ] - Guards[ n ].x; if( d < -MINACTORDIST || d > MINACTORDIST ) continue; d = self->position.origin[ 1 ] - Guards[ n ].y; if( d < -MINACTORDIST || d > MINACTORDIST) continue; return false; } return true; }
/** * \brief Called when a player pressed the USE button * \param[in] self Player * \param[in] lvl Level data structure * \return true if move is successful, otherwise false. */ PUBLIC _boolean PL_TryMove( player_t *self, LevelData_t *lvl ) { int xl, yl, xh, yh, x, y; int d, n; xl = POS2TILE( Player.position.origin[ 0 ] - PLAYERSIZE ); yl = POS2TILE( Player.position.origin[ 1 ] - PLAYERSIZE ); xh = POS2TILE( Player.position.origin[ 0 ] + PLAYERSIZE ); yh = POS2TILE( Player.position.origin[ 1 ] + PLAYERSIZE ); // Cheching for solid walls: for( y = yl ; y <= yh ; ++y ) for( x = xl ; x <= xh ; ++x ) { if( lvl->tilemap[ x ][ y ] & SOLID_TILE ) return false; if( lvl->tilemap[ x ][ y ] & DOOR_TILE && Door_Opened( &lvl->Doors, x, y) != DOOR_FULLOPEN ) return false; } // check for actors for( n = 0 ; n < NumGuards ; ++n ) { if( Guards[ n ].state >= st_die1 ) continue; d = self->position.origin[ 0 ] - Guards[ n ].x; if( d < -MINACTORDIST || d > MINACTORDIST ) continue; d = self->position.origin[ 1 ] - Guards[ n ].y; if( d < -MINACTORDIST || d > MINACTORDIST) continue; return false; } return true; }