Paddle And Ball Collision Help 
	 
	
		| Author | 
		Message | 
	 
		 
		gergysun
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Nov 30, 2007 6:36 pm    Post subject: 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 <= 0 then
 
        run := +1
 
    elsif bally + 50 >= maxy then
 
        rise := -1
 
 
    elsif bally - 50 <= 0 then
 
        exit
 
    end if
 
 
 
 
 
    View.Update
 
    delay (10) % delay's playback 10 milliseconds
 
    cls %Clears the screen
 
    % Paddle
 
    Draw.Box (50, 50, maxx - 50, maxy - 50, white)%draws main border
 
    drawfill (50, 40, white, white)% draws inside-outise white box
 
    drawfillbox (x - 80, 66, x + 80, 75, brightcyan) % Draws paddle
 
    % outside rectangle + fill
 
    drawline (40, 30, 40, 370, black)% draws line
 
    drawline (40, 30, 600, 30, black)% draws line
 
    drawline (600, 30, 600, 370, black)% draws line
 
    drawline (600, 370, 40, 370, black)% draws line
 
    drawfill (0, 10, brightred, black)%fills outside border brightred
 
end loop % ends the main loop
 
 
 
 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		StealthArcher
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Nov 30, 2007 6:50 pm    Post subject: Re: Paddle And Ball Collision Help  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				gergysun @ Fri Nov 30, 2007 5:36 pm wrote: 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 probably could start by being patient and not making new topics everytime i feel ignored....
 
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
 	  | Turing: | 	 		  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 <=  0 then
        run  := + 1
    elsif bally +  50 >=  maxy then
        rise  := - 1
    elsif bally -  50 <=  0 then
        exit
    end if
    View.Update
    delay (10) % delay's playback 10 milliseconds
    cls %Clears the screen
    % Paddle
    Draw.Box (50,  50,  maxx -  50,  maxy -  50,  white)%draws main border
    drawfill  (50,  40,  white,  white)% draws inside-outise white box
    drawfillbox (x -  80,  66, x +  80,  75,  brightcyan) % Draws paddle
    % outside rectangle + fill
    drawline (40,  30,  40,  370,  black)% draws line
    drawline (40,  30,  600,  30,  black)% draws line
    drawline (600,  30,  600,  370,  black)% draws line
    drawline (600,  370,  40,  370,  black)% draws line
    drawfill  (0,  10,  brightred,  black)%fills outside border brightred
end loop % ends the main loop 
 | 	  
 
 
 
 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Clayton
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Nov 30, 2007 6:53 pm    Post subject: RE:Paddle And Ball Collision Help  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				gergysun wrote: This is my THIRD topic about this subject ...  
 
 
Exactly. For this reason this topic will be locked. You're not just going to get the answer on a silver platter here. Tony has already given you more than  enough information to do this in your other thread.
 
 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |