Correctly limit camera.

This commit is contained in:
Steve 2018-01-31 08:37:01 +00:00
parent 81000d7948
commit 0d534d6ef8
3 changed files with 4 additions and 7 deletions

View File

@ -287,7 +287,6 @@ struct Tuple {
};
typedef struct {
SDL_Rect bounds;
float shakeAmount;
int x;
int y;

View File

@ -42,12 +42,12 @@ int getPercent(float current, float total)
float limit(float i, float a, float b)
{
if (i > a)
if (i < a)
{
return a;
}
if (i < b)
if (i > b)
{
return b;
}

View File

@ -84,10 +84,8 @@ float cameraChase(Entity *e, int maxSpeed)
void clip(void)
{
camera.bounds.x = (int) limit(camera.x, world.map.bounds.x, world.map.bounds.w);
camera.bounds.y = (int) limit(camera.y, world.map.bounds.y, world.map.bounds.h + (MAP_TILE_SIZE * 3));
camera.bounds.w = SCREEN_WIDTH;
camera.bounds.h = SCREEN_HEIGHT;
camera.x = (int) limit(camera.x, world.map.bounds.x, world.map.bounds.w);
camera.y = (int) limit(camera.y, world.map.bounds.y, world.map.bounds.h);
}
int isOnScreen(Entity *e)