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

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




PostPosted: Thu Jan 13, 2011 2:10 pm   Post subject: Colision problem

What is it you are trying to achieve?
What i want to happen is make my ball bounce of of a paddle.

What is the problem you are having?
What's going wrong is.. my ball will sometimes go through the paddle and will shake, go down and then go back up and shoot off. sometimes it will deflect even if the paddle isn't there.


Describe what you have tried to solve this problem
i've look through my code, and tried changing it a litte.. (Mainly i just changed the checking part of the code)


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:

    loop

        Draw.FillOval (ballx, bally, 7, 7, yellow)      %This draws the first ball
        delay (5)
        Draw.FillOval (ballx, bally, 7, 7, black)       %This draws the second ball behind it to make it look like a solid ball
        ballx := ballx + changex * dirx             %The directions for the ball.
        bally := bally + changey * diry
            if (ballx > maxx - 10) or (ballx <= 10) then        %If the ball touchs this spot very left of very right, it deflects
                dirx := dirx * -1
            end if
            if (bally >= maxy - 311) or (bally <= 240) then     %This sets the ceiling boundaries
                diry := diry * -1
            end if
            if    (bally >= lpaddley) and (bally <= lpady ) and (ballx <= left_paddle) then     %This is where the ball deflects off the left paddle
                dirx := dirx * -1
            elsif (bally >= rpaddley) and (bally <= rpady ) and (ballx >= right_paddle) then    %This makes the ball deflect off the right paddle
                dirx := dirx * -1
            end if
 
    end loop


Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jan 13, 2011 2:17 pm   Post subject: RE:Colision problem

Pick one of the paddles (lets say left) and try to describe in words _all_ of the locations where a ball could be, for it to be deflected. That should point you towards some cases where problems could occur.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: