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->trollEnabled = 0;
|
||||
hf->besthit = 0;
|
||||
hf->impstreakcounter = 0;
|
||||
keypad(stdscr, FALSE);
|
||||
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->guesses++;
|
||||
trollHitScreen(gs, hf, found);
|
||||
trollHandleImpressive(hf, gs, found); //Prints a message with a little animation
|
||||
}
|
||||
} else {
|
||||
/* 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) {
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#define ANIM_DURATION 1
|
||||
#define LINEBREAK 16 //Linebreak offset
|
||||
#define HITFEEDSLOTS 5
|
||||
#define IMPRESSIVESTREAK 3 //reach amount of hit streaks to activate impressive screen
|
||||
#define IMPRESSIVEHIT 2
|
||||
|
||||
/* Data structures */
|
||||
typedef struct {
|
||||
@@ -41,6 +43,7 @@ typedef struct hitfeed {
|
||||
char history[HITFEEDSLOTS][50]; //Prints the last 3 streaks
|
||||
char beststreak[50]; //Prints the best streak
|
||||
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;
|
||||
|
||||
/* Function prototypes */
|
||||
@@ -64,6 +67,7 @@ int centerDiff(int coordinate, char *str);
|
||||
void readRandomLine(char *file, char *result);
|
||||
void trollHitScreen(game_state *gs, hitfeed *hf, int hits);
|
||||
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 animateLineClear(game_state *gs, int line, int offsetMultiplier);
|
||||
void printHitFeed(game_state *gs, hitfeed *hf);
|
||||
|
Reference in New Issue
Block a user