I've been going through major hell trying to get just one. damn. simple. little. game. working. I can't even complete ping pong! There's almost no game easier than ping pong, and I can't even do it after so much stress trying, and I'm becoming so frustrated over this that I want to kill everyone.
I don't have any clue on how to post code tags here.
This is my best code so far, and not enough enough to do anything decent, and I'm dead tired after spending hours writing this:
....#include <SDL/SDL.h>
void PlayerControl(SLD_Surface* TEMPIMAGEHM, SDL_Surface* BGTEMP1, short PTheight, short PTwidth, short PTxspeed, short PTyspeed, short PTxoff, short PTyoff);
void ComputerControl(SDL_Surface* TEMPIMAGECO, SDL_Surface* BGTEMP2, short CTheight, short CTwidth, short CTxspeed, short CTyspeed, short CTxoff, short CTyoff);
void GameBall(SDL_Surface* TEMPIMAGEBALL, SDL_Surface* BGTEMPBALL, short BTheight, short BTwidth, short BTxspeed, short BTyspeed, short BTxoff, short BTyoff);
void ScoreBar(SDL_Surface* SCORETEMP, SDL_Surface* BGTEMP3, short STheight, short STwidth, short STxspeed, short STyspeed, short STxoff, short STyoff);
void ReadyText(SDL_Surface* READYTEXT, SDL_Surface* BGTEMP4, short RTheight, short RTwidth, short RTxspeed, short RTyspeed, short RTxoff, short RTyoff);
void GoText(SDL_Surface* GOTEXT, SDL_Surface* BGTEMP4, short GTheight, short GTwidth, short GTxspeed, short GTyspeed, short GTxoff, short GYyoff);
void BALLFINDER(SDL_Surface TEMPBALLXPRINT, SDL_Surface *TEMPBALLYPRINT, short, short);
struct GameBall
{
short Bheight;
short Bwidth;
short Bxspeed;
short Byspeed;
short Bxoff;
short Byoff;
bool InBounds;
}; GameBall BALL;
struct ScoreBar
{
short Sheight;
short Swidth;
short Sxspeed;
short Syspeed;
short Sxoff;
short Syoff;
bool Sapply;
}; ScoreBar SCORE;
struct ReadySplash
{
short Rheight;
short Rwidth;
short Rxspeed;
short Ryspeed;
short Rxoff;
short Ryoff;
bool Rapply;
}; ReadySplash READYTEXT;
struct GoSplash
{
short Gheight;
short Gwidth;
short Gxspeed;
short Gyspeed;
short Gxoff;
short Gyoff;
short Gapply;
}; GoSplash GOTEXT;
struct playerpaddle
{
short Pheight;
short Pwidth;
short Pxspeed;
short Pyspeed;
short Pxoff;
short Pyoff;
short PPoints;
bool PCanMove;
}; playerpaddle Player;
struct computerpaddle
{
short Cheight;
short Cwidth;
short Cxspeed;
short Cyspeed;
short Cxoff;
short Cyoff;
short CPoints;
bool CCanMove;
}; computerpaddle Computer;
struct computerlogistics
{
double CReactSpeed;
double CReactFromFirst;
double CReactFromLast;
double CFocusPercentage;
short firstmeasure;
short lastmeasure;
int randomizer;
}; computerlogistics CPU;
int main(int args, char LOCATION[])
{
bool GAMELOOP = 1;
playerpaddle Player;
computerpaddle Computer;
GameBall BALL;
Scorebar SCORE;
ReadySplash READYTEXT;
GoSplash GOTEXT;
Player.Pheight = 30;
Player.Pwidth = 64;
Player.Pxspeed = 0;
Player.Pyspeed = 0;
Player.Pxoff = 136;
Player.Pyoff = 385;
Player.PCanMove = true;
Computer.Cheight = 30;
Computer.Cwidth = 64;
Computer.Pxspeed = 0;
Computer.Pyspeed = 0;
Computer.Cxoff = 136;
Computer.Cyoff = 15;
Ball.Bheight = 26;
Ball.Bwidth = 26;
Ball.Bxspeed = 0;
Ball.Byspeed = 0;
Ball.Bxoff = 174;
Ball.Byoff = 199;
READYTEXT.Rheight = 60;
READYTEXT.Rwidth = 124;
READYTEXT.Rxspeed = 0;
READYTEXT.Ryspeed = 0;
READYTEXT.Rxoff = 140;
READYTEXT.Ryoff = 101;
GOTEXT.Gheight = 60;
GOTEXT.Gwidth = 124;
GOTEXT.Gxspeed = 0;
GOTEXT.Gyspeed = 0;
GOTEXT.Gxoff = 140;
GOTEXT.Gyoff = 101;
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* PLAYERPADDLE = SDL_LoadBMP("playerpaddle.bmp");
SDL_Surface* COMPUTERPADDLE = SDL_LoadBMP("computerpaddle.bmp");
SDL_Surface* BALL = SDL_LoadBMP("ball.bmp");
SDL_Surface* SCOREBAR = SDL_LoadBMP("score.bmp");
SDL_Surface* READYMSG = SDL_LoadBMP("readysplash.bmp");
SDL_Surface* GOMSG = SDL_LoadBMP("gosplash.bmp");
SDL_Surface* SCREEN = SDL_SetVideoMode(32, 400, 450, SDL_SWSURFACE, SDL_HWSURFACE, SDL_DOUBLEBUF);
SDL_SetColorKey( PLAYERPADDLE, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, 255, 0, 255) );
SDL_SetColorKey( COMPUTERPADDLE, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, 255, 0, 255) );
SDL_SetColorKey( BALL, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, 255, 0, 255) );
SDL_Event EVENT;
if(GAMELOOP == 1)
{
if(SDL_PollEvent(&EVENT))
{
if(Player.PCanMove == true)
if(EVENT.type == SDL_KEYDOWN)
{
switch(EVENT.key.keysym.sym)
{
case SDLK_RIGHT: Player.xpos += 1; break;
case SDLK_LEFT: Player.Xpos -= 1; break;
}
else if(EVENT.type == SDL_QUIT)
{
GAMELOOP = 0;
}
}
SDL_FillRect(SCREEN, NULL, SDL_MapRGB(SCREEN->format, 220, 50, 192));
PlayerControl(PLAYERPADDLE, SCREEN, Player.Pheight, Player.Pwidth, Player.Pxspeed, Player.Pyspeed, Player.Pxoff, Player.Pyoff);
ComputerControl(COMPUTERPADDLE, SCREEN, Computer.Cheight, Computer.Cwidth, Computer.Cxspeed, Computer.Cyspeed, Computer.Cxoff, Computer.Cyoff);
SDL_Flip(SCREEN);
}
}
}
void PlayerControl(SLD_Surface* TEMPIMAGEHM, short PTheight, short PTwidth, short PTxspeed, short PTyspeed, short PTxoff, short PTyoff);
{
SDL_Rect SRC;
SDL_RECT DST;
SRC.x = PTxspeed;
SRC.y = PTyspeed;
SRC.h = PTheight;
SRC.w = PTwidth;
DST.x = PTxoff;
DST.y = PTyoff;
DST.w = PTwidth;
DST.h = PTheight;
SDL_BlitSurface(PLAYERPADDLE, &SRC, SCREEN, &DST);
}
void ComputerControl(SDL_Surface* TEMPIMAGECO, SDL_Surface* BGTEMP2, short CTheight, short CTwidth, short CTxspeed, short CTyspeed, short CTxoff, short CTyoff);
{
short SCRNCENTXL1 = 200;
short SCRNCENTXL2 = 220;
short SCRNCENTXL3 = 240;
short SCRNCENTXL4 = 260;
short SCRNCENTXL5 = 280;
short SCRNCENTXL6 = 300;
short SCRNCENTXL7 = 320;
short SCRNCENTXL8 = 340;
short SCRNCENTXL9 = 360;
short SCRNCENTXL10 = 380;
short SCRNCENTXL11 = 180;
short SCRNCENTXL12 = 160;
short SCRNCENTXL13 = 140;
short SCRNCENTXL14 = 120;
short SCRNCENTXL15 = 100;
short SCRNCENTXL16 = 80;
short SCRNCENTXL17 = 60;
short SCRNCENTXL18 = 40;
short SCRNCENTXL19 = 20;
short BALLCURX = GameBall.Bxspeed;
short BALLCURY = GameBall.BYspeed;
short *BALLFINDERX = &BALLCURX;
short *BALLFINDERY = &BALLCURY;
computerlogistics CPU;
CPU.firstmeasure ++;
CPU.lastmeasure;
srand((unsigned)time(0));
CPU.randomizer = rand();
rand() % 2;
switch(randomizer)
{
case default: CPU.CFocusPercentage = 0.8; CPU.lastmeasure ++; break;
case 1: CPU.CFocusPercentage = 1.2; CPU.lastmeasure ++; break;
case 2: CPU.CFocusPercentage = 1; CPU.lastmeasure ++; break;
}
switch(randomizer)
{
case default: CPU.CReactSpeed = 0.2; break;
case 1: CPU.CReactSpeed = 0.3; break;
case 2: CPU.CReactSpeed = 0.4; break;
}
CPU.CReactSpeed + CPU.CFocusPercentage = CPU.CReactFromFirst;
rand() % 1;
switch(randomizer)
{
case default: CPU.CReactFromLast = 1.2; break;
case 1: CPU.CReactFromLast = 1.6; break;
}
CPU.CReactFromLast = CPU.lastmeasure * BALLFINDER;
void BALLFINDER(BALLCURX, BALLCURY, BALLFINDERX, BALLFINDERY);
if(BALLCURX < 225)
{
}....