-
Notifications
You must be signed in to change notification settings - Fork 0
/
sporktris.h
77 lines (58 loc) · 1.66 KB
/
sporktris.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
#ifndef __SPORKTRIS
#define __SPORKTRIS
#include "display.h"
#include "controller.h"
#include "input_processor.h"
#define PIECE_COUNT 7
struct Tetromino {
struct Rect {
int8_t x, y, x2, y2;
int8_t center_x();
};
uint8_t positions;
uint8_t axis_x;
uint8_t axis_y;
uint8_t cur_pos;
uint8_t color;
int8_t points[4][2];
Tetromino rotated(bool cw);
Rect bounding_rect();
static Tetromino piece_of_type(uint8_t type);
};
struct PlayerState {
PlayerState();
Tetromino get_next_piece();
int line_count;
uint8_t level;
uint8_t next_piece_types[PIECE_COUNT * 2];
uint8_t next_piece_index;
Tetromino cur_piece;
int8_t piece_x, piece_y;
bool need_new_piece;
bool clearing_lines;
uint8_t pending_garbage;
bool alive;
unsigned long last_cycle;
unsigned long cycle_length;
};
class Sporktris: public InputProcessor {
public:
Display& disp;
Sporktris(Display& disp, Controller *controllers, uint8_t controller_count);
bool play();
private:
uint8_t board[MAX_DISPLAY_PIXELS];
PlayerState player_states[2];
bool paused;
uint8_t get_board_cell(uint8_t x, uint8_t y);
void set_board_cell(uint8_t x, uint8_t y, uint8_t value);
uint8_t get_board_cell(uint8_t player_index, uint8_t x, uint8_t y);
void set_board_cell(uint8_t player_index, uint8_t x, uint8_t y, uint8_t value);
bool handle_button_down(Controller::Button button, uint8_t controller_index);
void add_garbage(uint8_t player_index, uint8_t count);
// Returns amount of garbage to send to other players.
uint8_t cycle(uint8_t player_index);
void draw();
bool is_valid_position(uint8_t player_index, Tetromino piece, int8_t x, int8_t y);
};
#endif