Smooth camera

This commit is contained in:
Cong 2017-05-25 23:50:27 +10:00
parent 960da014b0
commit 71665c2afb
1 changed files with 6 additions and 2 deletions

View File

@ -218,8 +218,12 @@ static void draw(void)
{ {
if (player->alive == ALIVE_ALIVE) if (player->alive == ALIVE_ALIVE)
{ {
battle.camera.x = player->x - (SCREEN_WIDTH / 2) + ((app.mouse.x - (SCREEN_WIDTH / 2)) / 4); float targetX, targetY;
battle.camera.y = player->y - (SCREEN_HEIGHT / 2) + ((app.mouse.y - (SCREEN_HEIGHT / 2)) / 4); targetX = player->x - (SCREEN_WIDTH / 2) + ((app.mouse.x - (SCREEN_WIDTH / 2)) / 4);
targetY = player->y - (SCREEN_HEIGHT / 2) + ((app.mouse.y - (SCREEN_HEIGHT / 2)) / 4);
/* Smoothly follow target using lerp */
battle.camera.x += (targetX - battle.camera.x) * 0.1f;
battle.camera.y += (targetY - battle.camera.y) * 0.1f;
} }
drawBackground(battle.background); drawBackground(battle.background);