Esempio n. 1
0
void CArena::Draw(CWindow *theWindow)
{
    // Center the view on the player
    CView theOriginalView = CView(theWindow->getView());
    CView theView = theOriginalView;
    
    CVector2f viewSize = theView.getSize();
    CVector2f viewCenter;
    viewCenter.x = mPlayer->GetPosition().x;
    viewCenter.y = mPlayer->GetPosition().y;
    
    float minmaxPixel = (mArenaSize / 2.0f) + 150.0f;
    float rightmostPixel = viewCenter.x + (viewSize.x / 2.0f);
    float leftmostPixel = viewCenter.x - (viewSize.x / 2.0f);
    if (rightmostPixel > minmaxPixel)
    {
        float offset = rightmostPixel - minmaxPixel;
        viewCenter.x -= offset;
    }
    if (leftmostPixel < -minmaxPixel)
    {
        float offset = -minmaxPixel - leftmostPixel;
        viewCenter.x += offset;
    }
    float topmostPixel = viewCenter.y - (viewSize.y / 2.0f);
    float bottommostPixel = viewCenter.y + (viewSize.y / 2.0f);
    if (bottommostPixel > minmaxPixel)
    {
        float offset = bottommostPixel - minmaxPixel;
        viewCenter.y -= offset;
    }
    if (topmostPixel < -minmaxPixel)
    {
        float offset = -minmaxPixel - topmostPixel;
        viewCenter.y += offset;
    }
    
    theView.setCenter(viewCenter);
    theWindow->setView(theView);
    
    // Draw static objects
    for (CGameObject *theObject : mStaticObjects)
    {
        theObject->Draw(theWindow);
    }
    
    // Draw floor pattern
    int interval = 50;
    for (int xy = interval - 500; xy < 500; xy += interval)
    {
        CLine theHorizontalLine = CLine(CVector2f(-500, xy), CVector2f(500, xy));
        CLine theVerticalLine = CLine(CVector2f(xy, -500), CVector2f(xy, 500));
        theWindow->DrawLine(theHorizontalLine, CColour::Black);
        theWindow->DrawLine(theVerticalLine, CColour::Black);
    }
    
    // Draw dynamic objects
    for (CGameObject *theObject : mObjects)
    {
        theObject->Draw(theWindow);
    }
    
    theWindow->setView(theOriginalView);
}