Quickest way to get to a number
Author |
Message |
Atherial
|
Posted: Thu Jan 07, 2016 10:18 pm Post subject: Quickest way to get to a number |
|
|
Basically, my summative due date is coming up and im panicking.
My game has a sprite that spins a full 360 degrees.
I need my sprite to turn based on my WASD key presses
I could do the actual rotation of the sprite, however I need to figure out what the fastest way to get from one number to another is.
So basically, if I pressed D id want the angle of my sprite to become 0. So if the angle was 45, id want it to slowly subtract slowly until it reached 0, if it was -45, id want it to add until it reached 0.
This is my code so far, but I cant seem to think it out in my head
(angle 0 is my sprite facing right, 90 is up, 180 is left, -90 is down. My array is from -180 to 180 for each angle.)
Turing: | loop
Input.KeyDown(chars )
if chars ('d') and tankangle > 0 then
tankangle := tankangle - 0. 125
elsif chars ('d') and tankangle < 0 then
tankangle := tankangle + 0. 125
elsif chars ('w') and tankangle > 90 then
tankangle := tankangle - 0. 125
elsif chars ('w') and tankangle < 90 then
tankangle := tankangle + 0. 125
elsif chars ('s') and tankangle > 90 then
tankangle := tankangle + 0. 125
elsif chars ('s') and tankangle < 90 then
tankangle := tankangle - 0. 125
elsif chars ('a') and tankangle <= 0 and tankangle not= - 179 then
tankangle := tankangle - 0. 125
elsif chars ('a') and tankangle > 0 and tankangle not= 180 then
tankangle := tankangle + 0. 125 end if
if tankangle > 179 then tankangle := - 179 end if
Text.Locate(1, 1)
put tankangle
Text.Locate(2, 1)
put (round(tankangle ))
Sprite.ChangePic(tanksprite,tanks (round(tankangle )))
Sprite.SetPosition(tanksprite,userX,userY, false)
delay(1)
end loop
|
Does anyone have any pre made procedures to do this? Or any reccomendations to make sure Im doing this correctly?
Super urgent that I need a response.
Thanks so much for the help!
-Mackenzie |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Atherial
|
Posted: Mon Jan 11, 2016 10:48 am Post subject: Re: Quickest way to get to a number |
|
|
Solved with a ton of if statements. |
|
|
|
|
|
|
|