void CGamePlayState::GetCamera( int& X , int& Y )
{
    CBaseEntity* player = (CBaseEntity*)MObjectManager::GetInstance()->GetUnit( testVaribale );

    if( player )
    {
        X = (int)player->GetPosX() - 800/2 + 32;
        Y = (int)player->GetPosY() - 600/2 + 32;

        if( X + 800 > MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerWidth() * TILE_WIDTH )
            X = MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerWidth() * TILE_WIDTH - 800;

        if( Y + 600 > MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerHeight() * TILE_HEIGHT )
            Y = MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerHeight() * TILE_HEIGHT - 600;

        if( X < 0 )
            X = 0;

        if( Y < 0 )
            Y = 0;

    }
    return ;
}
void CGamePlayState::Render(void)
{
    CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();

    CBaseEntity* player = nullptr;
    if( testVaribale > 0 )
    {
        player = (CBaseEntity*)MObjectManager::GetInstance()->GetUnit( testVaribale );
    }
    else
    {
        cout << "No player to render\n";
    }

    if( player )
    {
        cameraX = (int)player->GetPosX() - 800/2 + 32;
        cameraY = (int)player->GetPosY() - 600/2 + 32;

        if( cameraX + 800 > MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerWidth() * TILE_WIDTH )
            cameraX = MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerWidth() * TILE_WIDTH - 800;

        if( cameraY + 600 > MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerHeight() * TILE_HEIGHT )
            cameraY = MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerHeight() * TILE_HEIGHT - 600;

        if( cameraX < 0 )
            cameraX = 0;

        if( cameraY < 0 )
            cameraY = 0;

        MObjectManager::GetInstance()->Render( cameraX, cameraY, MObjectManager::GetInstance()->FindLayer( testVaribale ).GetLayerID() );
    }
    else
    {
        MObjectManager::GetInstance()->Render( 0, 0, 0 );
    }


    //Draw the HUD
    CHUD::GetInstance()->Render();
    //pD3D->DrawTextA( "Gameplay State", 100, 100 );

    int mouseX = CSGD_DirectInput::GetInstance()->MouseGetPosX() ;
    int mouseY = CSGD_DirectInput::GetInstance()->MouseGetPosY() ;

    if( m_bDrawMouse )
        CSGD_TextureManager::GetInstance()->Draw( m_nMouseID , mouseX - 8 , mouseY - 2 ) ;

    MMessageSystem::GetInstance()->ProcessMessages();

    //char temp[64];

    //sprintf_s( temp, "%f", timestep );
    //sprintf( temp, "%f", timestep );

    //CSGD_Direct3D::GetInstance()->DrawTextA( temp, 100, 126 );

    //sprintf( temp, "%f", 1.0f / timestep );

    //CSGD_Direct3D::GetInstance()->DrawTextA( temp, 100, 164 );

    if( m_bIsOver )
    {
        int fade = int( 255 * ( m_fCountdown / 10.0f ) );

        if( fade > 255 )
            fade = 255;

        CSGD_TextureManager::GetInstance()->Draw( m_nIMG_Black, 0, 0, 1.0f, 1.0f, 0, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( fade, 255, 255, 255 ) );

        MetalText.Print( "But Now You Must Escape . . .", 800 / 2 - 256, 600 / 2, 0.5f );
    }
}