Thanks for coming by, I have made my Pong game, Ive already done it once, But now with more features, Its called The Pongster, Critique my game, And you can download the Source and the Game and If you have time, Play it and tell me how it is.
Its got Music and stuff too.
Thanks!
Note: This is compiled in Windows 7 and i doubt it would work in Windows XP, But i will be uploading the Windows XP version soon. Thanks.
Source and Game:
http://www.mediafire...7vg478qq7kgquu9
ScreenShots:
Code Sample:
There is a Lot of code in the project and i cant post everything, So here is some incase you dont believe me
main.cpp
/*COPYRIGHT*/
/* This game was solemnly made by Rahul */
/*Finished at March 9th, 2012 */
/* Compiled in Windows 7, EXPORTED AND COMPILED IN Windows XP too */
/*You are welcome to use the code for knowledge, If you are using it on your code, send a shout to my name */
/*Enjoy the Game! */
#include "game.h"
int main( int argc, char** argv )
{
Game g;
g.Start();
return 0;
}
paddle.h
#ifndef _PADDLE_H
#define _PADDLE_H
#include "functions.h"
#include "game.h"
class Paddle : public Functions
{
private:
float x1, y1, x2, y2;
float velocity;
int w, h;
SDL_Surface *img, *img1;
public:
Paddle();
~Paddle();
virtual void DrawImage();
virtual bool loadImage();
void Move( SDL_Event event );
void computerAI( float y, bool cEasy, bool cHard, bool cMighty);
SDL_Rect* getPRect(); //Players rect
SDL_Rect* getCRect(); //Computers rect
};
#endif
paddle.cpp
#include "paddle.h"
Paddle::Paddle()
{
x1 = 10;
y1 = 320;
x2 = 610;
y2 = 240;
velocity = 2;
w = 20;
h = 70;
if(Easy) velocity = 2;
if(Hard) velocity = 5;
loadImage();
}
Paddle::~Paddle()
{
SDL_FreeSurface(img);
}
void Paddle::Move( SDL_Event event )
{
if( event.type == SDL_MOUSEMOTION)
{
y1 = event.motion.y;
if( y1 < 0 )
{
y1 = 0;
}
if( y1 > SDL_GetVideoSurface()->h - h )
{
y1 = (float)SDL_GetVideoSurface()->h - h;
}
}
}
void Paddle::DrawImage()
{
Functions::DrawImage(img, SDL_GetVideoSurface(), (int)x1, (int)y1);
Functions::DrawImage(img1, SDL_GetVideoSurface(), (int)x2, (int)y2);
}
bool Paddle::loadImage()
{
img = Functions::loadImage("GFX/paddle.bmp");
img1 = Functions::loadImage("GFX/paddle.bmp");
if(!img || !img1 )
{
printf("Error loading Paddle Image");
return false;
}
return true;
}
void Paddle::computerAI( float y, bool cEasy, bool cHard, bool cMighty )
{
if(cEasy)
{
if( y2 < y )
{
y2 += 3.0;
}
else if( y2 > y )
{
y2 -= 3.0;
}
}
else if(cHard)
{
if( y2 < y )
{
y2 += 5.0;
}
else if( y2 > y )
{
y2 -= 5.0f;
}
}
else if(cMighty)
{
y2 = y;
}
if( y2 < 0 )
y2 = 0;
if( y2 > SDL_GetVideoSurface()->h - h )
y2 = (float)SDL_GetVideoSurface()->h - h;
}
SDL_Rect* Paddle::getPRect()
{
SDL_Rect rect = { (int)x1, (int)y1, 20, 70 };
return ▭
}
SDL_Rect* Paddle::getCRect()
{
SDL_Rect rect = { (int)x2, (int)y2, 20, 70 };
return ▭
}
Thanks For playing my game!
~Rahul