[HELP] Having a picture turn
Author |
Message |
Canned
|
Posted: Mon Sep 15, 2008 8:40 pm Post subject: [HELP] Having a picture turn |
|
|
Trying to make a game in my spare time, as I passed grade 10 computer sciences with flying colours, and I still love coding.
Anyways, back on topic. How would I make a picture turn to follow the mouse? Like, if the mouse is north of the picture, it faces north, if the mouse is south, it faces south ect.
Heres the code:
Turing: | View.Set ("graphics:500;450,nobuttonbar,title: Work In Progress")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Variables and Constants %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var cirX, cirY, recX1, recX2, recY1, recY2 : int
var chars : array char of boolean
cirX := 50
cirY := 50
recX1 := 50
recY1 := 50
recX2 := 55
recY2 := 75
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Test Picture %
%%%%%%%%%%%%%%%%%%%%%%%%%%
Draw.FillOval (cirX, cirY, 10, 10, 42)
Draw.FillBox (recX1, recY1, recX2, recY2, 24) |
I know it'll have to do it with some trig, but I dont know how. Help = appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
The_Bean
|
Posted: Mon Sep 15, 2008 9:27 pm Post subject: Re: [HELP] Having a picture turn |
|
|
Is it a turing generated image using Draw. commands, or are you importing an actual image?
Also do you want it to face only up, down, left, right, or do u want it to face your mouse for all 360 degrees.
If you are importing a picture or making something complex, you will want to look into Pic.Rotate.
He is an example of finding the angle, and drawing something at it.
Turing: |
View.Set ("graphics:500;500,nobuttonbar,offscreenonly")
var xm, ym, bm : int
var charX, charY : int := 250
var gunX, gunY : int
var degree : real
function setAngle (x, y : real) : real
if x = 0 and y = 0 then
result 0
elsif x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif y = 0 and x > 0 then
result 0
elsif y = 0 and x < 0 then
result 180
elsif x > 0 and y > 0 then
result arctand (y / x )
elsif x < 0 and y > 0 then
result 180 + arctand (y / x )
elsif x > 0 and y < 0 then
result 360 + arctand (y / x )
elsif x < 0 and y < 0 then
result 180 + arctand (y / x )
else
result 0
end if
end setAngle
loop
cls
Mouse.Where (xm, ym, bm )
degree := setAngle (xm - charX, ym - charY )
gunX := round (cosd (degree ) * 25) + charX
gunY := round (sind (degree ) * 25) + charY
Draw.FillOval (charX, charY, 10, 10, 42)
Draw.ThickLine (charX, charY, gunX, gunY, 5, 24)
View.Update
delay (10)
exit when hasch
end loop
|
|
|
|
|
|
|
Canned
|
Posted: Tue Sep 16, 2008 7:15 am Post subject: RE:[HELP] Having a picture turn |
|
|
Heh thanks man, +bits |
|
|
|
|
|
|
|