Added hitfeed; ClearAnimation 0 offset fix

This commit is contained in:
2017-05-24 15:10:51 +02:00
parent 72385eea81
commit 874367f321
2 changed files with 63 additions and 11 deletions

View File

@@ -34,13 +34,16 @@ int main(int argc, char **argv) {
initscr();
atexit(quitProgram);
game_state *gs;
hitfeed *hf;
gs = malloc(sizeof(game_state));
hf = malloc(sizeof(hitfeed)); //zeroes the whole struct
initCoordinates(gs);
gs->allowedMoves = DEFAULTTRIES;
gs->moves = 0;
gs->guesses = 0;
gs->trollEnabled = 0;
hf->besthit = 0;
keypad(stdscr, FALSE);
nonl(); //No new line. Prevents the new line when hitting enter
@@ -86,21 +89,23 @@ int main(int argc, char **argv) {
initAlphabet(gs);
drawAlphabet(gs, 0);
drawFigure(gs, 0);
startGame(gs);
startGame(gs, hf);
nl(); //enable newline again
while (getch() != 10);
clear();
free(gs);
free(hf);
return 0;
}
void startGame(game_state *gs) {
void startGame(game_state *gs, hitfeed *hf) {
noecho(); /* Don't show the player input */
time(&gs->startTime);
while (checkWin(gs)) {
updateScreen(gs);
playerInput(gs);
printHitFeed(gs, hf);
playerInput(gs, hf);
}
}
@@ -244,7 +249,7 @@ void drawGuessWord(game_state *gs) {
refresh();
}
int playerInput(game_state *gs) {
int playerInput(game_state *gs, hitfeed *hf) {
int inp;
int i, found = 0;
inp = getch();
@@ -260,7 +265,7 @@ int playerInput(game_state *gs) {
if (fillCurrentWord(gs, inp)) {
//gs->moves++;
gs->guesses++;
trollHitScreen(gs, found);
trollHitScreen(gs, hf, found);
}
} else {
/* no valid character found */
@@ -338,7 +343,7 @@ void printGameStats(game_state *gs) {
}
} else {
for (z = 0; z <= gs->wordRows; z++) {
animateLineClear(gs, gs->centery + z, -1); //-1 to speed up the animation
animateLineClear(gs, gs->centery + z, 0); //-1 to speed up the animation
}
}
@@ -394,7 +399,7 @@ void readRandomLine(char *file, char *result) {
fclose(fp);
}
void trollHitScreen(game_state *gs, int hits) {
void trollHitScreen(game_state *gs, hitfeed *hf, int hits) {
if (gs->trollEnabled) {
char *strings[] = {"Double Hit", "Triple Hit", "Multi Hit", \
"Ultra Hit", "Monster Hit", "Rampage", \
@@ -415,11 +420,50 @@ void trollHitScreen(game_state *gs, int hits) {
flash(); /* flash the screen */
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
refresh();
/* Put the new streak to the hit feed */
addHitToFeed(hf, strings[i], hits);
animateLineClear(gs, 5, i);
}
}
}
void addHitToFeed(hitfeed *hf, char *streak, int hit) {
/* Shift the array to put the new string to the first slot */
int i;
for (i = HITFEEDSLOTS - 1; i > 0; i--) {
strcpy(hf->history[i], hf->history[i - 1]);
}
/* Set the new first item */
strcpy(hf->history[0], streak);
if (hit > hf->besthit) {
strcpy(hf->beststreak, streak);
hf->besthit = hit;
}
}
void printHitFeed(game_state *gs, hitfeed *hf) {
if (gs->trollEnabled) {
/* print the stats at the bootom right corner */
int newMaxy = gs->maxy - HITFEEDSLOTS;
int newMaxx = gs->maxx - (gs->centerx / 2);
int i, z;
for (i = 0; i < HITFEEDSLOTS; i++) {
for (z = 0; z < gs->maxx - newMaxx; z++) {
mvprintw(newMaxy + i, newMaxx + z, " ");
}
}
for (i = 0; i < HITFEEDSLOTS; i++) {
mvprintw(newMaxy + i, newMaxx, hf->history[i]);
}
/* Print best score above history feed */
char message[100];
sprintf(message, "Best: %s (%i hits)", hf->beststreak, hf->besthit);
mvprintw(newMaxy - 1, newMaxx, message);
}
}
void drawFigure(game_state *gs, int drawNext) {
int row = 6;
int length = 8;
@@ -442,7 +486,7 @@ void drawFigure(game_state *gs, int drawNext) {
void animateLineClear(game_state *gs, int line, int offsetMultiplier) {
/* sleep and vanish */
int j = 0, k = gs->maxx, usec;
usec = (ANIM_DURATION * 1000000 + (100000 * offsetMultiplier)) / gs->maxx;
usec = ((ANIM_DURATION * 1000000) + (100000 * offsetMultiplier)) / gs->maxx;
for (j = 0; j <= gs->centerx; j++, k--) {
mvprintw(line, j, "!");