Main Menu

Spanned jump

Started by Adaz, October 07, 2008, 08:14:44 AM

Previous topic - Next topic

Adaz

Hi,

How can I move a sprite spanned between two points? I'm not good in maths, so can anybody help mi with an algorythm?
See the picture what I mean.

Thank you!

Ádáz

Hungary

kevin


plot a line, and add the Y axis of the sine wave to it.

thaaks

What is fixed? The two points or gravity, direction and acceleration?

The curve looks like a Bezier curve. But that needs three points. With fixed points you'll need a third one to describe the spanning or bow of the curve (quadratic bezier curve, see here.

If you use something like gravity, direction and acceleration you should look at the PB 2D Platformer example.

Could you explain a bit more?

Cheers,
Tommy

kevin




jumpHeight=100

; start point
   x1=100
   y1=400

; end point   
   x2=500
   y2=200



do
cls 0

; distance from start to end point
dist#=getdistance2d(x1,y1,x2,y2)
nx#=(x2-x1)/dist#
ny#=(y2-y1)/dist#


angle#=0
AngleStep#=180/Dist#

for ThisPoint=0 to dist#
x#=x1+(nx#*ThisPoint)
y#=y1+(ny#*ThisPoint)
; pixel along path
dot x#,y#

yoffset=sin(ThisPoint*AngleStep#)*jumpHeight

; jump curve
dot x#,y#-Yoffset
next

circle x1,y1,5,false
circle x2,y2,5,false

Sync

waitkey
waitnokey

; start point
   x1=rnd(800)
   y1=rnd(600)

; end point   
   x2=rnd(800)
   y2=rnd(600)

loop


Adaz

Thank both of you very much, kevin's code is what I've been looking for!

Ádáz

Hungary

thaaks

And I wonder what books Kevin reads to know that you just need to "add the Y axis of the sine wave to it"  ::)

Makes me feel dumb so often  :-[

That's one of the most complicated things for me: to figure out how to achieve certain effects, behavior or algorithms for game play issues.

Someone needs to create a list for the most common game coders' problems and their solutions...I could start with the problems  ;D

Before I forget: Thanks, Kevin! Learned something new today!Error Missing Closing Square Bracket

Adaz

Me too!

And just 1 thing: I use this code to move a sprite on this spanned path, but if the distance is small, it moves very quickly, and if it's big, it's a snail. So how can I modify this code if I want the sprite to step always the same number of steps (for example always 20)? So if the distance is bigger, then the steps are far from each other, and if smaller, then the steps are close.
Thank you!

Ádáz

Hungary

thaaks

#7
Oh, that's easy - even I can help you here  ;D

You just need to divide the distance #dist by your preferred step size (say 20). I called the result xstep# which is the x increment for each step.
And then run the for-next loop with your step size xstep#.


jumpHeight=100

nrOfSteps = 20

; start point
   x1=100
   y1=400

; end point   
   x2=500
   y2=200



do
cls 0

; distance from start to end point
dist#=getdistance2d(x1,y1,x2,y2)
nx#=(x2-x1)/dist#
ny#=(y2-y1)/dist#


angle#=0
AngleStep#=180/Dist#

xstep# = dist# / nrOfSteps

for ThisPoint=0 to dist# step xstep#
x#=x1+(nx#*ThisPoint)
y#=y1+(ny#*ThisPoint)
; pixel along path
dot x#,y#

yoffset=sin(ThisPoint*AngleStep#)*jumpHeight

; jump curve
dot x#,y#-Yoffset
next

circle x1,y1,5,false
circle x2,y2,5,false

Sync

waitkey
waitnokey

; start point
   x1=rnd(800)
   y1=rnd(600)

; end point   
   x2=rnd(800)
   y2=rnd(600)

loop


Cheers,
Tommy

kevin

  Sinus is a lot of fun, you can make lots of cool/bizarre patterns from often really simple routines.   This one is just something I came up with for a projectile routine about 20 years ago.. Oh how time flies :)  - More recent example would be Altus's   Beat em up game,  which will give the same style of movement path.


Adaz

Quote from: thaaks on October 07, 2008, 01:33:00 PM
Oh, that's easy - even I can help you here  ;D
Works like a charm, thank you once more :)

Ádáz

Hungary

Adaz

Quote from: kevin on October 07, 2008, 07:24:12 PM
  Sinus is a lot of fun, you can make lots of cool/bizarre patterns from often really simple routines.   This one is just something I came up with for a projectile routine about 20 years ago.. Oh how time flies :)  - More recent example would be Altus's   Beat em up game,  which will give the same style of movement path.
20 years ago I was able to write a little maze game only, but calculating with sine was always an extraterrestrial alien thing for me :-) Now I begin to understand it... Thank you!

Ádáz

Hungary

kevin

   In 1988 I was finishing high school, tinkering with the Amiga and drumming an awful lot..   Not too much has changed.. :)


ATLUS

 :o nice code for sport-isometrical games!!!
Thanks all for code ;)

Adaz

Quote from: kevin on October 08, 2008, 06:02:14 AM
   In 1988 I was finishing high school, tinkering with the Amiga and drumming an awful lot..   Not too much has changed.. :)
In that year I was learning programming from my father on a Sinclair QL's, that machine was the future of computing in 1985 with its SuperBasic, multitasking and window handling, etc. Finally in 1990 I obtained an Amiga at last :)  And later started to learn Amos :) Playbasic always reminds me to that. I know it's not an unintended similarity:)

Ádáz

Hungary

kevin

QuoteIn that year I was learning programming from my father on a Sinclair QL's, that machine was the future of computing in 1985 with its SuperBasic, multitasking and window handling, etc.

   Don't recall seeing a Sinclair QL but   Amiga 1000 was released around the same time :)

QuoteAnd later started to learn Amos  Playbasic always reminds me to that. I know it's not an unintended similarity:)

    To be honest, I wasn't too keen on Amos.  Wrote a bunch of tools in them though (most Amos Pro), prior to the that I wrote virtually everything in assembly (since 1982).   Any similarities to Amos come from surveying the RTG forums user base during PB design time (a DB community,).