-
Notifications
You must be signed in to change notification settings - Fork 0
/
pong.h
100 lines (68 loc) · 1.48 KB
/
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
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
#ifndef __PONG_H__
#define __PONG_H__
#include "defines.h"
class pong : public animation {
public:
pong(uint8_t _player=0) {
player = _player;
fade = 4;
ball_x = (float)(GRID_WIDTH / 2);
ball_y = (float)(GRID_HEIGHT / 2);
rate_x = random_speed();
rate_y = random_speed();
random_color();
}
INLINE void random_color() {
color = pix_colorx[
random(0, 7)
];
}
INLINE float random_speed() {
return ((float)random(300, 700)) / ((float)1000);
}
virtual void frame(pixelArray **strip, WII **wii) {
uint8_t *data;
data = (uint8_t*) strip[player]->getPixels();
for (uint16_t i=0; i<GRID_TOTAL*3; i++) {
if (data[i] > 64) {
data[i] >>= 1;
} else if (data[i] > fade) {
data[i] -= fade;
} else {
data[i] = 0;
}
}
//MOVE BALL ON X AXIS
ball_x += rate_x;
if (((int)ball_x) >= GRID_WIDTH) {
ball_x = (float)(GRID_WIDTH-1);
rate_x = -random_speed();
random_color();
} else if (ball_x <= 0) {
ball_x = 0;
rate_x = random_speed();
random_color();
}
//MOVE BALL ON Y AXIS
ball_y += rate_y;
if (((int)ball_y) >= GRID_HEIGHT) {
ball_y = (float)(GRID_HEIGHT-1);
rate_y = -random_speed();
random_color();
} else if (ball_y <= 0) {
ball_y = 0;
rate_y = random_speed();
random_color();
}
strip[player]->draw((int)ball_x, (int)ball_y, color);
}
private:
uint8_t player;
uint8_t fade;
float ball_x;
float ball_y;
float rate_x;
float rate_y;
color_t color;
};
#endif //__PONG_H__