Ah! That's perfect! I actually thought of using break before, but I never tested it. I assumed it wouldn't work, because the only time I had used break before was with switch(). Thank you, yet again!
The final source for the app is below, I don't know if you're interested in how it turns out. It's super-basic, and the system for adjusting angles is sub-par.
/*
Pong Clone, Written by Mike Perron on December 8, 2007.
The idea of this project was to learn how to use DarkGDK with Visual C++ 2008 Express.
*/
#define ball 1
#define paddle 2
#define background 3
#define player 5
#define cpu 6
int ballDirection= 0;
int ballVert= 0;
int lastPlayerPos= 0;
int lastCPUPos= 0;
int playerScore= 0;
char playerSchar;
int cpuScore= 0;
char cpuSchar;
char szTemp[128];
int winner= 0;
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSetWindowTitle("Pong Clone");
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetTextFont("Verdana");
dbSetTextSize(16);
//Internal Media Creation through bitmap manipulation (image numbers defined)
dbCreateBitmap(1,35,35); //Draw ball image
dbSetCurrentBitmap(1);
dbInk(RGB(255,255,255),RGB(0,0,0));
dbBox(0,0,35,35);
dbGetImage(ball,0,0,35,35);
dbSetCurrentBitmap(0);
dbDeleteBitmap(1);
dbCreateBitmap(1,20,120); //Draw padddle image
dbSetCurrentBitmap(1);
dbInk(RGB(255,255,255),RGB(0,0,0));
dbBox(0,0,20,120);
dbGetImage(paddle,0,0,20,120);
dbSetCurrentBitmap(0);
dbDeleteBitmap(1);
dbCreateBitmap(1,dbScreenWidth(),dbScreenHeight());
dbSetCurrentBitmap(1);
dbInk(RGB(1,0,0),RGB(0,0,0));
dbBox(0,0,dbScreenWidth(),dbScreenHeight());
dbGetImage(background,0,0,dbScreenWidth(),dbScreenHeight());
dbSetCurrentBitmap(0);
dbDeleteBitmap(1);
dbCreateBitmap(player,100,25);
dbSetCurrentBitmap(player);
dbCLS(RGB(0,0,0));
dbInk(RGB(255,255,255),RGB(255,255,255));
sprintf(szTemp,"%d",playerScore);
dbPrint(szTemp);
dbGetImage(player,0,0,100,25);
dbSetCurrentBitmap(0);
dbCreateBitmap(cpu,100,25);
dbSetCurrentBitmap(cpu);
dbCLS(RGB(0,0,0));
dbInk(RGB(255,255,255),RGB(255,255,255));
sprintf(szTemp,"%d",cpuScore);
dbPrint(szTemp);
dbGetImage(cpu,0,0,100,25);
dbSetCurrentBitmap(0);
dbSprite(background,0,0,background);
dbSprite(ball,dbScreenWidth()/2-18,dbScreenHeight()/2-18,ball);
dbSprite(player,20,dbScreenHeight()/2-60,paddle);
dbSprite(cpu,dbScreenWidth()-40,dbScreenHeight()/2-60,paddle);
dbSprite(player+10,0,0,player);
dbSprite(cpu+10,dbScreenWidth()-100,0,cpu);
while (LoopGDK())
{
lastPlayerPos=dbSpriteY(player);
lastCPUPos=dbSpriteY(cpu);
//Player control
if ((dbUpKey()==1)&&(dbSpriteY(player)>0)){
dbSprite(player,dbSpriteX(player),dbSpriteY(player)-2,paddle);
}
if ((dbDownKey()==1)&&(dbSpriteY(player)<dbScreenHeight()-120)){
dbSprite(player,dbSpriteX(player),dbSpriteY(player)+2,paddle);
}
//CPU control
if ((dbSpriteY(ball)+18<dbSpriteY(cpu)+60)&&(dbSpriteY(cpu)+60-dbSpriteY(ball)+18>2)&&(ballDirection==0)){
dbSprite(cpu,dbSpriteX(cpu),dbSpriteY(cpu)-2,paddle);
}
if ((dbSpriteY(ball)+18<dbSpriteY(cpu)+60)&&(dbSpriteY(cpu)+60-dbSpriteY(ball)+18==1)&&(ballDirection==0)){
dbSprite(cpu,dbSpriteX(cpu),dbSpriteY(cpu)-1,paddle);
}
if ((dbSpriteY(ball)+18>dbSpriteY(cpu)-60)&&(dbSpriteY(ball)+18-dbSpriteY(cpu)-60>2)&&(ballDirection==0)){
dbSprite(cpu,dbSpriteX(cpu),dbSpriteY(cpu)+2,paddle);
}
if ((dbSpriteY(ball)+18>dbSpriteY(cpu)-60)&&(dbSpriteY(ball)+18-dbSpriteY(cpu)-60==1)&&(ballDirection==0)){
dbSprite(cpu,dbSpriteX(cpu),dbSpriteY(cpu)+1,paddle);
}
//Vertical Ball Collision and Motion
if (ballVert!=0){dbSprite(ball,dbSpriteX(ball),dbSpriteY(ball)+ballVert,ball);}
if (((dbSpriteY(ball)<0)&&(ballVert<0))||((dbSpriteY(ball)>dbScreenHeight()-35)&&(ballVert>0))){ballVert=ballVert*-1;}
if ((dbSpriteCollision(ball,cpu)==1)&&(dbSpriteY(ball)+18<dbSpriteY(cpu)+40)){ballVert=ballVert-2;}
if ((dbSpriteCollision(ball,cpu)==1)&&(dbSpriteY(ball)+18>=dbSpriteY(cpu)+40)&&(dbSpriteY(ball)+18<dbSpriteY(cpu)+80)&&(ballVert>0)){ballVert=ballVert-1;}
if ((dbSpriteCollision(ball,cpu)==1)&&(dbSpriteY(ball)+18>=dbSpriteY(cpu)+40)&&(dbSpriteY(ball)+18<dbSpriteY(cpu)+80)&&(ballVert<0)){ballVert=ballVert+1;}
if ((dbSpriteCollision(ball,cpu)==1)&&(dbSpriteY(ball)+18>dbSpriteY(cpu)+80)){ballVert=ballVert+2;}
if ((dbSpriteCollision(ball,player)==1)&&(dbSpriteY(ball)+18<dbSpriteY(player)+40)){ballVert=ballVert-2;}
if ((dbSpriteCollision(ball,player)==1)&&(dbSpriteY(ball)+18>=dbSpriteY(player)+40)&&(dbSpriteY(ball)+18<dbSpriteY(cpu)+80)&&(ballVert>0)){ballVert=ballVert-1;}
if ((dbSpriteCollision(ball,player)==1)&&(dbSpriteY(ball)+18>=dbSpriteY(player)+40)&&(dbSpriteY(ball)+18<dbSpriteY(cpu)+80)&&(ballVert<0)){ballVert=ballVert+1;}
if ((dbSpriteCollision(ball,player)==1)&&(dbSpriteY(ball)+18>dbSpriteY(player)+80)){ballVert=ballVert+2;}
//Horizontal Ball Collision and Motion
if (ballDirection==0){dbSprite(ball,dbSpriteX(ball)+2,dbSpriteY(ball),ball);}
if ((ballDirection==0)&&(ballVert>0)){dbSprite(ball,dbSpriteX(ball)+ballVert,dbSpriteY(ball),ball);}
if ((ballDirection==0)&&(ballVert<0)){dbSprite(ball,dbSpriteX(ball)-ballVert,dbSpriteY(ball),ball);}
if (ballDirection==1){dbSprite(ball,dbSpriteX(ball)-2,dbSpriteY(ball),ball);}
if ((ballDirection==1)&&(ballVert>0)){dbSprite(ball,dbSpriteX(ball)-ballVert,dbSpriteY(ball),ball);}
if ((ballDirection==1)&&(ballVert<0)){dbSprite(ball,dbSpriteX(ball)+ballVert,dbSpriteY(ball),ball);}
if (dbSpriteCollision(ball,cpu)==1){ballDirection=1;}
if (dbSpriteCollision(ball,player)==1){ballDirection=0;}
//Scoring; score management
if (dbSpriteX(ball)<dbSpriteX(player)+15){
cpuScore=cpuScore+1;
ballDirection=0;
ballVert=dbRND(2)-1;
dbSetCurrentBitmap(cpu);
dbCLS(RGB(0,0,0));
dbInk(RGB(255,255,255),RGB(255,255,255));
sprintf(szTemp,"%d",cpuScore);
dbPrint(szTemp);
dbGetImage(cpu,0,0,100,25);
dbSetCurrentBitmap(0);
dbSprite(cpu+10,dbScreenWidth()-100,0,cpu);
sprintf(szTemp,"Pong Clone (Player: %d; CPU: %d)",playerScore,cpuScore);
dbSetWindowTitle(szTemp);
}
if (dbSpriteX(ball)>dbSpriteX(cpu)-30){
playerScore=playerScore+1;
ballDirection=1;
ballVert=dbRND(2)-1;
dbSetCurrentBitmap(player);
dbCLS(RGB(0,0,0));
dbInk(RGB(255,255,255),RGB(255,255,255));
sprintf(szTemp,"%d",playerScore);
dbPrint(szTemp);
dbGetImage(player,0,0,100,25);
dbSetCurrentBitmap(0);
dbSprite(player+10,0,0,player);
sprintf(szTemp,"Pong Clone (Player: %d; CPU: %d)",playerScore,cpuScore);
dbSetWindowTitle(szTemp);
}
if (playerScore==10){winner=1;}
if (cpuScore==10){winner=2;}
//System
dbSync();
if (winner!=0){break;}
}
dbSyncOff();
if (winner==1){dbSetWindowTitle("Player wins!");}
if (winner==2){dbSetWindowTitle("CPU wins!");}
dbWait(3000);
return;
}