From 2f2a02f4f8c781675fed0a424c52764072cdd338 Mon Sep 17 00:00:00 2001 From: GeoffreyFrogeye Date: Tue, 8 Apr 2014 21:25:29 +0200 Subject: [PATCH] Made animation rely on RTC_getTicks() Makes animation smoother, constant on every device and grid heavyness. Set at 0.25s (0.25*128=32 ticks) --- 2048.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/2048.c b/2048.c index eb783c2..78535be 100644 --- a/2048.c +++ b/2048.c @@ -55,6 +55,8 @@ typedef struct findFarthestPosition_return { Cell farthest; } findFarthestPosition_return; +#define SCREEN_ANIMATION_TIME 32 + int Game_score = 0; bool Game_over = false; bool Game_won = false; @@ -259,17 +261,19 @@ bool Game_isGameTerminated() { // Intentionally moved here void Screen_actuate() { - float i; + int animationStartTime; + float animationLength; Screen_drawFixedTiles(true); - SaveDisp(SAVEDISP_PAGE1); - for (i = 0; i <= 1; i += 0.02) { + animationStartTime = RTC_getTicks(); + do { + animationLength = RTC_getTicks() - animationStartTime; RestoreDisp(SAVEDISP_PAGE1); - Screen_drawMovingTiles(i); + Screen_drawMovingTiles(animationLength/SCREEN_ANIMATION_TIME); ML_display_vram(); - } + } while (animationLength <= SCREEN_ANIMATION_TIME); RestoreDisp(SAVEDISP_PAGE1); Screen_drawFixedTiles(false); @@ -484,7 +488,6 @@ int initGame() { int x, y; // Reset variables - srand(RTC_getTicks()); Game_score = 0; Game_over = false; Game_won = false; @@ -499,8 +502,6 @@ int initGame() { } } - ML_clear_screen(); - // Draw Title PrintXY(67, 54, "2048", 0); @@ -523,6 +524,8 @@ int AddIn_main(int isAppli, unsigned short OptionNum) { // Variables unsigned int key; + srand(RTC_getTicks()); + initGame(); while (1) { // Main loop GetKey(&key);