Author Topic: Sprite Direction  (Read 8523 times)

0 Members and 1 Guest are viewing this topic.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Sprite Direction
« on: June 16, 2010, 04:31:49 pm »
Suppose i have a sprite moving across the screen from left to right, and i want to press a button and it will make a large sweeping arc and change its direction 180°.
this would be its trajectory:
Start:
---->---
            \
             )
            /
---<----
^End

now i'm wondering how i could implement this in axe. keep in mind i want this to be free of any sort of gravity, so the sprite is moving at a constant velocity and all i want to do is change its direction.


Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: Sprite Direction
« Reply #1 on: June 16, 2010, 04:35:38 pm »
Could be done by using sin/cos to generate the coordinates.
Its called goniometrics (w00t) i learned something at math.

I know how to do this but not in the mood to boot up my comp atm.

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Sprite Direction
« Reply #2 on: June 16, 2010, 04:37:04 pm »
yeah, it's summer. all the math i learned last year (which included sin cos tan  :-\) has been forgotten


Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: Sprite Direction
« Reply #3 on: June 16, 2010, 04:40:06 pm »
If no one has created something by tomorrow, il create you some commented code...

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite Direction
« Reply #4 on: June 16, 2010, 04:41:53 pm »
If I knew more about the cos( and sin( functions in Axe I would help. Unfortunately I haven't much. Maybe later.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: Sprite Direction
« Reply #5 on: June 16, 2010, 04:46:40 pm »
Btw, quigibo (dunno if I spelled that right)
Which mode of angles is axe using? Degrees or Radials?

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Sprite Direction
« Reply #6 on: June 16, 2010, 04:50:03 pm »
You spelled it right.
Since Axe doesn't support floating point numbers, it uses neither Degrees nor Radians. Rather, the input, in range 0-255, corresponds to 0-2*pi radians and the output, in range -128 to 127, corresponds to -1-1.
Edit: 300th post!
« Last Edit: June 16, 2010, 04:50:31 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: Sprite Direction
« Reply #7 on: June 16, 2010, 04:55:01 pm »
You spelled it right.
Since Axe doesn't support floating point numbers, it uses neither Degrees nor Radians. Rather, the input, in range 0-255, corresponds to 0-2*pi radians and the output, in range -128 to 127, corresponds to -1-1.
Edit: 300th post!
Gz,
Anyway, that's too bad, how are we supposed to make circles or something round then?

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Sprite Direction
« Reply #8 on: June 16, 2010, 04:58:18 pm »
idea: have an x and y velocity, and make sure they ALWAYS add up to 100. then when the user presses a key, you change one of the velocities, thus changing the other. so 50/50 would make the sprite move at a 45 degree angle, while 25 Y velocity with 75 X velocity would make the sprite move at a 22.5 degree angle. i'm not sure if the sprite would move at a constant speed though... you'd have to do some division tricks as well, so you can get good precision.


Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Sprite Direction
« Reply #9 on: June 16, 2010, 05:01:27 pm »
That's off-topic, but I'll write you a quick one (should work)
Code: [Select]
.CIRCLE
For(X,0,255
Pxl-On(cos(X)//4+48,sin(X)//4+32
End
Okay, it's not perfect (some points are off-screen), but it should draw a circle
Edit: Did I really type Pt-On( ... fixed
« Last Edit: June 16, 2010, 06:42:41 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite Direction
« Reply #10 on: June 16, 2010, 05:25:56 pm »
Ya, that routine works for the most part (you do need to change Pt-On( to Pxl-On( and put a DispGraph at the end). Only thing is that the circle produced is sort of square-ish.

Edit:
Here is a screenshot of what I mean.

Edit 2:
Here is one with a sprite.

Also, glad you got use from it, nemo.
« Last Edit: June 16, 2010, 05:46:57 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Sprite Direction
« Reply #11 on: June 16, 2010, 05:44:20 pm »
thanks calcdude! it's been modified for my purposes but i doubt i would've come up with that code on my own.
EDIT: the inside of your sprite gif looks like a perfect circle, though.
« Last Edit: June 16, 2010, 05:55:38 pm by nemo »


Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Sprite Direction
« Reply #12 on: June 16, 2010, 09:25:24 pm »
Nice circle!  Great job calcdude and meishe! ;D

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite Direction
« Reply #13 on: June 16, 2010, 11:17:50 pm »
thanks calcdude! it's been modified for my purposes but i doubt i would've come up with that code on my own.
EDIT: the inside of your sprite gif looks like a perfect circle, though.

That's due to the properties of how sprites are displayed I believe. If it displayed sprites from the center instead of the top-left corner you would get a skewed inner-circle (I believe).
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Sprite Direction
« Reply #14 on: June 16, 2010, 11:28:37 pm »
Wow, despite not looking 100% perfect (the later screenshot) it sure draws circles friggin fast!

Sadly I can't help much though because we did not do a lot of trig at school (it was only people who had advanced maths classes) and most was forgotten since my last math class was 7 years ago
« Last Edit: June 16, 2010, 11:32:36 pm by DJ Omnimaga »