So I'm developing a game called PongBreakout in c++ using a game engine i got from uni (when i was there..) I've got a few problems with my game that i'm struggling to fix and need some help to figure out how to do so.
the first bug is that the countdown is far to fast and i dont know how to slow it down - ive been told to use a scalar (not a clue what that is..) <- ball.cpp (Update())
the code for this is below, I've debugged the value for .mdframetime and it keeps varying between 0.016 and 0.015 however it remains to countdown far to fast.
double frametime = g_theTimer.mdFrameTime; // Update frametime
if (reset == true) // If the ball needs reseting.
{
countdown -= frametime; // Reduce countdown - This needs fixing its far to fast.
if(countdown > 2)
{
pTheDrawEngine->WriteText(512,384,"3");
}
else if(countdown > 1)
{
pTheDrawEngine->WriteText(512,384,"2");
}
else if(countdown > 0)
{
pTheDrawEngine->WriteText(512,384,"1");
}
if(countdown <= 0)
{
countdown = 3;
reset = false;
position.set(512, 384);
}
}
the second bug is that the ball sometimes gets stuck at the side of the screen if the paddle is there (play it and you'll eventually notice it.) <- ball.ccp (ProcessCollisons())
void Ball::PanelCollision(Rectangle2D Panel1, Rectangle2D Panel2, Rectangle2D Panel3)
{
if (BallOutline.Intersects(Panel1))
{
velocity.XValue *= -1;
velocity.YValue = 5 * ((position.YValue - Panel1.GetCentre().YValue) / 25);
}
else if (BallOutline.Intersects(Panel2))
{
velocity.XValue *= -1;
velocity.YValue = 5 * ((position.YValue - Panel2.GetCentre().YValue) / 25);
}
else if (BallOutline.Intersects(Panel3))
{
velocity.XValue *= -1;
velocity.YValue = 5 * ((position.YValue - Panel3.GetCentre().YValue) / 25);
}
}
I'm not to sure about whats wrong with this function, as it works untill the panels are at positon 0 or 768 it causes the ball to stick and in some cases go of the screen but still be drawn in the same place.
Do you think its possibly best to make a counter that will increase, after x ammount of times its increased the ball is obviously stuck so get the position of the panel and the positition of the panel, take them away to get the value of how close the ball is stuck towards the center of the panel and minus it away to unstick it?
the third bug is that the rand() function doesnt seem to be working for getting a value between 8 and 5. <- ball.cpp
srand (time(NULL)); // Seed the random
switch(rand() % 4 + 1) // Which way should the ball shoot off?
{
case 1: velocity.set(rand()%4 + 5 ,-rand() % 5 + 1); // Rand is broken. Why? - Needs to be between 5 and 7. for X
break;
case 2: velocity.set(-rand()%4 + 5 ,rand() % 5 + 1);
break;
case 3: velocity.set(rand()%4 + 5 ,rand() % 5 + 1);
break;
case 4: velocity.set(-rand()%4 + 5 ,-rand() % 5 + 1);
break;
}
the rand() function needs to return a value between 5 and 7 but its returning values less than 5 in some cases and i cant figure out why. ive tried the max - min + min method and that didn't work either.
To run this game you need direct x aug 2009.
https://www.dropbox.com/sh/yykud3daabght8y/aejKK5bXFZ
http://www.microsoft.com/en-us/download/details.aspx?id=23549
Everything related to my code is on on my dropbox.