-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
118 lines (93 loc) · 2.4 KB
/
Game.h
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
118
#ifndef GAME_H
#define GAME_H
#include "Util.h"
#include "Math.h"
#include <U8g2lib.h>
#include <ezBuzzer.h>
// Game maps size
#define MAP_WIDTH 124
#define MAP_HEIGHT 62
extern U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2;
extern ezBuzzer musicPlayer;
extern bool gSpeakerOn;
// Map (defined as a rectangle)
struct Map
{
vec2i pos;
uint8_t width;
uint8_t height;
};
// map for snake (same for pong game)
const Map snakeMap = {vec2i{2, 2}, MAP_WIDTH, MAP_HEIGHT};
// current game state (used also for menu)
enum struct GameState
{
PLAYING = 0, // For Menu it means that it's on menu
PAUSE = 1, // For Menu it menas that it's not in menu (so it's playing a game)
FINISHED = 2,
GO_MENU = 3,
MATCH_ENDED = 4
};
class Game
{
public:
virtual ~Game() = default;
virtual void Update(int input) = 0;
inline GameState GetState() const { return mState; }
protected:
GameState mState;
Game(GameState state) : mState(state) {}
};
inline void DrawPauseScreen()
{
// Display is divided in two pages (half screen is frist page, other half is second page)
u8g2.firstPage();
do
{
// Set font
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(5, 15);
u8g2.print(F("Pause!"));
// Set font
u8g2.setFont(u8g2_font_BitTypeWriter_tr);
u8g2.setCursor(5, 35);
u8g2.print(F("Press play to resume"));
} while (u8g2.nextPage());
}
inline void DrawGameOver(uint8_t score)
{
u8g2.firstPage();
do
{
// Set font
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(5, 15);
u8g2.print(F("Game over!"));
// Set font
u8g2.setFont(u8g2_font_BitTypeWriter_tr);
u8g2.setCursor(5, 35);
u8g2.print(F("Score "));
u8g2.print(score);
u8g2.setCursor(5, 50);
u8g2.print(F("'play' -> menu"));
} while (u8g2.nextPage());
}
inline void DrawYouWin(uint8_t score)
{
u8g2.firstPage();
do
{
// Set font
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(5, 15);
u8g2.print(F("You win!"));
// Set font
u8g2.setFont(u8g2_font_BitTypeWriter_tr);
u8g2.setCursor(5, 35);
u8g2.print(F("Score "));
u8g2.print(score);
u8g2.setCursor(5, 50);
u8g2.print(F("'play' -> menu"));
} while (u8g2.nextPage());
}
#endif