Testing moving a circle

Advanced game related topics
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Testing moving a circle

Post by ricardo »

I never do anything related to games before. I want to move the circle but something went wrong !

See and cry

Code: Select all

#ScreenWidth  = 800  ; Feel free to change this to see the pixel filling speed !
#ScreenHeight = 600

If InitSprite() = 0 Or InitKeyboard()=0
  MessageRequester("Error","DirectX 7+ is needed.",0)
EndIf




If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")
  
  Repeat
    
    wave+6
    x+2
    If wave > 320 : wave = 0 : EndIf
    
    If StartDrawing(ScreenOutput())
          Circle(x, 100, 30, RGBA(100, 255, 100, 10))
      StopDrawing()
    EndIf
    
    ExamineKeyboard()
    
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error","Can't open the screen !",0)
EndIf

End

Any help are apprecited.
Also i do not know how to use delay or something similar. I want to move the circle according to specific times AND also move it to the position where i put the mouse and give a click.
Also, alpha do nothing :P

Can anybody can give me a simple example please?

Thanks in advance !! :)
ARGENTINA WORLD CHAMPION
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Testing moving a circle

Post by Lunasole »

Just missed ClearScreen() ^^

Code: Select all

#ScreenWidth  = 800  ; Feel free to change this to see the pixel filling speed !
#ScreenHeight = 600

If InitSprite() = 0 Or InitKeyboard()=0
  MessageRequester("Error","DirectX 7+ is needed.",0)
EndIf



If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")
  
  Repeat
    ; epilectic attack
    ClearScreen(RGB(Random(255), Random(255), Random(255)))
    
    wave+6
    x+2
    If wave > 320 : wave = 0 : EndIf
    
    If StartDrawing(ScreenOutput())
          Circle(x, 100, 30, RGBA(100, 255, 100, 10))
      StopDrawing()
    EndIf
    
    ExamineKeyboard()
    
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error","Can't open the screen !",0)
EndIf

End
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Testing moving a circle

Post by Fig »

; Feel free to change this to see the pixel filling speed ! <== ???
Not sure what you want to achieve here... But this is my understanding of what you asked...

Code: Select all

EnableExplicit
#ScreenWidth  = 800 
#ScreenHeight = 600
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):end:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   
   If StartDrawing(ScreenOutput())
      Circle(x, y, 30, RGBA(100, 255, 100, 10))
      Circle(MouseX(),MouseY(),2,RGBA(255,0,0,0)) ;display mouse position with a little red dot
      StopDrawing()
   EndIf

Until KeyboardPushed(#PB_Key_Escape)
End
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Testing moving a circle

Post by ricardo »

Fig wrote:
; Feel free to change this to see the pixel filling speed ! <== ???
Not sure what you want to achieve here... But this is my understanding of what you asked...

Code: Select all

EnableExplicit
#ScreenWidth  = 800 
#ScreenHeight = 600
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):end:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   
   If StartDrawing(ScreenOutput())
      Circle(x, y, 30, RGBA(100, 255, 100, 10))
      Circle(MouseX(),MouseY(),2,RGBA(255,0,0,0)) ;display mouse position with a little red dot
      StopDrawing()
   EndIf

