when consuming an item, set the time of next bonus then (instead of just
when spawning). at spawn time we also factor in the time a bonus might
be alive (can be shortened by eating it).
bonus actions (i.e. wraparound) is now a bitmap. thus, more than 1
action might be active at the same time.
girst [Fri, 31 Aug 2018 20:57:33 +0000 (22:57 +0200)]
fix: snake speed bug
originally, I noticed the snake speeding up when eating a BONUS_SLOW,
suspecting a bug there. as i found out a after way too long, i forgot to
restart the timer after routinely incrementing the velocity every 100
points. m(
however, a nice routine for debugging this was the following at the end
of the draw_sprites():
#include<sys/timeb.h>
struct timeb __now_time__;
ftime(&__now_time__);
long __time__ = __now_time__.time*1000+__now_time__.millitm;
static long __last_time__ = 0;
if(__last_time__) printf ("->%f (%ld)<-", g.v, __time__-__last_time__);
__last_time__ = __time__;
girst [Tue, 22 May 2018 12:41:09 +0000 (14:41 +0200)]
game loop (restartable), fix memory leak
if we set respawn, we need to break out of the loop, otherwise `i' gets
->next'ed until i == NULL. then, spawn_item() will malloc() a new item,
and `i' was not freed(), but just NULL'd.
girst [Sat, 19 May 2018 23:18:42 +0000 (01:18 +0200)]
minor in-code cleanup, documentation
i wanted to remove the 'only draw diff'-todo and looked into where i was
calling show_playfield(). i didn't call it anywhere where i expected it,
so i fired up gdb. gdb told me show_playfield() gets called from the
input loop after the switch(getchar()). i was puzzled about that,
because it fired even when no keys were pressed. then i noticed that
everytime the signal handler fires, a STX (ASCII 0x02) gets pushed onto
stdin. WHO FIGURES?! i was unable to find anything in the
documentation of sigaction or on the internet that indicates this!