curssses

Snake game for the linux terminal.
git clone git://git.amin.space/curssses.git
Log | Files | Refs | LICENSE

commit 154dbdbd5ba9d4450d699c621d8c5ff9a66ae9da
parent e491eef5214078afe13da6a4e745659ddf7c88a0
Author: amin <dev@aminmesbah.com>
Date:   Fri,  2 Dec 2016 21:05:08 +0000

Make debug info toggleable with 'i' key.

FossilOrigin-Name: df471c26aea578b9edc3f8d7de4e2e0c5c7102d52cadaa6b9d1b763faaf6bc8e
Diffstat:
Mcurssses.c | 28++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/curssses.c b/curssses.c @@ -5,7 +5,7 @@ #include <unistd.h> #define SECOND 1000000 -#define FPS 20 +#define FPS 60 typedef enum { @@ -125,8 +125,10 @@ int main(void) keypad(stdscr, TRUE); curs_set(0); + bool debug = false; + snake *s = snake_init(); - for (int i = 0; i < 4; ++i) + for (int i = 0; i < 50; ++i) { snake_add_segment(s); } @@ -164,24 +166,34 @@ int main(void) nodelay(stdscr, FALSE); getch(); nodelay(stdscr, TRUE); - } + } break; + case 'i': + { + debug = !debug; + } break; } erase(); snake_move(s); - mvprintw( - 0, 0, - "Screen: [%d, %d]\nSnake Length: %d\nHead: (%d, %d)\nTail: (%d, %d)", - COLS, LINES, s->length, s->head->x, s->head->y, s->tail->x, s->tail->y); + if (debug) + { + mvprintw( + 0, 0, + "Screen: [%d, %d]\nSnake Length: %d\nHead: (%d, %d)\nTail: (%d, %d)", + COLS, LINES, s->length, s->head->x, s->head->y, s->tail->x, s->tail->y); + } segment *current = s->head; int i = 0; while (current != 0) { mvaddch(current->y, current->x, s->symbol); - mvprintw(i+4, 0, "Segment %d (%d, %d)", i+1, current->x, current->y); + if (debug) + { + mvprintw((i%20)+4, (i/20)*25, "Segment %d (%d, %d)", i+1, current->x, current->y); + } current = current->next; i++; }