# Helping fix a few things.

This topic is 1775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey,

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 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())
the third bug is that the rand() function doesnt seem to be working for getting a value between 8 and 5. <- ball.cpp
And lastly the cpu paddle is very buggy movement wise, is there anyway to make it move a bit better instead of always juttering.. <- enemyboard.cpp

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 required is on on my dropbox.

##### Share on other sites

A scalar is a single value, like "2" or ".01".  They usually...scale things.  Scalar is often used in the same concept space as "vector" and the difference there is that a vector has its multiple fields (x, y, and z value, for example) while a scalar is just a solitary value.

You can multiply two scalars together,

2 * .4 = .8

and multiply a vector by a scalar,

(1,1,0) * 2 = (2,2,0)

but you can't multiply two vectors together (what does that even mean, anyway?).  Vectors have specific operations like dot- and cross-products.  Though you CAN add and subtract them, if they're the same dimension.

TL;DR: someone has told you to use a scalar to reduce the countdown speed, so you probably want to find the spot in your code that's counting down, determine what numerical value it's using as the check (I hope it's time-based and not frames-based, as the latter will run at different speeds on different PCs), and then multiply that by some number (either increasing it or decreasing it) to reach the desired countdown speed.

I can't check the other bugs thanks to corporate firewall disliking dropbox.

##### Share on other sites

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())

My guess for #2 is, if the paddle is moved to intersect the ball while the ball is in the middle of the paddle, the X-velocity isn;'t large enough so that, on the next frame, it can't move outside the boundary of the paddle, so the x-velocty values just toggles between +X and -X each frame.  I would ensure the ball is moved to the edge of the paddles boundary before negating the X velocity.

the third bug is that the rand() function doesnt seem to be working for getting a value between 8 and 5. <- ball.cpp

The line:

case 1: velocity.set((rand()%(8-5)+5),-rand() % 5 + 1); // Rand is broken. Why?


Will set X between 5 and 7, since rand()%(8-5) will return 0, 1, or 2, and adding it to 5 will give 5, 6, or 7.

Is that what you are seeing?  You need to make it rand()%4 + 5 if you want a random value from 5 to 8.

And lastly the cpu paddle is very buggy movement wise, is there anyway to make it move a bit better instead of always juttering.. <- enemyboard.cpp

If the Y-velocity of the ball is less than half the Y speed of the enemy paddle (ie, enemy paddle is 5, and Y velocity is 2), then the paddle will jump back and forth according to your code.  Imagine PaddleY is 100, and BallY is 99.  You will move the PaddleY = 95 the next frame, and the BallY = 97.  Now you will move the PaddleY back up to 100 since PaddleY < BallY.

You could, instead of always moving the enemy paddle the maximum speed, simple move it the the Y difference if it is smaller than the maximum speed.  Change this:

// Change this...

else if (position.YValue > BallPos.YValue)
{
position.YValue = position.YValue - speed;

}
// To This...

else if (position.YValue > BallPos.YValue)
{
position.YValue = position.YValue - MIN(speed, position.YValue - BallPos.YValue);
}

//Where MIN returns the minimum of the 2 values.


##### Share on other sites

the third bug is that the rand() function doesnt seem to be working for getting a value between 8 and 5. <- ball.cpp

The line:

case 1: velocity.set((rand()%(8-5)+5),-rand() % 5 + 1); // Rand is broken. Why?


Will set X between 5 and 7, since rand()%(8-5) will return 0, 1, or 2, and adding it to 5 will give 5, 6, or 7.

Is that what you are seeing?  You need to make it rand()%4 + 5 if you want a random value from 5 to 8.

What was actually happening is that it was still somehow being set between 3 - 8 and i wasnt sure why.

I'll be sure to try get these fixes into place tomorrow morning,.

EDIT: rand is still returning values less than the minimum value.

Edited by Dynamite Andy