-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState_MainMenu.cpp
More file actions
96 lines (82 loc) · 2.97 KB
/
State_MainMenu.cpp
File metadata and controls
96 lines (82 loc) · 2.97 KB
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
#include "precomp.h"
#include "State_MainMenu.h"
#include "State_PasswordWindow.h"
#include "game.h"
void State_MainMenu::Init() {
Surface::FromSpriteSheet("assets/bomberman/fontsheet.png", SCALE, FILE_FONT_SIZE.x, 38, 2, true, IntArray(0), m_font);
Surface src("assets/bomberman/mainscreen.png");
src.UpscaleAndDestroy(&m_graphics, SCALE, 0, 0);
m_game->screen->Clear(0x0);
m_choiceGraphics = &m_font[10];
m_emptyGraphics = &m_font[37];
m_game->SetScore(0);
}
void State_MainMenu::Enter() {
m_game->screen->Clear(0);
const int x{ m_game->screen->m_width / 2 - m_graphics.m_width / 2 };
m_graphics.CopyTo(m_game->screen, x, 0);
for (int i{ 0 }; i < MODE_CHOICES_NUM; i++) {
const Surface* surf{ m_emptyGraphics };
if (m_modeSelectionIndex == i) {
surf = m_choiceGraphics;
}
surf->CopyTo(m_game->screen, m_modeChoicesPositions[i].x * SCALE + x, m_modeChoicesPositions[i].y * SCALE);
}
m_inputValid = true;
if (Input::IsKeyDown(KeyCode::Enter)) {
m_inputValid = false;
}
m_game->m_audio.RequestMusic(AudioManager::Music::EnterMainMenu);
}
void State_MainMenu::Update(float /*deltaTime*/) {
const int x{ m_game->screen->m_width / 2 - m_graphics.m_width / 2 };
if (!m_isChoosing && Input::IsKeyDown(KeyCode::RightShift)) {
// loop selection index
m_modeSelectionIndex = repeat(m_modeSelectionIndex + 1, MODE_CHOICES_NUM);
for (int i{ 0 }; i < MODE_CHOICES_NUM; i++) {
const Surface* surf{ m_emptyGraphics };
if (m_modeSelectionIndex == i) {
surf = m_choiceGraphics;
}
surf->CopyTo(m_game->screen, m_modeChoicesPositions[i].x * SCALE + x, m_modeChoicesPositions[i].y * SCALE);
}
m_isChoosing = true;
}
if (!m_isChoosing) {
if (Input::IsKeyDown(KeyCode::Num1)) m_playerSelectionIndex = 0;
if (Input::IsKeyDown(KeyCode::Num2)) m_playerSelectionIndex = 1;
if (Input::IsKeyDown(KeyCode::Right)) m_playerSelectionIndex = repeat(m_playerSelectionIndex + 1, PLAYER_NUM_CHOICES_NUM);
if (Input::IsKeyDown(KeyCode::Left)) m_playerSelectionIndex = repeat(m_playerSelectionIndex - 1, PLAYER_NUM_CHOICES_NUM);
for (int i{ 0 }; i < PLAYER_NUM_CHOICES_NUM; i++) {
const Surface* surf{ m_emptyGraphics };
if (m_playerSelectionIndex == i) {
surf = m_choiceGraphics;
}
surf->CopyTo(m_game->screen, m_playerNumChoicesPositions[i].x * SCALE + x, m_playerNumChoicesPositions[i].y * SCALE);
}
m_isChoosing = true;
}
if (!Input::IsKeyDown(KeyCode::RightShift) &&
!Input::IsKeyDown(KeyCode::Num1) &&
!Input::IsKeyDown(KeyCode::Num2) &&
!Input::IsKeyDown(KeyCode::Right) &&
!Input::IsKeyDown(KeyCode::Left)) {
m_isChoosing = false;
}
if (!Input::IsKeyDown(KeyCode::Enter)) {
m_inputValid = true;
}
else if (m_inputValid) {
switch (m_modeSelectionIndex) {
case NEW_GAME_INDEX:
m_game->m_playerNum = m_playerSelectionIndex + 1; // m_playerSelectionIndex goes from 0 to 1
m_game->LoadLevel(DEFAULT_LEVEL);
break;
case ENTER_PASSWORD_INDEX:
m_game->SetState(m_game->m_passwordState);
break;
}
}
}
void State_MainMenu::Exit() {
}