/
stagelogic.c
79 lines (61 loc) · 2.03 KB
/
stagelogic.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
71
72
73
74
75
76
77
78
79
#include "stagelogic.h"
#include <stdlib.h>
#include <tari/log.h>
#include <tari/input.h>
#include "collision.h"
int NO_TILT = 0;
void checkExit(WorldData* tWorldData, CharacterData* tCharacterData) {
int exitTileX = (int)RealPositionToTileX(tWorldData->exitPosition.x);
int exitTileY = (int)RealPositionToTileWitoutPlatformY(tWorldData->exitPosition.y);
int pTileX = (int)RealPositionToTileX((tCharacterData->physics.mPosition.x+(TILE_SIZE/2)));
int pTileY = (int)RealPositionToTileWitoutPlatformY(tCharacterData->physics.mPosition.y);
if (exitTileX == pTileX && exitTileY == pTileY) {
tWorldData->state = GAME_WON;
}
}
#define MAX_TILT_VELOCITY 0.075
int direction = 0;
void changeDirection() {
direction = (direction + 1) % 2;
}
void handleScreenTilting(WorldData* tWorldData, CharacterData* tCharacterData) {
if (NO_TILT) {
return;
}
if (direction) {
double tiltAcceleration = ((rand() % 500) * 0.000001);
debugDouble(tiltAcceleration);
tWorldData->tiltVelocity += tiltAcceleration;
} else {
double tiltAcceleration = -((rand() % 500) * 0.000001);
debugDouble(tiltAcceleration);
tWorldData->tiltVelocity += tiltAcceleration;
}
if (rand() % 500 == 0) {
changeDirection();
}
if (tWorldData->tiltVelocity > MAX_TILT_VELOCITY) {
tWorldData->tiltVelocity = MAX_TILT_VELOCITY;
changeDirection();
} else if (tWorldData->tiltVelocity < -MAX_TILT_VELOCITY) {
tWorldData->tiltVelocity = -MAX_TILT_VELOCITY;
changeDirection();
}
tWorldData->tiltAngle += tWorldData->tiltVelocity;
}
GameReturnType checkGameAbort(WorldData* tWorldData, CharacterData* tCharacterData) {
if (hasPressedAbortFlank()) {
return RETURN_TO_MENU;
} else if (tWorldData->state == GAME_WON) {
return RETURN_WON;
} else if (tWorldData->state == GAME_OVER) {
return RETURN_LOSS;
} else {
return RETURN_NORMAL;
}
}
void checkGameOver(WorldData* tWorldData, CharacterData* tCharacterData) {
if (hasLeftScreen(tWorldData, tCharacterData)) {
tWorldData->state = GAME_OVER;
}
}