Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / DarkBASIC Discussion :: Ball Movement (Pong etc)

Author
Message
freestyler
21
Years of Service
User Offline
Joined: 16th Dec 2002
Location:
Posted: 17th Jan 2003 12:05
Hi all, I am a n00b at DarkBASIC and was wondering how complicated is setting up the ball movement like in the classic Pong?

I mean when the ball hits a wall or you (a bar at the bottom or something similar) how do you make the ball bounce off in the right direction.

ADVANCED - {not important :yet:}
Also how would you make the ball bounce in different directions eg, If the user controlled bar at the side/bottom collides with the ball while moving fast along the side/top how could you make the ball react differently to moving slower

(hmmm explained well? hmm

Thanks !
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 17th Jan 2003 14:06
OK either way I would use collision. For the paddles, i would say for instance if the ball is at the same coordinates as the paddle then send the ball in the opposide direction (by moving object) and repeat this process until the ball isnt in the general area of the paddle.

For your other method, you could find the angles of the area being hit, and for a certain angle, send it in a certain direction.

RPGamer

This may sound like chinese to you, but I tried Hopefully it helps

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Hatsu
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location:
Posted: 17th Jan 2003 16:46
As I programmed in other languages before DB I would use sin and cos as it is what I am used to. Just take the angle of the ball that you want it moving in and then cosine this for the vertical speed and sine the angle for the horizontal speed. For the bounce you would then either need to reflect the ball on the horizontal axis or the vertical axis depending if it hit a vertical wall or horizontal wall respectively.

Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 17th Jan 2003 19:22
To change the angle at which the ball comes off the racket you would use sine and cosine. First find the distance moved by the racket by subtracting the new pos from the old pos. Then use that as the 'angle' in your formula.



Yum! Yum! Yum! Yum!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 17th Jan 2003 19:42
here is a 5 sec triganometry tutorial if you havent a clue:

you can find all the features of a right angled triangle if you have either 1 angle and the lenght of 1 side, the lengths of 2 sides using cosine, sine and tangent.

[img]C:\WINDOWS\Desktop\triangle.jpg[/img]

use these formulas:

sin(a)=y/h
cos(a)=x/h
tan(a)=y/x

asin(y/h)=a
acos(x/h)=a
atan(y/x)=a

these commands can be used in db using the sin(),asin(),etc commands.

these are useful for finding the amount to move along the x and y axis in programming (also the z axis in db). If you inagine that the line 'h' is the distance you want to move and a is the angle you want to move at then you can find how far you want to move using cosine and sine (lines 'x' and 'y').

Hope I helped

Yum! Yum! Yum! Yum!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 17th Jan 2003 19:44
[img]C:\WINDOWS\Desktop\triangle.jpg[/img]

Yum! Yum! Yum! Yum!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 17th Jan 2003 19:47


Yum! Yum! Yum! Yum!

Login to post a reply

Server time is: 2024-11-23 21:33:24
Your offset time is: 2024-11-23 21:33:24