-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstagemenu.cpp
113 lines (95 loc) · 2.74 KB
/
stagemenu.cpp
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
//
// Created by Allen on 4/28/2020.
//
#include "stagemenu.h"
#include "UART.h"
#include "metadata.h"
#include "colors_stagemenu.h"
void StageMenu::start(bool isEnglish) {
reset();
animator_setBackgroundColors(colors_stagemenu);
animator_readPersistentSprite(persistentSprites[BACKGROUND_STAGEMENU], 0, 0);
animator_readCharacterSDCard(4);
englishSelected = isEnglish;
}
void StageMenu::loop(double joyH1, double joyV1, double joyH2, double joyV2, bool btnA,
void (*transitionCall)(int8_t, bool)) {
double dt = 49;
currentTime += (uint8_t)dt;
SpriteSendable s;
s.charIndex = charIndex;
s.framePeriod = 1;
s.persistent = false;
s.continuous = false;
s.mirrored = false;
// P1 btn A press
if(btnA) {
int8_t selectedStage = getStage(cursorX, cursorY);
if(selectedStage != -1) {
(*transitionCall)(selectedStage, englishSelected);
return;
}
else {
int8_t selectedLanguage = getLanguage(cursorX, cursorY);
if(selectedLanguage == 0) englishSelected = true;
else if(selectedLanguage == 1) englishSelected = false;
}
}
double joyH = joyH1 + joyH2;
double joyV = joyV1 + joyV2;
cursorX += STAGEMENU_CURSORSPEED * joyH;
cursorY += STAGEMENU_CURSORSPEED * joyV;
if(cursorY < 0) cursorY = 0;
if(cursorY > 215) cursorY = 215;
if(cursorX < 0) cursorX = 0;
if(cursorX > 295) cursorX = 295;
// draw crosshair
s.animationIndex = 4;
s.frame = 0;
s.x = (int16_t) cursorX;
s.y = (int16_t) cursorY;
s.layer = LAYER_CHARACTER;
UART_sendAnimation(s);
// draw language selection box
s.animationIndex = 5;
s.x = englishSelected ? STAGEMENU_ENGLISH_X : STAGEMENU_CHINESE_X;
s.y = englishSelected ? STAGEMENU_ENGLISH_Y : STAGEMENU_CHINESE_Y;
UART_sendAnimation(s);
UART_commandUpdate();
}
void StageMenu::reset() {
currentTime = 0;
cursorX = 145;
cursorY = 25;
}
int8_t StageMenu::getStage(double x, double y) {
if(y < 43 || y > 160 || x < 20 || x > 263) return -1;
if(y > 102) {
if(x < 100) {
return STAGE_FINALDESTINATION;
}
else if(x < 182) {
return STAGE_TOWER;
}
else {
return STAGE_BATTLEFIELD;
}
}
else {
if(x < 100) {
return STAGE_SMASHVILLE;
}
else if(x < 182) {
return STAGE_EER;
}
else {
return STAGE_GREGORYGYM;
}
}
}
int8_t StageMenu::getLanguage(double x, double y) {
// printf("%0.0f\t%0.0f\n", x, y);
if(x >= 67 && x <= 130 && y >= 0 && y <= 20) return 0;
if(x >= 150 && x <= 214 && y >= 1 && y <= 20) return 1;
return -1;
}