Page 1 of 1

pointer-trail similar as Gradius ship

Posted: Sat Oct 21, 2017 11:26 am
by Psychophanta
Hi programmers.
I have made an approach to a pointer-trail composed by lines, or sprites, as a snake, or as the way the gradius konami's game for its "option" selection.
Well, much better than my explanations, just see the behaviour of my approach to understand it:

Code: Select all

Structure Vector3D
  x.f:y.f:z.f:m.f
  color.l
EndStructure
Global puntero.Vector3D,punterodelta.Vector3D,SCREENWIDTH.u=GetSystemMetrics_(#SM_CXSCREEN),SCREENHEIGHT.u=GetSystemMetrics_(#SM_CYSCREEN),bitplanes.a=32,puntero\x=SCREENWIDTH/2,puntero\y=SCREENHEIGHT/2
Global wind.Vector3D:wind\x=0:wind\y=0
InitMouse():InitSprite():InitKeyboard()
OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes,title$)

Global NewList estela_puntero.Vector3D()
#maxlenstela=10
#colorestelapuntero=$0FABE5
#lenestela=7
MouseLocate(puntero\x,puntero\y)
For a.u=1 To #maxlenstela
  AddElement(estela_puntero()):estela_puntero()\color=#colorestelapuntero
Next
Repeat
  ClearScreen(RGB(5,8,9)):ExamineKeyboard():ExamineMouse()
  punterodelta\x=MouseDeltaX():punterodelta\y=MouseDeltaY()
  puntero\x=MouseX():puntero\y=MouseY()
  If FirstElement(estela_puntero()); And (punterodelta\x Or punterodelta\y)
    estela_puntero()\x=#lenestela*(-punterodelta\x+wind\x):estela_puntero()\y=#lenestela*(-punterodelta\y+wind\y)
    If LastElement(estela_puntero())
      *p.Vector3D=@estela_puntero()
      While PreviousElement(estela_puntero())
        CopyMemory(@estela_puntero(),*p,SizeOf(Vector3D))
        *p=@estela_puntero()
      Wend
    EndIf
  EndIf
  StartDrawing(ScreenOutput())
  prev.Vector3D\x=puntero\x:prev.Vector3D\y=puntero\y
  ForEach estela_puntero()
    Circle(prev\x+estela_puntero()\x,prev\y+estela_puntero()\y,8,estela_puntero()\color)
    Line(prev\x,prev\y,estela_puntero()\x,estela_puntero()\y,estela_puntero()\color)
    prev\x+estela_puntero()\x:prev\y+estela_puntero()\y
  Next
  Circle(puntero\x,puntero\y,14,$C01177)
  StopDrawing()
  FlipBuffers():Delay(15)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
But it is very far of the thing i want, because this approach does not move the sprites in a smooth way. Any idea to perform it slower and smoothly, and some ideas to versatilize the behaviour of the "snake" movements.

Thanks in advance! :)

Re: pointer-trail similar as Gradius ship

Posted: Tue Oct 24, 2017 10:38 am
by #NULL
interesting :)

Code: Select all

  ;;;punterodelta\x=MouseDeltaX():punterodelta\y=MouseDeltaY()
  
  ; sum up add smaller fractions of mouse delta
  punterodelta\x = punterodelta\x + 0.08 * MouseDeltaX()
  punterodelta\y = punterodelta\y + 0.08 * MouseDeltaY()
  ; reduce over time
  punterodelta\x = punterodelta\x * 0.8
  punterodelta\y = punterodelta\y * 0.8
this gives some smoothness but the tail still grows 'backwards'.

Re: pointer-trail similar as Gradius ship

Posted: Tue Oct 24, 2017 2:02 pm
by IceSoft
Better you using a 2D pyhsics engine.
Look this one (SWF snake game called Python):
http://www.gameslist.com/Python

Re: pointer-trail similar as Gradius ship

Posted: Tue Oct 24, 2017 8:20 pm
by Lunasole
Really cool experiment ^^ I'd like to play with your code somehow later
Psychophanta wrote: But it is very far of the thing i want, because this approach does not move the sprites in a smooth way. Any idea to perform it slower and smoothly, and some ideas to versatilize the behaviour of the "snake" movements.
Maybe simple lerp over coordinates will be enough to make stuff smooth:
(probably also need to do drawing asynchronous/separated from input handling)

Code: Select all

; linearly interpolate A to B by T
Procedure.f lerp (A.f, B.f, T.f) 
	ProcedureReturn a + t * (b - a)
EndProcedure

Define.f A = 50.0

A = lerp(A, 80, 0.5)
Debug A
A = lerp(A, 80, 0.5)
Debug A
A = lerp(A, 80, 0.5)
Debug A
A = lerp(A, 80, 0.5)
Debug A
A = lerp(A, 80, 0.5)
Debug A
A = lerp(A, 80, 0.5)
Debug A

Re: pointer-trail similar as Gradius ship

Posted: Thu Oct 26, 2017 1:59 pm
by Psychophanta
Good ideas for inspiring.
Even there are thousands of "classic" games, I realize there can be multiple ways to perform these kind of things.

Thank you all.

Re: pointer-trail similar as Gradius ship

Posted: Fri Nov 10, 2017 7:35 pm
by Psychophanta
Play freely with constant values, and use freely for you ideas too:

Code: Select all

Structure Vector2D
  x.f:y.f
EndStructure

Global SW.u=1024,SH.u=768
InitMouse():InitSprite():InitKeyboard()
OpenWindowedScreen(OpenWindow(0,0,0,3*SW/4,3*SH/4,"maggot",#PB_Window_ScreenCentered),0,0,3*SW/4,3*SH/4,1,0,0)

CreateSprite(8,32,32)
StartDrawing(SpriteOutput(8))
Circle(16,16,15,$AABE2A)
StopDrawing()

MouseLocate(SW/2,SH/2)

Global .Vector2D V0,V,p0,NewList p()
#maxitems=3000; <- numero maximo de anillos
#a=0.07
#b=0.2
#r=0.33
#f=1:#f0=2
#d=200; <- divisor de velocidad
Repeat
  ClearScreen(0):ExamineKeyboard():ExamineMouse()
  ForEach p()
    V\x=(p0\x-p()\x)*#a*val.f:V\y=(p0\y-p()\y)*#a*val.f
    p()\x+#f0*V\x-#f*V0\x:p()\y+#f0*V\y-#f*V0\y
    DisplayTransparentSprite(8,p()\x-16,p()\y-16)
    V0=V
    p0=p()
  Next
  V0\x=MouseDeltaX()/#d:V0\y=MouseDeltaY()/#d:val.f=Pow(V0\x*V0\x+V0\y*V0\y,#r)+#b
  p0\x=MouseX():p0\y=MouseY()
  DisplayTransparentSprite(8,p0\x-16,p0\y-16,222,$5696AA)
  If MouseButton(#PB_MouseButton_Right) And ListSize(p())<#maxitems:AddElement(p()):p()=p0
  ElseIf LastElement(p()) And MouseButton(#PB_MouseButton_Left):DeleteElement(p())
  EndIf
  FlipBuffers():Delay(15)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()