Results 1 to 2 of 2

Thread: I need help with a motion system for a ball in c++(please help!)

                  
   
  1. #1
    DCEmu Newbie
    Join Date
    Nov 2007
    Posts
    18
    Rep Power
    0

    Default I need help with a motion system for a ball in c++(please help!)

    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...

  2. #2
    DCEmu Newbie
    Join Date
    Nov 2007
    Posts
    18
    Rep Power
    0

    Default

    Nevermind, I got it... see hehehe

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Motion kit driver announcement
    By wraggster in forum Sony Consoles News Forum
    Replies: 3
    Last Post: December 15th, 2007, 23:11
  2. Dragon Ball Z Blasts Onto Handhelds
    By wraggster in forum Sony Consoles News Forum
    Replies: 6
    Last Post: February 27th, 2007, 14:48
  3. Review: Intec Sound System
    By bandit in forum DCEmu Reviews & Games Reviews Forum
    Replies: 0
    Last Post: May 1st, 2006, 22:27
  4. Review: Logic3 2.1 Sound System
    By bandit in forum DCEmu Reviews & Games Reviews Forum
    Replies: 0
    Last Post: May 1st, 2006, 22:13
  5. Replies: 0
    Last Post: November 27th, 2004, 03:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •