-
Notifications
You must be signed in to change notification settings - Fork 0
/
routehandler.c
70 lines (56 loc) · 1.27 KB
/
routehandler.c
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
#include "routehandler.h"
#include <tari/math.h>
#include <tari/wrapper.h>
#include "routes/standardroute.h"
#include "routes/pukeroute.h"
#include "levelhandler.h"
#include "route.h"
#include "gameoverscreen.h"
#include "titlescreen.h"
static struct {
int mCurrentRoute;
int mAmount;
int mIsContinuing;
} gData;
static Route* gRoutes[] = {
//&StandardRoute,
&PukeRoute,
};
static void resetAllRoutes() {
int i;
for (i = 0; i < gData.mAmount; i++) {
gRoutes[i]->mReset();
}
}
void reloadRoute() {
if (gData.mIsContinuing) {
gData.mIsContinuing = 0;
return;
}
gData.mAmount = (sizeof gRoutes) / sizeof(Route*);
int i;
for (i = 0; i < gData.mAmount; i++) {
gData.mCurrentRoute = randfromInteger(0, gData.mAmount - 1);
if (gRoutes[gData.mCurrentRoute]->mCanBePlayed()) break;
}
if (!gRoutes[gData.mCurrentRoute]->mCanBePlayed()) {
resetAllRoutes();
reloadRoute();
}
}
void startNewRoute() {
gRoutes[gData.mCurrentRoute]->mLoadRoute();
}
void updateRouteHandler() {
if (gRoutes[gData.mCurrentRoute]->mHasLost()) {
setNewScreen(&GameOverScreen);
}
gRoutes[gData.mCurrentRoute]->mUpdate();
}
void setCurrentRouteToContinue()
{
gData.mIsContinuing = 1;
if (gRoutes[gData.mCurrentRoute]->mSetToContinue) {
gRoutes[gData.mCurrentRoute]->mSetToContinue();
}
}