-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitlescreen.c
117 lines (89 loc) · 2.69 KB
/
titlescreen.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "titlescreen.h"
#include <tari/log.h>
#include <tari/input.h>
#include <tari/math.h>
#include <tari/drawing.h>
#include <tari/system.h>
#include "titledata.h"
#include "drawing.h"
#include "texture.h"
#include "round.h"
#include "roundscreen.h"
#define TITLE_TILT_ACCELERATION 0.001
#define TITLE_TILT_VELOCITY_MAX 0.02
TitleData gTitleData;
void calculateTilt() {
gTitleData.tiltVelocity += gTitleData.tiltAcceleration;
if (gTitleData.tiltVelocity > TITLE_TILT_VELOCITY_MAX) {
gTitleData.tiltVelocity = TITLE_TILT_VELOCITY_MAX;
} else if (gTitleData.tiltVelocity < -TITLE_TILT_VELOCITY_MAX) {
gTitleData.tiltVelocity = -TITLE_TILT_VELOCITY_MAX;
}
gTitleData.tiltAngle += gTitleData.tiltVelocity;
debugDouble(gTitleData.tiltAngle);
if ((gTitleData.tiltAngle < -0.5 && gTitleData.tiltAcceleration < 0) || (gTitleData.tiltAngle > 0.5 && gTitleData.tiltAcceleration > 0)) {
debugLog("switch tilt direction");
gTitleData.tiltAcceleration *= -1;
}
}
static void checkDone() {
if (hasPressedStartFlank()) {
setNewScreen(&RoundScreen);
}
}
static void updateTitleScreen() {
updateSystem();
updateInput();
if (hasPressedAbortFlank()) {
abortScreenHandling();
}
checkDone();
calculateTilt();
}
static void drawTitleBackground(TitleData* tTitleData) {
debugLog("Draw Title background");
TextureData textureData = getTitleTexture();
Rectangle tTexturePosition;
tTexturePosition.topLeft.x = 0;
tTexturePosition.topLeft.y = 0;
tTexturePosition.bottomRight.x = textureData.mTextureSize.x - 1;
tTexturePosition.bottomRight.y = textureData.mTextureSize.y - 1;
Position pos;
pos.x = 0;
pos.y = 0;
pos.z = BACKGROUND_POSITION_Z;
drawSprite(textureData, pos, tTexturePosition);
}
static void drawPressStart(TitleData* tTitleData) {
debugLog("Draw Title background");
TextureData textureData = getPressStartTexture();
Rectangle tTexturePosition;
tTexturePosition.topLeft.x = 0;
tTexturePosition.topLeft.y = 0;
tTexturePosition.bottomRight.x = textureData.mTextureSize.x - 1;
tTexturePosition.bottomRight.y = textureData.mTextureSize.y - 1;
Position pos;
pos.x = PRESS_START_X;
pos.y = PRESS_START_Y;
pos.z = CHARACTER_POSITION_Z;
drawSprite(textureData, pos, tTexturePosition);
}
static void drawTitle() {
debugLog("Begin drawing title");
updateTiltingMatrix(gTitleData.tiltAngle);
drawTitleBackground(&gTitleData);
drawPressStart(&gTitleData);
}
static void initiateTitle() {
gTitleData.tiltAcceleration = TITLE_TILT_ACCELERATION;
}
static void loadTitleScreen() {
resetRound();
memset(&gTitleData, 0, sizeof gTitleData);
initiateTitle();
}
Screen TitleScreen = {
.mLoad = loadTitleScreen,
.mUpdate = updateTitleScreen,
.mDraw = drawTitle,
};