Until KeyboardPushed(#PB_Key_Escape)
End
Hi,

Thanks for your explanation and examples !!

One additional question. The moving circle is not nice. Is there a way to draw it with a best definition, etc or should i need to use a bitmap?

In case i need a bitmap, how to add it to this examples?

Thanks
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Testing moving a circle

Post by ricardo »

If displaying a PNG with alpha, how to achieve it?

Or if drawing with RGBA how to get reults, in the example i don't see any result with RGBA
Last edited by ricardo on Sun Oct 15, 2017 8:29 pm, edited 1 time in total.
ARGENTINA WORLD CHAMPION
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Testing moving a circle

Post by Mijikai »

ricardo wrote:If displaying a PNG with alpha, how to achieve it?
U can use Sprites -> Helpfile "2D Games"

Code: Select all

;UsePNGImageDecoder()
;Sprite = CatchSprite(#PB_All,?BUFFER,#PB_Sprite_AlphaBlending)
;DisplayTransparentSprite(Sprite,X,Y)
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Testing moving a circle

Post by ricardo »

Hi,

If i want to draw the circle with high quality? Because its not showing smooth, but with very noticeable square definition in the curves.
ARGENTINA WORLD CHAMPION
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Testing moving a circle

Post by Fig »

I guess you are looking for antialiased circles. ̶P̶b̶ ̶d̶o̶e̶s̶n̶'̶t̶ ̶p̶r̶o̶v̶i̶d̶e̶ ̶t̶h̶a̶t̶ ̶k̶i̶n̶d̶ ̶o̶f̶ ̶c̶i̶r̶c̶l̶e̶ ̶b̶y̶ ̶d̶e̶f̶a̶u̶l̶t̶,̶ ̶s̶o̶r̶r̶y̶.̶
You can draw your own circle by using Bressenham algo but if you are a beginer, it's out of your reach for now.

If you want a better circle definition, increment your resolution to decent values. (800x600 is not enough)
1280x768 or even more if your screen can display it.

Code: Select all

EnableExplicit
#ScreenWidth  = 1280
#ScreenHeight = 768
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
Define alpha.a=128    ;alpha chanel
Define inc_alpha.b=1
Define i.i,larg.i
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):End:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf
;create a new sprite BACKGROUND
CreateSprite(0,#ScreenWidth,#ScreenHeight)
StartDrawing(SpriteOutput(0))
For i=1 To 100
   larg=Random(100,40)
   Box(Random(#ScreenHeight),Random(#ScreenWidth),larg,larg,Random($ffffff))
Next i      
StopDrawing()
;create a new sprite CIRCLE
CreateSprite(1,64,64)
StartDrawing(SpriteOutput(1))
Circle(32,32,31,RGB(100,255,100))
StopDrawing()
;create a new sprite MOUSE
CreateSprite(2,16,16)
StartDrawing(SpriteOutput(2))
Circle(8,8,7,RGB(255,0,0))
StopDrawing()

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   ;display background
   DisplaySprite(0,0,0)
   ;display sprite Circle with alphachanel
   DisplayTransparentSprite(1,x,y,Alpha)
   Alpha+inc_alpha
   If alpha=255 Or alpha=0:inc_alpha=-inc_alpha:EndIf
   ;display mouse
   DisplayTransparentSprite(2,MouseX(),MouseY())
Until KeyboardPushed(#PB_Key_Escape)
End
Last edited by Fig on Mon Oct 16, 2017 7:05 pm, edited 2 times in total.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Testing moving a circle

Post by davido »

Wouldn't the VectorDrawing Library produce a satisfactory anti aliased circle?

Code: Select all

  If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)

    If StartVectorDrawing(CanvasVectorOutput(0))

      ; partial circle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      AddPathCircle(100, 100, 75)
      FillPath()
      ; partial circle with lines to the center
      MovePathCursor(300, 100)
      AddPathCircle(300, 100, 75, 0, 235, #PB_Path_Connected)
      ClosePath()
      
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10)
    
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
DE AA EB
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Testing moving a circle

Post by Fig »

Nice :D
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Testing moving a circle

Post by ricardo »

davido wrote:Wouldn't the VectorDrawing Library produce a satisfactory anti aliased circle?

Code: Select all

  If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)

    If StartVectorDrawing(CanvasVectorOutput(0))

      ; partial circle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      AddPathCircle(100, 100, 75)
      FillPath()
      ; partial circle with lines to the center
      MovePathCursor(300, 100)
      AddPathCircle(300, 100, 75, 0, 235, #PB_Path_Connected)
      ClosePath()
      
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10)
    
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

But can be used in a game or animated 2D?
ARGENTINA WORLD CHAMPION
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Testing moving a circle

Post by davido »

@ricardo ,
There have been some demos of 2d animation. Please take a look at the one below by eddy:
http://www.purebasic.fr/english/viewtop ... 02#p489402

I don't think that there is any hardware acceleration for the Vector Library so the animation may not be smooth enough for fast games.
DE AA EB
Post Reply