From b00abf88da53bc406800f75b626d419448bfda53 Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 24 May 2018 12:26:05 +0200 Subject: [PATCH] speed up every 100 points --- README.md | 2 +- viiper.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a883356..37615dd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ r to restart, p to pause, q to quit. - DONE input out of whack when stopping (^Z) and resuming - DONE keybindings for restart, pause, redraw - DONE on dying: show end screen, allow restarting - - timer, score, increasing speed + - DONE score, increasing speed, ~~timer~~ - bonus/special items: slower snake, shorter snake, etc. - decaying points? (more points the faster you get the food) - wall-wrap-around mode? diff --git a/viiper.c b/viiper.c index 88f3ffc..c51ffda 100644 --- a/viiper.c +++ b/viiper.c @@ -48,6 +48,8 @@ #define LINES_AFTER 1 #define CW op.sch->cell_width +#define SPEEDUP_AFTER 100 /* increment speed every n points */ + struct game { int w; /* field width */ int h; /* field height */ @@ -267,6 +269,8 @@ try_again: } void consume_item (struct item* i) { + int old_score = g.p; + switch (i->t) { case FOOD: switch (i->v) { @@ -284,6 +288,9 @@ void consume_item (struct item* i) { if (i->next) i->next->prev = i->prev; if (i->prev) i->prev->next = i->next; else g.i = i->next; + + /* snake speedup every 100 points: */ + if (g.p/SPEEDUP_AFTER - old_score/SPEEDUP_AFTER) g.v++; } void show_playfield (void) { @@ -499,7 +506,7 @@ void clamp_fieldsize (void) { void timer_setup (int enable) { static struct itimerval tbuf; - tbuf.it_interval.tv_sec = 0;//TODO: make it speed up automatically + tbuf.it_interval.tv_sec = 0; tbuf.it_interval.tv_usec = (1000000/g.v)-1; /*WARN: 1 <= g.v <= 999999*/ if (enable) { -- 2.39.3