diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/games/sokoban/animation.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/games/sokoban/animation.c')
-rwxr-xr-x | sys/src/games/sokoban/animation.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/sys/src/games/sokoban/animation.c b/sys/src/games/sokoban/animation.c new file mode 100755 index 000000000..147012b2f --- /dev/null +++ b/sys/src/games/sokoban/animation.c @@ -0,0 +1,60 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> + +#include "sokoban.h" + +void +initanimation(Animation *a) +{ + if (a == nil) + return; + + memset(a, 0, sizeof(Animation)); +} + +void +setupanimation(Animation *a, Route *r) +{ + if (a == nil || r == nil || r->step == nil) + return; + + a->route = r; + a->step = r->step; + if (a->step < a->route->step + a->route->nstep) + a->count = a->step->count; + else + stopanimation(a); +} + +int +onestep(Animation *a) +{ + if (a == nil) + return 0; + + if (a->count > 0 && a->step != nil && a->route != nil) { + move(a->step->dir); + a->count--; + if (a->count == 0) { + a->step++; + if (a->step < a->route->step + a->route->nstep) + a->count = a->step->count; + else + stopanimation(a); + } + } else if (a->count > 0 && (a->step == nil || a->route == nil)) + stopanimation(a); + return (a->count > 0); +} + +void +stopanimation(Animation *a) +{ + if (a == nil) + return; + + if (a->route != nil) + freeroute(a->route); + memset(a, 0, sizeof(Animation)); +} |