angle problem
Author |
Message |
shoobyman
![](http://compsci.ca/v3/uploads/user_avatars/1894631788463006b596f19.gif)
|
Posted: Fri Dec 08, 2006 10:13 am Post subject: angle problem |
|
|
code: | setscreen ("offscreenonly")
var angle : int := 1
var velx, vely := 0
var chars : array char of boolean
var pic : array 1 .. 359 of int
var shipx, shipy : int := 100
var linex1, liney1, linex2, liney2 : int
var x, y, button : int
linex1 := shipx + 23
linex2 := shipx + 23
liney1 := shipy + 38
liney2 := shipy + 28
for i : 1 .. 359
pic (i) := Pic.FileNew ("ship.bmp")
pic (i) := Pic.Rotate (pic (i), i, 23, 33)
drawfillbox (10, 200, (i + 10), 250, 12)
locate (12, 48)
put "Complete"
View.Update
locate (14, 18)
put "GENERATING PICTURES"
end for
loop
Input.KeyDown (chars)
mousewhere (x, y, button)
View.Update
delay (30)
cls
Pic.Draw (pic (angle), shipx, shipy, picCopy)
drawline (linex1, liney1, linex2, liney2, 7)
if x = 0 then
x := 1
end if
if y = 0 then
y := 1
end if
shipx += velx
shipy += vely
angle := arctan (y div x) div 1
if chars (KEY_UP_ARROW) then
velx := (linex1 - linex2) div 5
vely := (liney1 - liney2) div 5
end if
if button = 1 then
velx := (x - shipx) div 20
vely := (y - shipy) div 20
end if
if angle >= 360 then
angle := 1
end if
if angle < 1 then
angle := 358
end if
locate (1, 1)
put "Angle: ", angle
locate (2, 1)
put "x: ", x, " y: ", y
end loop
|
If you click, the ship moves properly, but can anyone help me with the formula for the way the ship is facing?
I want it to face the mouse, but I have tried a lot of different ways and i don't know how to do it. Anyone know the formula?
ps. Code is messy, but don't worry about that
Description: |
|
Filesize: |
9.33 KB |
Viewed: |
813 Time(s) |
![ship.bmp ship.bmp](uploads/attachments/ship.bmp)
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
zylum
![](http://compsci.ca/v3/uploads/user_avatars/1689129126468091c334ee0.gif)
|
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Mon Dec 11, 2006 2:44 pm Post subject: (No subject) |
|
|
I assume you mean something like this :
code: | View.Set ("offscreenonly")
var x1, y1, x2, y2, angle : real := 0
var x, y, button : int
loop
Mouse.Where (x, y, button)
if button not= 0 then
x1 += sign (x - x1)
end if
angle := arctand ((y - y1) / (x - x1 + 1e-6))
if angle < 0 then
angle += 180
end if
x2 := x1 + cosd (angle) * 40
y2 := y1 + sind (angle) * 40
Draw.Line (round (x1), round (y1), round (x2), round (y2), 7)
View.Update
delay (5)
cls
end loop |
Get the angle and then use sine and cosine. In your case, you already have the rotated images, so you don't even have to use sine and cosine! Just draw the image that's at that angle.
|
|
|
|
|
![](images/spacer.gif) |
|
|