-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArkanoid.ino
221 lines (155 loc) · 4.26 KB
/
Arkanoid.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*-- 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 = random(0,7);
int8_t bally = random(0,8);
int8_t dx = 1;
int8_t dy = 1;
int8_t sp1y = 0;
int8_t bottombounce = 0;
int8_t nohitcount = 0;
int8_t repetition = 0;
int8_t row1[] ={1,1,1,1,1,1,1,1,1};
int8_t row2[] ={1,1,1,1,1,1,1,1,1};
int8_t row3[] ={1,1,1,1,1,1,1,1,1};
int8_t row4[] ={1,1,1,1,1,1,1,1,1};
int8_t row5[] ={1,1,1,1,1,1,1,1,1};
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(){
repetition++;
ballx = constrain(ballx,0,13);
bally = constrain(bally,0,8);
//##################### 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 == 13){
dx = - 1;
}
//Bounce off Wall bottom X
if(ballx == 1 ){
dx = + 1;
//Randomisation of ball movement
bottombounce++;
if(bottombounce >= 5 && bally < 8){
bally = bally + 1;
bottombounce == 0;
}
}
//Bounce off Wall top Y
if( bally == 8){
dy = - 1;
}
//Bounce off Wall bottom Y
if(bally == 0 ){
dy = + 1;
}
//######################################
//################# ROW BLASTING BEGIN #####################
nohitcount++;
//Kill Rows
if( ballx == 10 && row4[bally] == 1){
row4[bally] = 0;
dx = - 1;
nohitcount = 0;
}
if( ballx == 11 && row3[bally] == 1){
row3[bally] = 0;
dx = - 1;
nohitcount = 0;
}
if( ballx == 12 && row2[bally] == 1){
row2[bally] = 0;
dx = - 1;
nohitcount = 0;
}
if( ballx == 13 && row1[bally] == 1){
row1[bally] = 0;
dx = - 1;
nohitcount = 0;
}
//######################################
//##################### SHIP MOVEMENT ######################
//Cosmetic: Makes ship stop if the ball just bounced off of it.
if(lastballx >= ballx){
// ### Ship Movement ###
if(bally >= sp1y){
sp1y= sp1y + 1;
}
else{
sp1y = sp1y -1;
}
if(sp1y == 8){
sp1y = sp1y -1;
}
if(sp1y == 0){
sp1y = sp1y +1;
}
}
//######################################
// RESET GAME IF ENDLESS LOOP
if ((nohitcount >= 10) && (ballx == 13) && (repetition >= 50)){
resetgame();
}
//Paint Objects
delay(130);
LedSign::Clear();
paintships();
paintrows();
paintball();
}
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(0,sp1y-1,1); //Values: First Number: X Axis Position, Second Number: Y Axis Position, third Nubmer: LED ON/OFF
}
void paintrows(){
//Paint TopRow (13)
for (int i = 0; i <= 8; i++){
LedSign::Set(13,i,row1[i]);
LedSign::Set(12,i,row2[i]);
LedSign::Set(11,i,row3[i]);
LedSign::Set(10,i,row4[i]);
}
}
void resetgame(){
nohitcount = 0;
ballx = random(2,8);
bally = random(2,8);
for(int i = 0; i <= 8; i++){
row1[i] = 1;
row2[i] = 1;
row3[i] = 1;
row4[i] = 1;
}
LedSign::Clear(1);
delay (400);
LedSign::Clear(0);
delay (300);
LedSign::Clear(1);
delay (300);
LedSign::Clear(0);
delay (300);
LedSign::Clear(0);
delay (300);
}