-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCosmeticPimpedPong.ino
129 lines (96 loc) · 2.89 KB
/
CosmeticPimpedPong.ino
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Working Pong Ball bouncing off Walls.
Leaves 1 Space at top and bottom for Ship
-- Cosmetics to do:
- Ships don't move when Ball is not coming
- Increasing Speed
- Kometenschweif auf Ball
*/
#include <Charliplexing.h>
#include <Figure.h>
#include <Font.h>
int8_t ballx = 0;
int8_t bally = 0;
int8_t dx = 1;
int8_t dy = 1;
int8_t sp1y = 0;
int8_t sp2y = 8;
int8_t lastballx; //To save last Ball X position
int8_t lastbally; //To save last Ball Y position
// bally = random(9);
void setup(){
LedSign::Init(); //Initialize LOLShield
LedSign::SetBrightness(20);
randomSeed(analogRead(0)); //Initialize Random Number
}
void loop(){
//##################### BALL MOVEMENT ######################
//Saves last Ball X Position
lastballx = ballx;
lastbally = bally;
// Calculates new X and Y Ball Values
ballx = ballx + dx;
bally = bally + dy;
//Bounce off Wall top X
if( ballx == 12){
dx = - 1;
}
//Bounce off Wall bottom X
if(ballx == 1 ){
dx = + 1;
}
//Bounce off Wall top Y
if( bally == 8){
dy = - 1;
}
//Bounce off Wall bottom Y
if(bally == 0 ){
dy = + 1;
}
//################# BALL MOVEMENT END #####################
//##################### SHIP MOVEMENT ######################
//Cosmetic: Makes ship stop if the ball just bounced off of it.
if(lastballx >= ballx){
// ### Left Ship Movement ###
if(bally >= sp1y){
sp1y= sp1y + 1;
}
else{
sp1y = sp1y -1;
}
if(sp1y == 8){
sp1y = sp1y -1;
}
}
//Cosmetic: Makes ship stop if the ball just bounced off of it.
if(lastballx <= ballx){
// right Ship Movement
if(bally >= sp2y){
sp2y= sp2y + 1;
}
else{
sp2y = sp2y -1;
}
if(sp2y == 0){
sp2y = sp2y + 1;
}
if(sp2y == 9){
sp2y = sp2y - 1;
}
}
//################# SHIP MOVEMENT END #####################
//Paint Objects
paintships();
paintball();
delay(160);
LedSign::Clear();
}
void paintball(){
// LedSign::Set(lastballx,lastbally,7); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
LedSign::Set(ballx,bally,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
}
void paintships(){
LedSign::Set(0,sp1y,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
LedSign::Set(0,sp1y+1,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
LedSign::Set(13,sp2y,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
LedSign::Set(13,sp2y-1,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
}