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

Username:   Password: 
 RegisterRegister   
 pong help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
LindenRulz




PostPosted: Fri Feb 23, 2007 9:07 pm   Post subject: pong help

I need help to detect if it hits the paddle or not and reflect if it does and quit if it doesn't. This is my code.

code:

var ballx, bally, rise, run, rad, u, yy, xx : int
ballx := maxx div 2
bally := maxy div 2
rad := 10
rise := 1
run := 3
View.Set ("offscreenonly")
loop
    var x, y, button : int
    Mouse.Where (x, y, button)
    Draw.FillOval (ballx, bally, rad, rad, blue)
    ballx := ballx + run
    bally := bally + rise
    if ballx > maxx or ballx < 0 then
        run := run * -1
    end if
    if bally > maxy or bally < 0 then
        rise := rise * -1
    end if
    View.Update
    delay (10)
    cls
    drawfillbox (x - 50, 0, x + 50, 10, red)
if bally = 10 and ballx < x - 51 and ballx > x + 51 then
exit
end if
    end loop
[/code]
Sponsor
Sponsor
Sponsor
sponsor
rollerdude




PostPosted: Sat Feb 24, 2007 5:56 pm   Post subject: Re: pong help

well, i haven't run it yet, but by looking at it, i see this line

ballx < x - 51 and ballx > x + 51

if x=0 then ballx would have to be >51 and <-51

other than that, i seems allright

maybe you meant

ballx > x - 51 and ballx < x + 51

??

hope i could help
CodeMonkey2000




PostPosted: Sat Feb 24, 2007 8:12 pm   Post subject: RE:pong help

You need to figure out the shortest distance between the mid-point of the ball and the top line of your paddle. If the distance is equal to or less than the radius of the ball then it has collided with your paddle and must now change direction, or else keep going.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: