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 { typedef struct {
SDL_Rect bounds;
float shakeAmount; float shakeAmount;
int x; int x;
int y; int y;

View File

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

View File

@ -84,10 +84,8 @@ float cameraChase(Entity *e, int maxSpeed)
void clip(void) void clip(void)
{ {
camera.bounds.x = (int) limit(camera.x, world.map.bounds.x, world.map.bounds.w); camera.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.y = (int) limit(camera.y, world.map.bounds.y, world.map.bounds.h);
camera.bounds.w = SCREEN_WIDTH;
camera.bounds.h = SCREEN_HEIGHT;
} }
int isOnScreen(Entity *e) int isOnScreen(Entity *e)