Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Happybobjr on January 12, 2011, 06:12:30 pm

Title: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:12:30 pm
I know this is a dumb question but, how can i make a sprite move along a line?
I feel like the answer is obvious but i just can''t figure it out.
Title: Re: [Help plz] Sprite allong a line.
Post by: yunhua98 on January 12, 2011, 06:13:38 pm
YOU COULD DISPLAY IT AND THEN USE hORIZONTAL/vERTICAL, OR increment the x/y coordinate...  by a constant value

stupid caps lock...

Read it this way, lol:  you could display it and then use horizontal/vertical, or increment the x/y coordinate by a constant value.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:15:15 pm
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee on January 12, 2011, 06:17:51 pm
This might not be the most efficient method, but try this:

Code: [Select]
[Sprite data]->Pic1
Sprite X-coordinate ->X
Sprite Y-coordinate ->Y
Sprite X-momentum ->S
Sprite Y-momentum ->T

.Main loop
While 1
    Stuff
    More stuff
    ClrDraw
    X+S->X
    Y+T->Y
    Pt-On(X,Y,Pic1)
End

You could make it move in a sort of diagonal pattern if you set both the X and Y values to differing numbers, though it'll skip a little...
Title: Re: [Help plz] Sprite allong a line.
Post by: SirCmpwn on January 12, 2011, 06:22:03 pm
Do you mean a user-defined line?
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:24:57 pm
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.
Title: Re: [Help plz] Sprite allong a line.
Post by: AngelFish on January 12, 2011, 06:25:33 pm
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.

What are your needs?

Also, sorry about the downrating. I accidentally clicked it.

EDIT: Ninja'd.

You can just use a For( loop and increment the X and/or Y position.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:28:11 pm
If I understand what you are saying, I don't think that would be the appropriate way to solve my problem for my needs.

What are your needs?

Also, sorry about the downrating. I accidentally clicked it.

EDIT: Ninja'd.

You can just use a For( loop and increment the X and/or Y position.

Umm, it says it was rated up ???

a bullet that can pretty much go any direction that is determined by the tanks barrel (I think that's the right word.)
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee on January 12, 2011, 06:29:29 pm
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.

Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)
Title: Re: [Help plz] Sprite allong a line.
Post by: AngelFish on January 12, 2011, 06:32:59 pm
Well, you'd have to rotate the sprite, but that's simple.

Take this example code:
Code: [Select]
While 1
   Pt-On(X,Y,<pointer>
   Dispgraph
   Pt-change(X,Y,<pointer>
   If <collision detected>
      Goto <Collision handling>
   Else
      X+A->X
      Y+B->Y
   End
End

To change the direction, just change A and B.

PS: I accidentally downrated your post, so I uprated in response.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:34:20 pm
Crud, more complex stuff :/

Thank you.  I'll take a look
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.

Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)

Qwerty@  The problem is that i don't know what a and b are. I only know the start point and endpoint.
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee on January 12, 2011, 06:37:53 pm
Crud, more complex stuff :/

Thank you.  I'll take a look
Do you mean a user-defined line?
umm... i think.
I want it to be like axe's line algorithm except only draw one pixel at a time. and instead of it being a pixel, i want it to be a sprite.

Try modifying this:
http://ourl.ca/4129/138496 (http://ourl.ca/4129/138496)
/me shrugs
Yeah.  It's fairly easy to make things go in straight lines, or 45 degree angle lines, but getting things to move at other angles and slopes without skipping a bunch of pixels isn't something I've managed to figure out in Axe.
Title: Re: [Help plz] Sprite allong a line.
Post by: AngelFish on January 12, 2011, 06:38:41 pm

Qwerty@  The problem is that i don't know what a and b are. I only know the start point and endpoint.

You don't know what direction the tank is shooting in? Um, I'm not sure any line drawing algorithm is useful if you don't have the information to figure that out. It can be pretty easily derived from the start and endpoints though.
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee on January 12, 2011, 06:42:13 pm
It's easy to derive the slope, true, but if you have a steep vertical slope, your object will end up skipping a bunch of pixels, possibly throwing off collision detection and
making the speed look irregular.

If the tank isn't allowed to fire too high or too low, then you could probably just use an easier method and derive the slope of the line, increment the X value each loop, crunch the new Y value, then display the bullet.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:45:23 pm
So no one knows how to follow along Bresenham's line algorithm?
Edit: Qwerty will you rate that one back down? (to 0 not -1 :P)
Title: Re: [Help plz] Sprite allong a line.
Post by: AngelFish on January 12, 2011, 06:46:05 pm
Michael's code *is* Bresenham's Line algorithm.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 06:47:37 pm
I think i need to sleep now.  I am not processing this well.
Title: Re: [Help plz] Sprite allong a line.
Post by: nemo 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.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr 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)
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee 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?
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr 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
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee 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

Title: Re: [Help plz] Sprite allong a line.
Post by: Quigibo 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.
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 12, 2011, 08:08:11 pm
/me hugs Quigibo
I appreciate this so much.
I would have spent many frustrated hours trying to figure all this out
Title: Re: [Help plz] Sprite allong a line.
Post by: DJ Omnimaga 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.
Title: Re: [Help plz] Sprite allong a line.
Post by: SirCmpwn 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.
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee 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.
/me shrugs

@SirCmpwn and Quigbo: Those are awesome solutions!  I never would have thought of them.
Title: Re: [Help plz] Sprite allong a line.
Post by: DJ Omnimaga 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)
Title: Re: [Help plz] Sprite allong a line.
Post by: Michael_Lee 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.
Title: Re: [Help plz] Sprite allong a line.
Post by: DJ Omnimaga 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
Title: Re: [Help plz] Sprite allong a line.
Post by: Builderboy on January 13, 2011, 02:28:50 am
Yeah text can be finicky when dealing with only a single word x.x Well I really like quigibo's solution! Nice job! :D
Title: Re: [Help plz] Sprite allong a line.
Post by: Happybobjr on January 13, 2011, 09:07:03 am
It works perfectly.  I'm still trying to understand it, but i haven't gotten another look this morning after i have woken up. :)

I have learned that/me "...text"
or
smilies really help show how you are meant to interpret text.  I would have been banned long ago if i didn't put a :P near most of my jokes ;)