Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 pls help me wit my program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Wed Jan 11, 2006 9:08 am   Post subject: pls help me wit my program

ok this is my program, i need help to make the ball bounce off of the paddle :

var x, y, button : int
var paddleHEIGHT: int:=5
var objectVX, objectVY, x2, y2 : int
objectVY := 10
objectVX := 10
x2 := maxx div 2
y2 := maxy div 2
const ballRad : int := 5
setscreen ("offscreenonly")
loop
delay (30)
cls
mousewhere (x, y, button)

drawfillbox (x,13,x+60,paddleHEIGHT,black)

drawfilloval (x2, y2, ballRad, ballRad, black)
x2 += objectVX
y2 += objectVY
if x2 > maxx - 5 then
objectVX := -objectVX
elsif x2 < 5 then
objectVX := -objectVX
elsif y2 > maxy - 5 then
objectVY := -objectVY
elsif y2 < 5 then
objectVY := -objectVY
end if
View.Update
end loop
Sponsor
Sponsor
Sponsor
sponsor
codemage




PostPosted: Wed Jan 11, 2006 10:35 am   Post subject: (No subject)

Do a search for pong. There have been many, many posts about this already - where you can find your answer.
do_pete




PostPosted: Wed Jan 11, 2006 10:38 am   Post subject: (No subject)

Whenever the ball hits a paddle go
code:
Ball_X_Speed *= -1
pavol




PostPosted: Wed Jan 11, 2006 10:50 am   Post subject: (No subject)

use an if statement to check where the ball is. ex:
code:
if x2 > x and x2 < x + 60 and y2 <  13 then
    y2 := -y2
end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: