void Enemy_Handler::LoadEnemies( Game_Renderer* renderer, Map& map ) { //Delete all of the data before clearing for( int i = 0; i < enemies.size(); i++ ) delete enemies[ i ]; enemies.clear(); for( int y = 0; y < map.GetMapTileHeight(); y++ ) { for( int x = 0; x < map.GetMapTileWidth(); x++ ) { switch( map.GetEnemy( x, y ) ) { case Map::NONE: break; case Map::CORGI: enemies.push_back( new Enemy_Corgi( renderer, map.GetTileDest( x, y ).x, map.GetTileDest( x, y ).y - 64 ) ); break; case Map::GREYHOUND: enemies.push_back( new Enemy_GreyHound( renderer, map.GetTileDest( x, y ).x, map.GetTileDest( x, y ).y - 64 ) ); break; case Map::HUSKY: enemies.push_back( new Enemy_Husky( renderer, map.GetTileDest( x, y ).x, map.GetTileDest( x, y ).y - 64 ) ); break; case Map::SHIBA: enemies.push_back( new Enemy_Shiba( renderer, map.GetTileDest( x, y ).x, map.GetTileDest( x, y ).y - 64 ) ); break; case Map::BULLDOG: enemies.push_back( new Enemy_Bulldog( renderer, map.GetTileDest( x, y ).x, map.GetTileDest( x, y ).y - 64 ) ); break; } } } }
void Corgi_Physics::Move( Component_Game_Actor& actor, Map &map, float timeStep ) { int previousx = tempNewX; int previousy = tempNewY; //Temporary holdings for the speeds tempNewX += (int)xVelocity * timeStep; tempNewY += (int)yVelocity * timeStep; actorBox.x = tempNewX; actorBox.y = tempNewY; //moving right if( xVelocity > 0 ) { //Check out of bounds right if( tempNewX + actorBox.w < map.GetMapWidth() ) { //Get the tile where the actor is xTile = ( tempNewX + actorBox.w ) / TILE_SIZE; yTile = tempNewY / TILE_SIZE; int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE; //int botTile = ( tempNewY + actorBox.h - 1 ) / TILE_SIZE; //Check the tile just to the right if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) { //Check box collision for all tiles in front of the character. if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; StopX(); SetXVelocity( NEGATIVE_MOVEMENT ); } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; StopX(); SetXVelocity( NEGATIVE_MOVEMENT ); } /*else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; } */ } } else { tempNewX = map.GetMapWidth() - actor.GetGraphics()->GetDestination().w - TILE_SIZE; StopX(); SetXVelocity( NEGATIVE_MOVEMENT ); } } //moving left else if( xVelocity < 0 ) { //Check out of bounds left if( tempNewX > 0 ) { //Get the tile where the actor is xTile = tempNewX / TILE_SIZE; yTile = tempNewY / TILE_SIZE; int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE; //int botTile = ( tempNewY + actorBox.h - 1) / TILE_SIZE; //Check the tile just to the right if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) { //Check box collision for all tiles in front of the character.a if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; StopX(); SetXVelocity( POSITIVE_MOVEMENT ); } else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; StopX(); SetXVelocity( POSITIVE_MOVEMENT ); }/* else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) { actorBox.x = previousx; tempNewX = previousx; } */ } } else { tempNewX = 0; StopX(); SetXVelocity( POSITIVE_MOVEMENT ); } } //Falling //if( yVelocity > 0 ) { //Check bounds bottom if( tempNewY + actor.GetGraphics()->GetDestination().h < SCREEN_HEIGHT ) { // left side of the sprite underneath yTile = ( tempNewY + actorBox.h ) / TILE_SIZE; xTile = tempNewX / TILE_SIZE; //middle underneath int midX = ( tempNewX + ( actorBox.w / 2 ) ) / TILE_SIZE; // right side of the sprite underneath int rightX = ( tempNewX + actorBox.w ) / TILE_SIZE; //Check both undersides of the sprite to see if it should stop falling if( map.GetCollision( xTile, yTile ) || map.GetCollision( rightX, yTile ) || map.GetCollision( midX, yTile ) ) { if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) { actor.SetState( ACTOR_STAND ); jumpTotal = 0; tempNewY = map.GetTileDest( xTile, yTile ).y - actorBox.h; actorBox.y = tempNewY; StopY(); } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( rightX, yTile ), actorBox ) ) { actor.SetState( ACTOR_STAND ); jumpTotal = 0; tempNewY = map.GetTileDest( rightX, yTile ).y - actorBox.h; actorBox.y = tempNewY; StopY(); } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( midX, yTile ), actorBox ) ) { actor.SetState( ACTOR_STAND ); jumpTotal = 0; tempNewY = map.GetTileDest( midX, yTile ).y - actorBox.h; actorBox.y = tempNewY; StopY(); } } else { yVelocity = MAX_FALL; } //Check bounds top } else if( tempNewY < 0 ) { tempNewY = 0; StopY(); } //} //Jumping up if( tempNewY < 0 ) { tempNewY = 0; StopY(); } actor.GetGraphics()->SetDestinationX( tempNewX ); actor.GetGraphics()->SetDestinationY( tempNewY ); }