r_boolean M_P_CheckForCollision( pPlayer_t pP , pMap_t pMap ){ pVect2_t pPlayerPosition = &pP->ent.position; // first determine where to sample the tile set from. int mapRow = pMap->position.y >> 5; int mapCol = pMap->position.x >> 5; // now determine where player is in relation to normalized map coords. int playerRow = pPlayerPosition->y >> 5; int playerCol = pPlayerPosition->x >> 5; // sample tiles in moveable ( 4 ) directions around player , and the concurrent location int tileRefs[] = { 0 , 0 , 0 , 0 , 0 }; // conc up down left right TileType tileTypes[] = { TILE_TYPE_BACKGROUND , TILE_TYPE_BACKGROUND , TILE_TYPE_BACKGROUND , TILE_TYPE_BACKGROUND , TILE_TYPE_BACKGROUND }; r_boolean solidTiles[] = { r_false , r_false , r_false , r_false , r_false }; // get the tile references for all the surrounding tiles tileRefs[ MAP_DIRECTION_NULL ] = pMap->mapTiles[ mapRow + playerRow ][ mapCol + playerCol ]; tileRefs[ MAP_DIRECTION_UP ] = pMap->mapTiles[ (mapRow + playerRow) - 1 ][ mapCol + playerCol ]; tileRefs[ MAP_DIRECTION_DOWN ] = pMap->mapTiles[ (mapRow + playerRow) + 1 ][ mapCol + playerCol ]; tileRefs[ MAP_DIRECTION_LEFT ] = pMap->mapTiles[ mapRow + playerRow ][ (mapCol + playerCol) - 1 ]; tileRefs[ MAP_DIRECTION_RIGHT ] = pMap->mapTiles[ mapRow + playerRow ][ (mapCol + playerCol) + 1 ]; // ... based on the above , get the types of the surrounding tiles... tileTypes[ MAP_DIRECTION_NULL ] = pMap->tiles[ tileRefs[0] ].attribs.type;tileTypes[ MAP_DIRECTION_UP ] = pMap->tiles[ tileRefs[1] ].attribs.type;tileTypes[ MAP_DIRECTION_DOWN ] = pMap->tiles[ tileRefs[2] ].attribs.type; tileTypes[ MAP_DIRECTION_LEFT ] = pMap->tiles[ tileRefs[3] ].attribs.type;tileTypes[ MAP_DIRECTION_RIGHT ] = pMap->tiles[ tileRefs[4] ].attribs.type; // ... now check to see if there are any solid tiles solidTiles[ MAP_DIRECTION_NULL ] = pMap->tiles[ tileRefs[0] ].attribs.solid;solidTiles[ MAP_DIRECTION_UP ] = pMap->tiles[ tileRefs[1] ].attribs.solid;solidTiles[ MAP_DIRECTION_DOWN ] = pMap->tiles[ tileRefs[2] ].attribs.solid;solidTiles[ MAP_DIRECTION_LEFT ] = pMap->tiles[ tileRefs[3] ].attribs.solid;solidTiles[ MAP_DIRECTION_RIGHT ]= pMap->tiles[ tileRefs[4] ].attribs.solid; // Check for collison with solid tiles. for( int direction = 0;direction < MAP_DOF;direction++ ) { if( solidTiles[ direction ] ) { switch( direction ) { case MAP_DIRECTION_NULL: // concurrent { break; } case MAP_DIRECTION_UP: { pP->directions.up = r_false; break; } case MAP_DIRECTION_DOWN: { pP->directions.down = r_false; break; } case MAP_DIRECTION_LEFT: { pP->directions.left = r_false; break; } case MAP_DIRECTION_RIGHT: { pP->directions.right = r_false; break; } } if( Ent_TestForCollision( &pP->ent , &pMap->tiles[ tileRefs[ direction ] ].ent ) ) { Ent_InflictDamage( pP , &pMap->tiles[ tileRefs[ direction ] ].ent , r_false , r_true ); } } else { switch( direction ) { case MAP_DIRECTION_NULL: { pP->directions.up = pP->directions.down = pP->directions.left = pP->directions.right = r_false; break; } case MAP_DIRECTION_UP: { pP->directions.up = r_true; break; } case MAP_DIRECTION_DOWN: { pP->directions.down = r_true; break; } case MAP_DIRECTION_LEFT: { pP->directions.left = r_true; break; } case MAP_DIRECTION_RIGHT: { pP->directions.right = r_true; break; } } } } return pP->ent.collided;}
It still only operates in 4 dof , but it needs to do so in 8 dof.
Still haven't gotten the parallax stuff working yet , but I have decided to start on the sprites so this should be an exciting week.