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

Username:   Password: 
 RegisterRegister   
 launching: determining angles
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asd




PostPosted: 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
Sponsor
sponsor
SNIPERDUDE




PostPosted: 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




PostPosted: 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 Embarassed
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: