Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_fixcpp/sys/src/games/sokoban/animation.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <draw.h>
4
 
5
#include "sokoban.h"
6
 
7
void
8
initanimation(Animation *a)
9
{
10
	if (a == nil)
11
		return;
12
 
13
	memset(a, 0, sizeof(Animation));
14
}
15
 
16
void
17
setupanimation(Animation *a, Route *r)
18
{
19
	if (a == nil || r == nil || r->step == nil)
20
		return;
21
 
22
	a->route = r;
23
	a->step = r->step;
24
	if (a->step < a->route->step + a->route->nstep)
25
		a->count = a->step->count;
26
	else
27
		stopanimation(a);
28
}
29
 
30
int
31
onestep(Animation *a)
32
{
33
	if (a == nil)
34
		return 0;
35
 
36
	if (a->count > 0 && a->step != nil && a->route != nil) {
37
		move(a->step->dir);
38
		a->count--;
39
		if (a->count == 0) {
40
			a->step++;
41
			if (a->step < a->route->step + a->route->nstep)
42
				a->count = a->step->count;
43
			else
44
				stopanimation(a);
45
		}
46
	} else if (a->count > 0 && (a->step == nil || a->route == nil))
47
		stopanimation(a);
48
	return (a->count > 0);
49
}
50
 
51
void
52
stopanimation(Animation *a)
53
{
54
	if (a == nil)
55
		return;
56
 
57
	if (a->route != nil)
58
		freeroute(a->route);
59
	memset(a, 0, sizeof(Animation));
60
}