I am trying to make a pong program, but I am running into issues.
When I run this code, I get the paddles and the ball to output, but then there's white fuzz at the top of the screen, and nothing happens unless I hold down enter, then the ball moves very slowly. When the ball goes to the other side of the screen, the program stops.
Any ideas as to what is going on? I have the variables already set at the top of the program, so it's not the variables if that's what you're thinking.
I also have the project uploaded to GitHub if you want to try it out yourself, to troubleshoot better. https://github.com/Spyderdude2001/Pong
Thank you if you help out!
Code:
When I run this code, I get the paddles and the ball to output, but then there's white fuzz at the top of the screen, and nothing happens unless I hold down enter, then the ball moves very slowly. When the ball goes to the other side of the screen, the program stops.
Any ideas as to what is going on? I have the variables already set at the top of the program, so it's not the variables if that's what you're thinking.
I also have the project uploaded to GitHub if you want to try it out yourself, to troubleshoot better. https://github.com/Spyderdude2001/Pong
Thank you if you help out!
Code:
void play(){
gfx_FillScreen(9);
gfx_Sprite(scoreErase,0,0);
ps(p1score,0,0);
gfx_Sprite(scoreErase,330,0);
ps(p2score,330,0);
do{
gfx_SetColor(gfx_white);
gfx_FillRectangle(ballx, bally, 4, 4);
gfx_FillRectangle(0,p1,5,20);
gfx_FillRectangle(316,p2,5,20);
delay(50);
if (ballx <= 6){
if (bally-3>=p1&&bally+3<=p1+19)
yballdir = floor((p1-bally-8)/2);
ballx = 6;
xballdir = 1;
}else{
score();
}
if (ballx >= 312){
if (bally-3>=p2&&bally+3<=p2+19)
yballdir = floor((p2-bally-8)/2);
ballx = 312;
xballdir = -1;
}else{
score();
}
if (bally<11 || bally>236)
yballdir = -yballdir;
ballx+=xballdir;
bally+=yballdir;
gfx_SetColor(gfx_black);
kb_Scan();
if (kb_Data[3] == kb_7){
gfx_FillRectangle(0,p1,5,20);
p1-=5;
}
if (kb_Data[3] == kb_1){
gfx_FillRectangle(0,p1,5,20);
p1+=5;
}
if (kb_Data[5] == kb_3){
gfx_FillRectangle(316,p2,5,20);
p2+=5;
}
if (kb_Data[5] == kb_9){
gfx_FillRectangle(316,p2,5,20);
p2-=5;
}
if (kb_Data[6] == kb_Clear){
leave = 1;
}
if (p1<10)
p1=10;
if (p1>221)
p1 = 221;
if (p2<10);
p2=10;
if (p2>221)
p2 = 221;
}while(p1score<7 && p2score<7 || leave == 1);
ps("Press [CLEAR] for Main Menu",80,120);
ps("Press [ENTER] to Play Again",60,130);
delay(5000);
}