~rabbits/hiversaires

ref: 48e00fcdd82d1c3e02fabb9c29dceaf4d461f02c hiversaires/src/walkthrough.c -rw-r--r-- 1.5 KiB
48e00fcdRezmason Remade the splash animation sequence 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "walkthrough.h"

#include <string.h>
#include "datatypes.h"
#include "input.h"

/*
Copyright (c) 2013-2021 Devine Lu Linvega
2018 web port by rezmason
2021 C89 port by rezmason

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/

static InputType (*steps)[] = NULL;
static int numSteps;
static int stepIndex;

int
Walkthrough_Init(char *data)
{
	int i, j;
	stepIndex = 0;
	numSteps = strlen(data);
	steps = calloc(numSteps, sizeof(InputType));
	j = 0;
	for(i = 0; i < numSteps; i++) {
		int found = 1;
		InputType step = INPUTTYPE_ACTION;
		switch(data[i]) {
		case 'l': step = INPUTTYPE_LEFT; break;
		case 'r': step = INPUTTYPE_RIGHT; break;
		case 'f': step = INPUTTYPE_FORWARD; break;
		case 'a': step = INPUTTYPE_ACTION; break;
		default: found = 0; break;
		}
		if(found) {
			(*steps)[j] = step;
			j++;
		}
	}
	for(; j < numSteps; j++) {
		(*steps)[j] = INPUTTYPE_ACTION;
	}
	return 1;
}

void
Walkthrough_Quit()
{
	free(steps);
	steps = NULL;
}

void
Walkthrough_Reset()
{
	stepIndex = 0;
}

InputType
Walkthrough_Next()
{
	InputType step = INPUTTYPE_ACTION;
	if(stepIndex < numSteps) {
		step = (*steps)[stepIndex];
	}
#ifdef DEBUG
	printf("STEP %d: %d\n", stepIndex, step);
#endif
	stepIndex++;
	return step;
}