 # A different kind of Ball game HELP!!

Hey Guys,

I am trying to make a game with an Arduino Uno handling TVout and the Mega doing all the processing of the input from an accelerometer. The Game is supposed to mimic an android game at

There is a ball on the screen that is supposed to free fall without obstruction, but there are planks attached to the left and right of the screen that do not let it fall down. Here, the user has to move the ball left or right, towards the free space, using the accelerometer. The Uno is going to handle the Graphics generation, and i am trying to generate the wall pattern first and seem to be stuck with the code.

``````#include<TVout.h>
TVout TV;
int y;
int t;
int r=0;
void setup()
{
Serial.begin(9600);
TV.begin(_PAL);
}
void loop()
{
for(y=179;y>-80;y--)
{
TV.clear_screen();
r=0;
t=y;
for(t=y;t>0;t=t-12)
{
int x1=random(20,100);
TV.draw_line(0,t,x1,t,WHITE);
delay(10);
r=r+1;
if(r>8)
{
break;
}
}
Serial.println(r);
}
}
``````

The inner for loop, generates the lines on the screen, the outer for loop is supposed to give the felling that these lines are moving upwards. The problem is the presence of the random variable. When generating the lines, every line has to have a different length. This is achieved by the inner for loop. But then moving these lines up, the random variable x1 gets used again, for every line, and the line that is one pixel above the last line, is a new one. hence it doesnt work. Also, the sequence should work infinitely. So that lines keep getting generated.

the t=t-12 line generates lines at a distance of 12 pixels. That is supposed to be the design.

Also, so far, this is the thing i am trying to mimic.

``````#include<TVout.h>
TVout TV;
int y=-80;
int y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13;
int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13;

void setup()
{
TV.begin(_PAL);
}
void loop()
{
int x1=random(20,100);
int x2=random(30,50);
int x3=random(30,80);
int x4=random(60,110);
int x5=random(30,112);
int x6=random(20,60);
int x7=random(13,127);
int x8=random(10,60);
int x9=random(67,80);
int x10=random(70,120);
int x11=random(100,127);
int x12=random(70,100);
int x13=random(40,100);

for(y1=179,y2=167,y3=155,y4=143,y5=131,y6=119,y7=107,y8=95,y9=83,y10=71,y11=59,y12=47,y13=35;y1>y,y2>y,y3>y,y4>y,y5>y,y6>y,y7>y,y8>y,y9>y,y10>y,y11>y,y12>y,y13>y;y1--,y2--,y3--,y4--,y5--,y6--,y7--,y8--,y9--,y10--,y11--,y12--,y13--)
{
TV.clear_screen();
TV.draw_line(0,y1,x1,y1,WHITE);
TV.draw_line(0,y2,x2,y2,WHITE);
TV.draw_line(0,y3,x3,y3,WHITE);
TV.draw_line(0,y4,x4,y4,WHITE);
TV.draw_line(0,y5,x5,y5,WHITE);
TV.draw_line(0,y6,x6,y6,WHITE);
TV.draw_line(0,y7,x7,y7,WHITE);
TV.draw_line(0,y8,x8,y8,WHITE);
TV.draw_line(0,y9,x9,y9,WHITE);
TV.draw_line(0,y10,x10,y10,WHITE);
TV.draw_line(0,y11,x11,y11,WHITE);
TV.draw_line(0,y12,x12,y12,WHITE);
TV.draw_line(0,y13,x13,y13,WHITE);

delay(10);
}
}
``````

Please help me in getting this code work in the way it is supposed to. I have spent alot of nights already, trying to figure out a way.

Regards

Hey guys

I happen to have solved a part of the problem with arrays. With the code below

``````#include<TVout.h>
TVout TV;
int y;
int t;
int r=0;
int a;
int z,x,n;
void setup()
{
Serial.begin(9600);
TV.begin(_PAL);
}
void loop()
{
for(x=0;x<14;x++)
{
a[x]=random(20,100);
}

for(y=96;y>-1;y--)
{
TV.clear_screen();
r=0;
for(t=y,x=0;t>0,x<14;t=t-12,x++)
{
z=a[x];
TV.draw_line(0,t,z,t,WHITE);
delay(1);
r=r+1;
if(r>8)
{
break;
}
}
//Serial.println(r);

}
}
``````

Only problem that now resides is that the generation and movement doesnt continue indefinitely. Its like a page appears and scrolls up. then a new page is generated and scrolls up. How do i fix this now??

Regards