Jump to content

  • Log In with Google      Sign In   
  • Create Account

Helping fix a few things.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Dynamite Andy   Members   -  Reputation: 119

Like
0Likes
Like

Posted 15 March 2013 - 07:50 AM

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.

Sponsor:

#2 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

Posted 15 March 2013 - 08:25 AM

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.


Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#3 BeerNutts   Crossbones+   -  Reputation: 2998

Like
0Likes
Like

Posted 15 March 2013 - 10:13 AM

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.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 Dynamite Andy   Members   -  Reputation: 119

Like
0Likes
Like

Posted 15 March 2013 - 04:50 PM

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, 16 March 2013 - 05:41 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS