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

0 Members and 1 Guest are viewing this topic.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
[Help plz] Sprite allong a line.
« 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.
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 yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #1 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.
« Last Edit: January 13, 2011, 04:27:00 pm by yunhua98 »

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

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 #2 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.
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 #3 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...
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.

SirCmpwn

  • Guest
Re: [Help plz] Sprite allong a line.
« Reply #4 on: January 12, 2011, 06:22:03 pm »
Do you mean a user-defined line?

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 #5 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.
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 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 #6 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.
« Last Edit: January 12, 2011, 06:26:39 pm by Qwerty.55 »
∂²Ψ    -(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 #7 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.)
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 #8 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
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 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 #9 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.
« Last Edit: January 12, 2011, 06:34:14 pm by Qwerty.55 »
∂²Ψ    -(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 #10 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

Qwerty@  The problem is that i don't know what a and b are. I only know the start point and endpoint.
« Last Edit: January 12, 2011, 06:35:20 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 #11 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
* Michael_Lee 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.
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 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 #12 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.
« Last Edit: January 12, 2011, 06:40:09 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #13 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.
« Last Edit: January 12, 2011, 06:42:24 pm 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 Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: [Help plz] Sprite allong a line.
« Reply #14 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)
« Last Edit: January 12, 2011, 06:46:29 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
____________________________________________________________