Clip camera when observing entities.

This commit is contained in:
Steve 2018-03-04 09:49:31 +00:00
parent a3a4c01049
commit 3b88f1c973
2 changed files with 19 additions and 10 deletions

View File

@ -435,7 +435,7 @@ static void handleWidgets(void)
static void doWorldObserving(void)
{
int tx, ty;
int tx, ty, cx, cy;
float diffX, diffY;
tx = world.entityToTrack->x - (SCREEN_WIDTH / 2);
@ -449,27 +449,35 @@ static void doWorldObserving(void)
diffX = MAX(3, MIN(50, diffX));
diffY = MAX(3, MIN(50, diffY));
if (camera.x > tx)
cx = camera.x;
cy = camera.y;
if (cx > tx)
{
camera.x -= diffX;
cx -= diffX;
}
if (camera.x < tx)
if (cx < tx)
{
camera.x += diffX;
cx += diffX;
}
if (camera.y > ty)
if (cy > ty)
{
camera.y -= diffY;
cy -= diffY;
}
if (camera.y < ty)
if (cy < ty)
{
camera.y += diffY;
cy += diffY;
}
if (collision(camera.x, camera.y, MAP_TILE_SIZE, MAP_TILE_SIZE, tx, ty, MAP_TILE_SIZE, MAP_TILE_SIZE))
camera.x = cx;
camera.y = cy;
clipCamera();
if (collision(cx, cy, MAP_TILE_SIZE, MAP_TILE_SIZE, tx, ty, MAP_TILE_SIZE, MAP_TILE_SIZE))
{
if (--world.observationTimer <= 0)
{

View File

@ -115,6 +115,7 @@ extern void showWidgetGroup(char *group);
extern void startSectionTransition(void);
extern void stopMusic(void);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern void clipCamera(void);
extern App app;
extern Camera camera;