launching: determining angles
Author |
Message |
asd
|
Posted: Thu Aug 30, 2007 11:42 pm Post subject: launching: determining angles |
|
|
i'm making a game to kill time cause i'm grounded. I want to launch a ball using the mouse, but i dont know how to determine the angle in which the ball will be thrown.
any help is appreciated.
here's what i got so far:
%Launching Program
View.Set ("offscreenonly")
setscreen ("nobuttonbar")
var x, y, button, x2, y2, power : int := 0
var dist, speed : real := 0
var lineX, lineY, lineX2, lineY2 : int
loop
View.Update
delay (50)
cls
drawline (0, 50, 650, 50, black)
mousewhere (x, y, button)
locate (1, 1)
if button = 0 then
power := 0
put x : 4, " ", y : 4, " ", "Power: ", power : 4, " button up"
drawfilloval (x, y, 5, 5, blue)
x2 := x
y2 := y
else
drawoval (x2, y2, 50, 50, black)
lineX := x2 - 50
lineY := y2
lineX2 := x2 + 50
lineY2 := y2
drawline (lineX, lineY, lineX2, lineY2, black)
dist := sqrt ((x2 - x) ** 2 + (y2 - y) ** 2)
if dist >= 50 - 5 then
drawfilloval (x, y, 5, 5, blue)
power := 50
elsif dist <= 50 - 5 then
drawfilloval (x, y, 5, 5, blue)
power := ceil (dist)
end if
put x : 4, " ", y : 4, " ", "Power: ", power : 4, " button down"
end if
end loop |
|
|
|
|
|
Sponsor Sponsor
|
|
|
SNIPERDUDE
|
Posted: Fri Aug 31, 2007 4:07 pm Post subject: Re: launching: determining angles |
|
|
use trigonomics. there are plenty of examples on this site that provide as examples.
http://compsci.ca/v3/viewtopic.php?t=14083
^ Here ^ is an example. Please search before you post a question.
If you couldn't find an example, that's fine in this example, I had to spend a few mins trying to find this one.
This should tell you everything you need to know. |
|
|
|
|
|
asd
|
Posted: Fri Aug 31, 2007 9:55 pm Post subject: Re: launching: determining angles |
|
|
thanks man. i spent an hour searching through the forums yesterday, but couldn't find anything |
|
|
|
|
|
|
|