Hi,
I recently downloaded and installed Dark GDK and wanted to make a simple pong game, but I get some errors, which I can't fix.
I looked several times through the code but to me it looks just fine.
Here are the files (they're also attached)
ball.cpp
#include "DarkGDK.h"
#include "paddle.h"
#include "ball.h"
Ball::Ball( int px, int py, int pradius, int pdirX, int pdirY )
{
x = px;
y = py;
radius = pradius;
dirX = pdirX;
dirY = pdirY;
return;
}
int Ball::GetX() const
{
return x;
}
int Ball::GetY() const
{
return y;
}
int Ball::GetRadius() const
{
return radius;
}
void Ball::Update( const Paddle& ppaddleLeft, const Paddle& ppaddleRight )
{
// move ball
x += 1*dirX;
y += 1*dirY;
//check on collision with the bounds
if( y - radius <= 0 )
dirY *= -1;
if( y + radius >= 600 )
dirY *= -1;
//if( x - radius < 0 )
//if( x + radius > 800 )
// check on collision with the paddles
if( y - radius > ppaddleLeft.GetY() - ppaddleLeft.GetL()/2 && y + radius < ppaddleLeft.GetY() + ppaddleLeft.GetL()/2 )
{
if( x - radius <= ppaddleLeft.GetX() + ppaddleLeft.GetW()/2 && x - radius > ppaddleLeft.GetX() - ppaddleLeft.GetW()/2 )
dirX *= -1;
}
if( y - radius > ppaddleRight.GetY() - ppaddleRight.GetL()/2 && y + radius < ppaddleRight.GetY() + ppaddleRight.GetL()/2 )
{
if( x + radius > ppaddleRight.GetX() - ppaddleRight.GetW()/2 && x + radius < ppaddleRight.GetX() + ppaddleRight.GetW()/2 )
dirX *= -1;
}
return;
}
void Ball::Draw() const
{
dbInk( dbRgb( 255, 255, 255 ), dbRgb( 255, 255, 255 ) );
dbCircle( x, y, radius );
return;
}
ball.h
#ifndef _BALL_
#define _BALL_
#include "paddle.h"
class Ball
{
private:
int x;
int y;
int radius;
int dirX;
int dirY;
public:
Ball( int, int, int, int, int );
int GetX() const;
int GetY() const;
int GetRadius() const;
void Update( const Paddle&, const Paddle& );
void Draw() const;
};
#endif
main.cpp
#include "DarkGDK.h"
#include "ball.h"
#include "paddle.h"
void DarkGDK( void )
{
dbSyncOn();
dbSyncRate( 30 );
dbSetDisplayMode( 800, 600, 32 );
// create ball and players
Ball ball( 400, 300, 10, 1, 1 );
Paddle paddles[2] = { Paddle( 15, 300, 10, 20, false ), Paddle( 785, 300, 10, 20, true ) };
while( LoopGDK() )
{
dbCLS( dbRGB( 0, 0, 0 ) );
ball.Update( paddles[0], paddles[1] );
paddles[0].Update( ball );
paddles[1].Update( ball );
dbSync();
}
return;
}
paddle.cpp
#include "DarkGDK.h"
#include "paddle.h"
#include "ball.h"
Paddle::Paddle( int px, int py, int pl, int pw, bool phuman )
{
x = px;
y = py;
l = pl;
w = pw;
human = phuman;
return;
}
int Paddle::GetX() const
{
return x;
}
int Paddle::GetY() const
{
return y;
}
int Paddle::GetL() const
{
return l;
}
int Paddle::GetW() const
{
return w;
}
void Paddle::Update( const Ball& pball )
{
if( human )
{
if( dbUpKey() )
{
y -= 1;
if( y - l/2 < 0 )
y = l/2;
}
if( dbDownKey() )
{
y += 1;
if( y + l/2 > 600 )
y = 600 - l/2;
}
}
else
{
if( y > pball.GetY() )
{
y -= 1;
if( y - l/2 > 0 )
y = l/2;
}
if( y < pball.GetY() )
{
y += 1;
if( y + l/2 > 600 )
y = 600 - l/2;
}
}
return;
}
void Paddle::Draw() const
{
dbInk( dbRgb( 255, 255, 255 ), dbRgb( 255, 255, 255 ) );
dbBox( x - w/2, y - l/2, x + w/2, y + l/2 );
return;
}
paddle.h
#ifndef _PADDLE_
#define _PADDLE_
#include "ball.h"
class Paddle
{
private:
int x;
int y;
int w;
int l;
bool human;
public:
Paddle( int, int, int, int, bool );
int GetX() const;
int GetY() const;
int GetW() const;
int GetL() const;
void Update( const Ball& );
void Draw() const;
};
#endif
I hope someone can help, because I'm really dispair of these eror messages.
Thank you in advance and sorry for the not very descriptive thread title.