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)
This commit is contained in:
parent
f83d3e7785
commit
2f2a02f4f8
19
2048.c
19
2048.c
|
@ -55,6 +55,8 @@ typedef struct findFarthestPosition_return {
|
||||||
Cell farthest;
|
Cell farthest;
|
||||||
} findFarthestPosition_return;
|
} findFarthestPosition_return;
|
||||||
|
|
||||||
|
#define SCREEN_ANIMATION_TIME 32
|
||||||
|
|
||||||
int Game_score = 0;
|
int Game_score = 0;
|
||||||
bool Game_over = false;
|
bool Game_over = false;
|
||||||
bool Game_won = false;
|
bool Game_won = false;
|
||||||
|
@ -259,17 +261,19 @@ bool Game_isGameTerminated() { // Intentionally moved here
|
||||||
|
|
||||||
void Screen_actuate() {
|
void Screen_actuate() {
|
||||||
|
|
||||||
float i;
|
int animationStartTime;
|
||||||
|
float animationLength;
|
||||||
|
|
||||||
Screen_drawFixedTiles(true);
|
Screen_drawFixedTiles(true);
|
||||||
|
|
||||||
SaveDisp(SAVEDISP_PAGE1);
|
SaveDisp(SAVEDISP_PAGE1);
|
||||||
|
|
||||||
for (i = 0; i <= 1; i += 0.02) {
|
animationStartTime = RTC_getTicks();
|
||||||
|
do {
|
||||||
|
animationLength = RTC_getTicks() - animationStartTime;
|
||||||
RestoreDisp(SAVEDISP_PAGE1);
|
RestoreDisp(SAVEDISP_PAGE1);
|
||||||
Screen_drawMovingTiles(i);
|
Screen_drawMovingTiles(animationLength/SCREEN_ANIMATION_TIME);
|
||||||
ML_display_vram();
|
ML_display_vram();
|
||||||
}
|
} while (animationLength <= SCREEN_ANIMATION_TIME);
|
||||||
|
|
||||||
RestoreDisp(SAVEDISP_PAGE1);
|
RestoreDisp(SAVEDISP_PAGE1);
|
||||||
Screen_drawFixedTiles(false);
|
Screen_drawFixedTiles(false);
|
||||||
|
@ -484,7 +488,6 @@ int initGame() {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
// Reset variables
|
// Reset variables
|
||||||
srand(RTC_getTicks());
|
|
||||||
Game_score = 0;
|
Game_score = 0;
|
||||||
Game_over = false;
|
Game_over = false;
|
||||||
Game_won = false;
|
Game_won = false;
|
||||||
|
@ -499,8 +502,6 @@ int initGame() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ML_clear_screen();
|
|
||||||
|
|
||||||
// Draw Title
|
// Draw Title
|
||||||
PrintXY(67, 54, "2048", 0);
|
PrintXY(67, 54, "2048", 0);
|
||||||
|
|
||||||
|
@ -523,6 +524,8 @@ int AddIn_main(int isAppli, unsigned short OptionNum) {
|
||||||
// Variables
|
// Variables
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
|
|
||||||
|
srand(RTC_getTicks());
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
while (1) { // Main loop
|
while (1) { // Main loop
|
||||||
GetKey(&key);
|
GetKey(&key);
|
||||||
|
|
Reference in a new issue