It is currently Sun Nov 19, 2017 7:05 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: pointer-trail similar as Gradius ship
PostPosted: Sat Oct 21, 2017 11:26 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4385
Location: Spa, relaxing and thinking, and learning...
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:
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! :)

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: pointer-trail similar as Gradius ship
PostPosted: Tue Oct 24, 2017 10:38 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 637
Location: right here
interesting :)

Code:
  ;;;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'.


Top
 Profile  
Reply with quote  
 Post subject: Re: pointer-trail similar as Gradius ship
PostPosted: Tue Oct 24, 2017 2:02 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 8:51 am
Posts: 1378
Location: Germany
Better you using a 2D pyhsics engine.
Look this one (SWF snake game called Python):
http://www.gameslist.com/Python

_________________
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...


Top
 Profile  
Reply with quote  
 Post subject: Re: pointer-trail similar as Gradius ship
PostPosted: Tue Oct 24, 2017 8:20 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 887
Location: Ukraine
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:
; 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

_________________
Time beyond time

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
 Post subject: Re: pointer-trail similar as Gradius ship
PostPosted: Thu Oct 26, 2017 1:59 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4385
Location: Spa, relaxing and thinking, and learning...
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.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
 Post subject: Re: pointer-trail similar as Gradius ship
PostPosted: Fri Nov 10, 2017 7:35 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4385
Location: Spa, relaxing and thinking, and learning...
Play freely with constant values, and use freely for you ideas too:
Code:
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()

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
While (world==business) {world+=mafia}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye