
-----------------------------------
gergysun
Fri Nov 30, 2007 6:36 pm

Paddle And Ball Collision Help
-----------------------------------
PLEASE can someone HELP ME....This is my THIRD topic about this subject and no one has answered my question.

question :  " How can i get my pong ball to bounce off the paddle????"
i already have it set up to if it misses the paddle, (ie, hits bottom edge) the program finishes, and i have it that that ball bounces off of my borders but i cannot figure out how to make the ball bounce off the paddle. Someone said that it is the same code that i used to the borders, but ive tried different combinations like about 100 times... plz someone answer my question

here is my code

drawfill (1, 399, 150, 150)
% Ball is slding across title
var font1 : int %defiing font as an integer
font1 := Font.New ("Stencil:30") % defining font size
assert font1 > 0
Font.Draw ("Greg's Ping Pong Game", 160, 325, font1, red) % Main Title
Font.Free (font1)
colorback (6) % the background color
locate (7, 30)
var title1 : int %defines title1 as an integer
title1 := 10

loop %begins title loop
    %Title wiper
    drawfilloval (title1, 335, 20, 20, 12)
    exit when title1 = 600
    delay (50)%delay's playback 50 milliseconds
    drawfilloval (title1, 335, 20, 20, 158) % draws circle and fills it
    title1 := title1 + 10
end loop %ends title loop

cls % clears the screen
colorback (12)% defining background color
put " ---The intructions are ---- " % outputs "Intructions"
put " "% skips a line
put " Move the Paddle with mouse " % outputs actual instructions
put " Each time you keep the ball up in the air you reieve a point"% outputs actual instructions
put " If you miss the ball, you lose "% outputs actual instructions
put " "% skips a line
put " "% skips a line
put " "% skips a line
put " "% skips a line
put " "% skips a line

% press any key to continue
font1 := Font.New ("Stencil:20")%defines font1 as font.new and font size
Font.Draw ("~~Press any Key to Begin~~", 90, 125, font1, red)

Input.Pause % won't continue until user presses a key

colourback (blue)% defining bacground color
cls % Clears the screen
setscreen ("offscreenonly")

var rise, run, rad, u, yy, xx : int%defiing rise,run,rad,yy,xx as integers
var bally, ballx : int := 200% defining bally,ballx as integers
rad := 10 %defines Radius of ball
rise := 2% defines where the ball starts
run := 2 % defines where the ball starts

loop%begins main loop


    var x, y, button : int %defines x,y,button as integers
    Mouse.Where (x, y, button)%indicates where the mouse is
    Draw.FillOval (ballx, bally, rad, rad, yellow)% draws pong ball
    ballx := ballx + run
    bally := bally + rise


    if ballx + 50 >= maxx then
        run := -1
    elsif ballx - 50 = maxy then
        rise := -1

    elsif bally - 50 