camera.c
/* camera update - follow sprite passed below */
camera update - follow sprite passed below
camera update - follow sprite passed below
void followSprite(struct SPRITE *s)
{
    updateHitbox(&camera);
    newHitbox(&upper, camera.left, camera.y, camera.width, verticalSideHeight);
    newHitbox(&lower, camera.left, camera.y + camera.height - verticalSideHeight, camera.width, verticalSideHeight);
    newHitbox(&left, camera.left, camera.y - camera.height, horizontalSideWidth, camera.height * 3);
    newHitbox(&right, camera.right - horizontalSideWidth, camera.y - camera.height, horizontalSideWidth, camera.height * 3);
    if (!checkCollide(s->box, upper) && !preventCameraDown) {
        camera.y = camera.y + fabsf(s->GetVY(s));
        if (fabsf(s->GetVY(s)) < 0.1)
            camera.y = camera.y + s->GetMaxSpeedY(s);
    }
    if (!checkCollide(s->box, lower) && !preventCameraUp) {
        camera.y = camera.y - fabsf(s->GetVY(s));
        if (fabsf(s->GetVY(s)) < 0.1)
            camera.y = camera.y - s->GetMaxSpeedY(s);
    }
    if (!checkCollide(s->box, left) && !preventCameraRight) {
        camera.x = camera.x + fabsf(s->GetVX(s));
        if (!s->GetVX(s))
            camera.x = camera.x + s->GetMaxSpeedX(s);
    }
    if (!checkCollide(s->box, right) && !preventCameraLeft) {
        camera.x = camera.x - fabsf(s->GetVX(s));
        if (!s->GetVX(s))
            camera.x = camera.x - s->GetMaxSpeedX(s);
    }
    updateHitbox(&camera);
    if (camera.x < 0) {
        camera.x = 0;
    }
    if (camera.y < 0) {
        camera.y = 0;
    }
    if (camera.x + camera.width > boundx) {
        camera.x = boundx - camera.width;
    }
    if (camera.y + camera.height > boundy) {
        camera.y = boundy - camera.height;
    }
    updateHitbox(&camera);
}
void followSprite ( struct SPRITE * s ) { updateHitbox ( & camera ) ; newHitbox ( & upper , camera . left , camera . y , camera . width , verticalSideHeight ) ; newHitbox ( & lower , camera . left , camera . y + camera . height - verticalSideHeight , camera . width , verticalSideHeight ) ; newHitbox ( & left , camera . left , camera . y - camera . height , horizontalSideWidth , camera . height * 3 ) ; newHitbox ( & right , camera . right - horizontalSideWidth , camera . y - camera . height , horizontalSideWidth , camera . height * 3 ) ; if ( ! checkCollide ( s -> box , upper ) && ! preventCameraDown ) { camera . y = camera . y + fabsf ( s -> GetVY ( s ) ) ; if ( fabsf ( s -> GetVY ( s ) ) < 0.1 ) camera . y = camera . y + s -> GetMaxSpeedY ( s ) ; } if ( ! checkCollide ( s -> box , lower ) && ! preventCameraUp ) { camera . y = camera . y - fabsf ( s -> GetVY ( s ) ) ; if ( fabsf ( s -> GetVY ( s ) ) < 0.1 ) camera . y = camera . y - s -> GetMaxSpeedY ( s ) ; } if ( ! checkCollide ( s -> box , left ) && ! preventCameraRight ) { camera . x = camera . x + fabsf ( s -> GetVX ( s ) ) ; if ( ! s -> GetVX ( s ) ) camera . x = camera . x + s -> GetMaxSpeedX ( s ) ; } if ( ! checkCollide ( s -> box , right ) && ! preventCameraLeft ) { camera . x = camera . x - fabsf ( s -> GetVX ( s ) ) ; if ( ! s -> GetVX ( s ) ) camera . x = camera . x - s -> GetMaxSpeedX ( s ) ; } updateHitbox ( & camera ) ; if ( camera . x < 0 ) { camera . x = 0 ; } if ( camera . y < 0 ) { camera . y = 0 ; } if ( camera . x + camera . width > boundx ) { camera . x = boundx - camera . width ; } if ( camera . y + camera . height > boundy ) { camera . y = boundy - camera . height ; } updateHitbox ( & camera ) ; }
camera update - follow sprite passed below
camera update - follow sprite passed below
/* calculate deadzone */ /* fix camera in case sprite goes outside of dead zone */ /* clip camera to level bounds */