New impressive streak animation
This commit is contained in:
26
hangman.c
26
hangman.c
@@ -44,6 +44,7 @@ int main(int argc, char **argv) {
|
|||||||
gs->guesses = 0;
|
gs->guesses = 0;
|
||||||
gs->trollEnabled = 0;
|
gs->trollEnabled = 0;
|
||||||
hf->besthit = 0;
|
hf->besthit = 0;
|
||||||
|
hf->impstreakcounter = 0;
|
||||||
keypad(stdscr, FALSE);
|
keypad(stdscr, FALSE);
|
||||||
nonl(); //No new line. Prevents the new line when hitting enter
|
nonl(); //No new line. Prevents the new line when hitting enter
|
||||||
|
|
||||||
@@ -265,6 +266,7 @@ int playerInput(game_state *gs, hitfeed *hf) {
|
|||||||
//gs->moves++;
|
//gs->moves++;
|
||||||
gs->guesses++;
|
gs->guesses++;
|
||||||
trollHitScreen(gs, hf, found);
|
trollHitScreen(gs, hf, found);
|
||||||
|
trollHandleImpressive(hf, gs, found); //Prints a message with a little animation
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* no valid character found */
|
/* no valid character found */
|
||||||
@@ -464,6 +466,30 @@ void printHitFeed(game_state *gs, hitfeed *hf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trollHandleImpressive(hitfeed *hf, game_state *gs, int hits) {
|
||||||
|
if (hits >= IMPRESSIVEHIT) {
|
||||||
|
hf->impstreakcounter++; //Increase the counter
|
||||||
|
} else {
|
||||||
|
/* There was a hit beneath the hit threshold.
|
||||||
|
The streak is vanished */
|
||||||
|
hf->impstreakcounter = 0;
|
||||||
|
}
|
||||||
|
if (gs->trollEnabled && hf->impstreakcounter >= IMPRESSIVESTREAK) {
|
||||||
|
/* Execute animation and reset the counter */
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
mvprintw(5, gs->centerx - 5, "IMPRESSIVE!");
|
||||||
|
refresh();
|
||||||
|
usleep(100000);
|
||||||
|
mvprintw(5, gs->centerx - 5, " ");
|
||||||
|
refresh();
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
hf->impstreakcounter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void drawFigure(game_state *gs, int drawNext) {
|
void drawFigure(game_state *gs, int drawNext) {
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#define ANIM_DURATION 1
|
#define ANIM_DURATION 1
|
||||||
#define LINEBREAK 16 //Linebreak offset
|
#define LINEBREAK 16 //Linebreak offset
|
||||||
#define HITFEEDSLOTS 5
|
#define HITFEEDSLOTS 5
|
||||||
|
#define IMPRESSIVESTREAK 3 //reach amount of hit streaks to activate impressive screen
|
||||||
|
#define IMPRESSIVEHIT 2
|
||||||
|
|
||||||
/* Data structures */
|
/* Data structures */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -41,6 +43,7 @@ typedef struct hitfeed {
|
|||||||
char history[HITFEEDSLOTS][50]; //Prints the last 3 streaks
|
char history[HITFEEDSLOTS][50]; //Prints the last 3 streaks
|
||||||
char beststreak[50]; //Prints the best streak
|
char beststreak[50]; //Prints the best streak
|
||||||
int besthit; //Prints the best hit number e.g. Godlike with 15 hits
|
int besthit; //Prints the best hit number e.g. Godlike with 15 hits
|
||||||
|
int impstreakcounter; //if this counter hits IMPRESSIVESTREAK there'll be an animation
|
||||||
} hitfeed;
|
} hitfeed;
|
||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
@@ -64,6 +67,7 @@ int centerDiff(int coordinate, char *str);
|
|||||||
void readRandomLine(char *file, char *result);
|
void readRandomLine(char *file, char *result);
|
||||||
void trollHitScreen(game_state *gs, hitfeed *hf, int hits);
|
void trollHitScreen(game_state *gs, hitfeed *hf, int hits);
|
||||||
void addHitToFeed(hitfeed *hf, char *streak, int hit);
|
void addHitToFeed(hitfeed *hf, char *streak, int hit);
|
||||||
|
void trollHandleImpressive(hitfeed *hf, game_state *gs, int hits);
|
||||||
void drawFigure(game_state *gs, int drawNext);
|
void drawFigure(game_state *gs, int drawNext);
|
||||||
void animateLineClear(game_state *gs, int line, int offsetMultiplier);
|
void animateLineClear(game_state *gs, int line, int offsetMultiplier);
|
||||||
void printHitFeed(game_state *gs, hitfeed *hf);
|
void printHitFeed(game_state *gs, hitfeed *hf);
|
||||||
|
Reference in New Issue
Block a user