-
Notifications
You must be signed in to change notification settings - Fork 7
/
Tetris.h
57 lines (49 loc) · 1.35 KB
/
Tetris.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
#include <stdint.h>
//#include <Arduino.h>
#include <Tiny4kOLED_common.h>
#define PIXELS_IN_SHAPE 4
//TODO union type relativePosition with 4 bits for signed x and 4 for signed y
typedef struct {
int8_t x;
int8_t y;
} Position;
typedef struct {
Position pixels[PIXELS_IN_SHAPE];
} Shape;
class Tetris {
Position position;
uint32_t score = 0;
uint16_t lines = 0;
uint8_t level = 0;
SSD1306Device* oled;
static uint8_t board[32];
static const Shape shapes[];
static const uint8_t numShapes;
// so we don't fetch from progmem every frame
static Shape shape;
// required to keep track of rotations
static uint8_t shapeIndex;
public:
Tetris(SSD1306Device* _oled);
uint32_t run(void);
private:
void incrementLines(void);
void incrementScore(uint8_t lines);
uint16_t getMillisPerTick(void);
bool checkCollision(Position delta);
void addOrRemovePiece(bool add);
void advancePiece(void);
void assignRandomShape(void);
void assignShape(uint8_t index);
void checkForFullRows(void);
void checkInputs(bool unsetFlags = false);
void end(void);
void goLeft(void);
void goRight(void);
void main(void);
void resetButtons(void);
void movePiece(bool moveDown);
void renderBoard(bool wholeScreen = false, bool addPiece = true);
void rotatePiece(void);
void spawnNewPiece(void);
};