-
Notifications
You must be signed in to change notification settings - Fork 7
/
Pong.h
46 lines (39 loc) · 997 Bytes
/
Pong.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
#include <stdint.h>
#include <Tiny4kOLED_common.h>
typedef struct {
uint8_t x;
uint8_t y;
} UPosition;
typedef struct {
int8_t x;
int8_t y;
} Position;
class Pong {
SSD1306Device* oled;
uint8_t enemyPos = 24;
uint8_t playerPos = 24;
uint16_t enemyScore = 0;
uint16_t playerScore = 0;
UPosition prevBallPos = { 64, 16 };
UPosition ballPos = { 64, 16 };
Position ballVector = { 1, 1 };
public:
Pong(SSD1306Device* _oled);
void run(void);
void updateGame(void);
private:
bool checkForScore(void);
void checkForCollision(void);
void checkForPause(void);
void clearGame(void);
void moveBall(void);
void moveEnemy(void);
void movePlayer(void);
void newBallVector(uint8_t index, bool reverseX);
void randomBallVector(void);
void reset(bool hard);
void setupPlayArea(void);
void updateLines(uint8_t x, uint32_t line, uint8_t numLines);
void updateScreen(void);
void writeScoreToScreen(bool player);
};