-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
94 lines (72 loc) · 2.39 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
#pragma once
#include <cstdint>
#include <vector>
class Game {
public:
//This is default fullscreen shadow buffer. You can use it if you want to.
static unsigned *shadow_buf;
void init_game();
void close_game();
// Îòðèñîâêà èãðû.
void draw_game();
// Îáíîâëåíèå ìåõàíèêè. dt - âðåìÿ ñ ïðåäûäóùåãî âûçîâà.
void act_game(float dt);
private:
// Ðåæèì èãðû.
enum State {
Start,
Play,
Over,
};
State state;
// Êîíñòàíòû öâåòîâ.
const uint32_t black = make_color(0x00, 0x00, 0x00);
const uint32_t gray = make_color(0xA0, 0xA0, 0xA0);
const uint32_t red = make_color(0xFF, 0x00, 0x00);
const uint32_t yellow = make_color(0xFF, 0xFF, 0x00);
const uint32_t blue = make_color(0x00, 0x00, 0xFF);
const uint32_t purple = make_color(0xFF, 0x00, 0xFF);
const uint32_t lime = make_color(0x00, 0xFF, 0x00);
const uint32_t white = make_color(0xFF, 0xFF, 0xFF);
// Âåðõ è íèç ïîëÿ (íóæíî ïîòîìó, ÷òî ÷àñòü ýêðàíà ïî÷åìó-òî îáðåçàåòñÿ ïðè âûâîäå).
const int kFieldTop = 50;
const int kFieldBottom = 450;
// Ïàðàìåòðû êèðïè÷åé.
const int kBrickTopPosition = kFieldTop; // Âåðõ âåðõíåãî ðÿäà êèðïè÷åé.
const int kBrickColCount = 13;
const int kBrickRowCount = 6;
const int kBrickSpacing = 1; // Ðàñòîÿíèå ìåæäó êèðïè÷àìè.
const int kBrickHeight = 20;
// Ïàðàìåòðû êîðàáëÿ.
const int kVausMoveSpeed = 200;
const int kVausWidth = 50;
const int kVausHeight = 10;
const int kVausYPos = kFieldBottom; // Êîîðäèíàòà, íà êîòîðîé íàõîäèòñÿ âåðõ êîðàáëÿ.
// Ïàðàìåòðû ìÿ÷à.
const float kBallSpeed = 150;
const int kBallDiameter = 7;
// Ïàðàìåòðû âûâîäà æèçíåé è ïðîèãðûøà.
const int kLivesSpacing = 10;
const float kBlinkTime = 2;
const float kBlinkingTime = 0.5;
// Ìàññèâ öâåòîâ.
std::vector<uint32_t> colors;
typedef std::vector<bool> Row;
typedef std::vector<Row> Matrix;
// Ìàññèâ êèðïè÷åé. True åñëè åùå íå óáèò.
Matrix bricks;
// Øèðèíà êèðïè÷à âû÷èñëÿåòñÿ èç øèðèíû ýêðàíà.
int brick_width;
// Èãðîâûå ïàðàìåòðû ìÿ÷à è êîðàáëÿ.
float vaus_position;
float ball_position_x;
float ball_position_y;
float ball_speed_x;
float ball_speed_y;
float blink_timer;
int lives;
inline uint32_t make_color(uint8_t r, uint8_t g, uint8_t b) {
return static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b);
}
void draw_rect(int pos_x, int pos_y, int width, int height, uint32_t color);
};