Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation Mode #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions termosaur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,55 @@

#include "termosaur.hpp"

int main() {
int main(int argc, char **argv) {
setlocale(LC_ALL, "");

Termosaur *termo = new Termosaur();

termo->start();
termo->start(argc > 1 && argv[1] == std::string("-a"));

delete termo;

return 0;
}

void Termosaur::start() {
void Termosaur::start(bool animationMode) {
this->animationMode = animationMode;

char key;

while(1) {
timer = (timer >= TIMER_RANGE ? 0 : timer + 1);
key = getch();

switch(key) {
case ' ':
if (debounceTimer != 0)
break;

switch(gameState) {
case GAME_STARTED:
jump();
if (bushPos < 28 && bushPos > 6) {
score.passed++;
}
break;
case GAME_AI:
case GAME_OVER:
startGame();
if (animationMode) {
switch(key) {
case 'q':
return;
}
} else {
switch(key) {
case ' ':
if (debounceTimer != 0)
break;
}

break;
case 'q':
return;
switch(gameState) {
case GAME_STARTED:
jump();
if (bushPos < 28 && bushPos > 6) {
score.passed++;
}
break;
case GAME_AI:
case GAME_OVER:
startGame();
break;
}

break;
case 'q':
return;
}
}

draw();
Expand All @@ -97,7 +106,9 @@ void Termosaur::draw() {
attron(COLOR_PAIR(3));
drawDino();
attron(COLOR_PAIR(3));
drawScore();
if (!animationMode) {
drawScore();
}

switch(gameState) {
case GAME_AI:
Expand All @@ -123,7 +134,9 @@ void Termosaur::gameOver() {
}

void Termosaur::aiGame() {
mvprintw(winSize.y / 2, (winSize.x / 2) - (20 / 2), "Press SPACE to start");
if (!animationMode) {
mvprintw(winSize.y / 2, (winSize.x / 2) - (20 / 2), "Press SPACE to start");
}

if (bushPos < 23 && bushPos > 10 && !isJump) {
jump();
Expand Down
3 changes: 2 additions & 1 deletion termosaur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Termosaur {
Termosaur();
~Termosaur();

void start();
void start(bool);

private:
Point winSize;
Expand All @@ -66,6 +66,7 @@ class Termosaur {
bool isJump;
int bushPos;
char gameState;
bool animationMode;

void startCurses();
void stopCurses();
Expand Down