Clip camera when observing entities.
This commit is contained in:
parent
a3a4c01049
commit
3b88f1c973
|
@ -435,7 +435,7 @@ static void handleWidgets(void)
|
||||||
|
|
||||||
static void doWorldObserving(void)
|
static void doWorldObserving(void)
|
||||||
{
|
{
|
||||||
int tx, ty;
|
int tx, ty, cx, cy;
|
||||||
float diffX, diffY;
|
float diffX, diffY;
|
||||||
|
|
||||||
tx = world.entityToTrack->x - (SCREEN_WIDTH / 2);
|
tx = world.entityToTrack->x - (SCREEN_WIDTH / 2);
|
||||||
|
@ -448,28 +448,36 @@ static void doWorldObserving(void)
|
||||||
|
|
||||||
diffX = MAX(3, MIN(50, diffX));
|
diffX = MAX(3, MIN(50, diffX));
|
||||||
diffY = MAX(3, MIN(50, diffY));
|
diffY = MAX(3, MIN(50, diffY));
|
||||||
|
|
||||||
|
cx = camera.x;
|
||||||
|
cy = camera.y;
|
||||||
|
|
||||||
if (camera.x > tx)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
camera.x = cx;
|
||||||
|
camera.y = cy;
|
||||||
|
|
||||||
|
clipCamera();
|
||||||
|
|
||||||
if (collision(camera.x, camera.y, MAP_TILE_SIZE, MAP_TILE_SIZE, tx, ty, MAP_TILE_SIZE, MAP_TILE_SIZE))
|
if (collision(cx, cy, MAP_TILE_SIZE, MAP_TILE_SIZE, tx, ty, MAP_TILE_SIZE, MAP_TILE_SIZE))
|
||||||
{
|
{
|
||||||
if (--world.observationTimer <= 0)
|
if (--world.observationTimer <= 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -115,6 +115,7 @@ extern void showWidgetGroup(char *group);
|
||||||
extern void startSectionTransition(void);
|
extern void startSectionTransition(void);
|
||||||
extern void stopMusic(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 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 App app;
|
||||||
extern Camera camera;
|
extern Camera camera;
|
||||||
|
|
Loading…
Reference in New Issue