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

Username:   Password: 
 RegisterRegister   
 Angle Bounces and Redirections!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 3:35 pm   Post subject: Angle Bounces and Redirections!!!

I am making a pong game and am having trouble making the ball bounce off the board according to the angle that it approaches it in.

|
| o
|
|
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Tue Nov 30, 2004 3:41 pm   Post subject: (No subject)

so you have your xVelocity and yVelocuty... if it bounces off a vertical side ie | then mustiply the xVelocity by -1, otherwise if it hits a horizontal wall, multiply the yVelocity by -1
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 3:45 pm   Post subject: (No subject)

Would you be able to send me an example, because im not getting this....
zylum




PostPosted: Tue Nov 30, 2004 3:54 pm   Post subject: (No subject)

code:
setscreen ("offscreenonly")

var x, y, vx, vy : int
x := maxx div 2
y := maxy div 2
vx := 1
vy := 1
loop
    x += vx
    y += vy
    if x < 0 or x > maxx then
        vx := vx * -1
    end if
    if y < 0 or y > maxy then
        vy := vy * -1
    end if
    drawfilloval (x, y, 10, 10, 7)
    View.Update
    delay (10)
    cls
end loop
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 4:00 pm   Post subject: (No subject)

That's awesome, thanks man!
Mazer




PostPosted: Tue Nov 30, 2004 4:02 pm   Post subject: (No subject)

Yes, the only time you would need to worry about a change in the direction of the ball is if you are taking into consideration the velocity of the paddle when they collide. (as well as forces of friction)
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 4:08 pm   Post subject: (No subject)

Yeah, but im not gonna worry about that yet. However, when I delete the "offscreenonly" for the setscreen, my circle flickers, and I'm just curious as to know what the offscreenonly does and if there are any limitations with it?
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 4:24 pm   Post subject: (No subject)

I am experiencing another problem. When my two boards move, i HAVE TO put a delay, but by adding this delay, I am slowing down the speed of the ball. Any way around this!!??
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Tue Nov 30, 2004 4:52 pm   Post subject: (No subject)

lower the delay or increase the velocities
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 5:01 pm   Post subject: (No subject)

I have tried that. See the problem is that in my main loop there is no delay. But when I run my procedure, there is a 40 second delay. So while I am not pressing any buttons the ball travels fast. But when I press a button to run my procedure, it gets affected by the 40 second delay and is slowed down so it does not maintain the same speed. Any suggestions....?
Cervantes




PostPosted: Tue Nov 30, 2004 5:57 pm   Post subject: 40?!

40 seconds, or 40 milliseconds?
Anyways, why do you have a delay in your procedure but not in your main loop? What is the purpose of the delay in the procedure? When you say "your two boards move", what are you referring to? Paddles?
Posting code would help us to help you. Wink
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 10:04 pm   Post subject: (No subject)

I have figured it out!!! What I did was I put that x := x + 10 for when it was moving and put a 40 millisecond delay to make it seem more smoother. Now i just did x := x + 1 with no delay. :S, really dumb, I know!
xHoly-Divinity




PostPosted: Tue Nov 30, 2004 10:08 pm   Post subject: (No subject)

OK!!! Now that I have finished my 'Pong' I really need some help with the velocity and stuff. E.g. If your paddle approaches the ball really fast, then the angle will be greater and the speed (sort of like a spin) because mine will always bounce the same angle and speed regardless of where and how on the paddle it is hit.
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  [ 13 Posts ]
Jump to:   


Style:  
Search: