Author Topic: [Help plz] Sprite allong a line.  (Read 10370 times)

0 Members and 2 Guests are viewing this topic.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #15 on: January 12, 2011, 06:46:05 pm »
Michael's code *is* Bresenham's Line algorithm.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #16 on: January 12, 2011, 06:47:37 pm »
I think i need to sleep now.  I am not processing this well.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #17 on: January 12, 2011, 06:47:40 pm »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.


Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #18 on: January 12, 2011, 06:49:24 pm »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

I haven't been in calculus yet.
*yaa summer school ;)  (getting ahead, not catching up)
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #19 on: January 12, 2011, 06:51:23 pm »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

Wouldn't that get you a fraction?
Or does it round well?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #20 on: January 12, 2011, 06:57:48 pm »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe
« Last Edit: January 12, 2011, 06:58:07 pm by happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #21 on: January 12, 2011, 07:07:09 pm »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe

*Facepalm

My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #22 on: January 12, 2011, 07:13:13 pm »
You shouldn't need any complex line algorithm.  Try this, it should animate the sprite "Pic1" moving from (X,Y) to (A,B) in S steps.

Code: [Select]
:A-X*256//S->C
:B-Y*256//S->D
:For(L,0,S)
:ClrDraw
:Pt-On(C*L//256+X,D*L//256+Y,Pic1)
:DispGraph
:Pause 50
:End

EDIT: Fixed, I forgot the divisions had to be signed.
« Last Edit: January 12, 2011, 07:28:17 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #23 on: January 12, 2011, 08:08:11 pm »
* happybobjr hugs Quigibo
I appreciate this so much.
I would have spent many frustrated hours trying to figure all this out
« Last Edit: January 12, 2011, 08:08:21 pm by happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

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: [Help plz] Sprite allong a line.
« Reply #24 on: January 13, 2011, 12:33:19 am »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe

*Facepalm


No, not on Omnimaga.
« Last Edit: January 13, 2011, 12:33:34 am by DJ Omnimaga »

SirCmpwn

  • Guest
Re: [Help plz] Sprite allong a line.
« Reply #25 on: January 13, 2011, 12:51:39 am »
Here's an easy solution:
Draw the line on the backbuffer.  Then, use a loop with pixel testing on the back buffer to determine where to draw the sprite next.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #26 on: January 13, 2011, 01:49:39 am »
or if you know the angle the tank is shooting at, use sin(angle) as your y increment and cos(angle) as your x increment.

Wouldn't that get you a fraction?
Or does it round well?
sin and cos return -127 through 128 (or something like that)
Edit: *In axe

*Facepalm


No, not on Omnimaga.
I am not allowed to express disgust at my own stupidity on Omnimaga?  Oh.
* Michael_Lee shrugs

@SirCmpwn and Quigbo: Those are awesome solutions!  I never would have thought of them.
« Last Edit: January 13, 2011, 01:52:05 am by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

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: [Help plz] Sprite allong a line.
« Reply #27 on: January 13, 2011, 02:01:32 am »
Oh, it was because it was pretty hard to detect if the facepalm was directed at yourself or happybobjr. In the first case it might be fine, although in your case it was not clear because Facepalm is all that your post contained, so it's subject to misinterpretation from other people, who might think it's directed at Happybobjr (and see it as out of line)
« Last Edit: January 13, 2011, 02:03:35 am by DJ Omnimaga »

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #28 on: January 13, 2011, 02:11:33 am »
Oh, it was because it was pretty hard to detect if the facepalm was directed at yourself or happybobjr. In the first case it might be fine, although in your case it was not clear because Facepalm is all that your post contained, so it's subject to misinterpretation from other people, who might think it's directed at Happybobjr (and see it as out of line)
Huh.  I didn't even know that you could direct facepalm at others.  Well, lesson learned -- one-liners are subject to misinterpretation.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

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: [Help plz] Sprite allong a line.
« Reply #29 on: January 13, 2011, 02:17:02 am »
Yeah it's possible. If someone asks a question to gain help and you reply "*facepalm*", it generally implies you find the person stupid. Someone here did that once, although the thing is that someone might use Facepalm towards someone but not necessarily mean to be offensive. Since it can be, however, this is why I personally avoid using it or append something after it implying it was directed at me. Text can be confusing when it comes to transmitting emotions sometimes. X.x