User User name Password  
   
Thursday 9.1.2025 / 08:55
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > consoles > sony psp - homebrew software > i need help with a motion system for a ball in c++(please help!)
Show topics
 
Forums
Forums
I need help with a motion system for a ball in c++(please help!)
  Jump to:
 
Posted Message
Junior Member

1 product review
_
21. June 2009 @ 10:52 _ Link to this message    Send private message to this user   
--------------------------------------------------------------------------------

ok ive been making this pong game for a few days now (im a new programmer and this is my first game) and im almost done,Ive got a working menu screen, paddles move, collision detection, everythings fine...
BUT when I tried to make a motion system it just hits the paddle and stops and if you move the paddle the ball will continue to go off the screen and restart the game?
I know what is causing this problem but it will be easier if I show you the source code first.


if(active == 1)//if X is pressed
{
bx = move_left(bx,speed)
if(bx == 451)
{
if(CollisionDetection(bx,by,10,11,451,by,10,53) == 1)
{
bx = move_left(bx,speed);
}
else
{
bx = move_right(bx,speed);
}
}
if(bx == 12)
{
if(CollisionDetection(bx,by,10,11,12,py,10,53) == 1)
{
bx = move_left(bx,speed);
}
else
{
bx = move_right(bx,speed);
}
}
}//this is all in a while loop


bx is an int and it is responsible for the balls x position
speed is the speed of the ball
bx = move_right() and bx = move_left() make the ball move left or right and they work perfectly
CollisionDetection() does exactly what it sounds like and perfectly.
=================================
my problem is every time you press x to start the game the ball moves in the direction it should, but when it collides it just stops and if you move the paddle while the ball is stopped, right after the paddle isnt colliding with the ball it continues to go past me and I lose (its like playint pong with Chuck Norris)
this happens because the first thing there makes the ball move left and since that is repeated continuously in the while loop it will always move left until it hits the paddle and then after you move the paddle it will move left again.
how would I get the ball to move in a direction and then bounce back?
Please can somebody help me??
(right now Im only working on the x position not the y)
I might solve this on my own after I post this but im not sure...

I suck
Junior Member

1 product review
_
21. June 2009 @ 11:04 _ Link to this message    Send private message to this user   
nevermind, I got it

I suck
afterdawn.com > forums > consoles > sony psp - homebrew software > i need help with a motion system for a ball in c++(please help!)
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2025 by AfterDawn Ltd.

  IDG TechNetwork