Author Topic: Rotating, distorting sprite circle (from D-Bug 185 remake)  (Read 2219 times)

0 Members and 1 Guest are viewing this topic.

Offline KrazyK

  • Amiga 1200
  • ****
  • Posts: 278
  • Karma: 121
    • View Profile
    • KrazyK Remakes
Here's a snippet of code I conjoured up for the sprite circle routine in my D-Bug 185 remake.
Purebasic 5.20 (beta 5)
Feel free to use this code......credit would be nice though... :cheers:


Code: [Select]
;D-BUG 185 rotating sprite circle routine
;KrazyK
;July 2013
;For DBFInteractive.com

;PB 5.20 Beta 5

InitSprite()
OpenWindow(1,0,0,640,480,"DBUG 185",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_WindowCentered)
OpenWindowedScreen(WindowID(1),0,0,640,480)
ShowCursor_(0)
StickyWindow(1,1)


Global stp.f,t.f
Global CSPR=2501            ;our starting sprite number
Global xpos,ypos

#INT=220                    ;transparency value
#RADIUS=80                  ;circle radius
#NumBalls=16
Global stp.f=(#PI*2)/#NumBalls

Procedure DetectBalls()
       ;very simple routine to detect our boundary box and limit the ball sprites to the edges
If xpos <=0 : xpos=0:EndIf                      ;test left edge
If (xpos+16) >=640 : xpos=640-32:EndIf        ;test right edge
If ypos <=40 : ypos=40:EndIf        ;test top edge
If (ypos+16) >440-64 : ypos=440-64-16:EndIf      ;test top edge
EndProcedure

Procedure DrawCircle(CX,CY)
       t+0.085                                   ;move the balls to the left
       If t>=360:t=0:EndIf
For BALL=2501 To 2516                    ;16 sprites
t.f+stp.f                         ;step around the circle
xpos=CX+(Sin(t)*#RADIUS)         
ypos=CY+(Cos(t)*#RADIUS)         
DetectBalls()                 ;check the bounding box
DisplayTransparentSprite(BALL,xpos,ypos,#INT)
Next BALL
EndProcedure

Procedure InitCircle()

       ;create some basic sprites.  I used captured bitmaps in the remake.
       CreateSprite(1,32,32)
       StartDrawing(SpriteOutput(1))
              Circle(16,16,16,RGB(198,165,66))
       StopDrawing()
       
       CreateSprite(2,32,32)
       StartDrawing(SpriteOutput(2))
              Circle(16,16,16,RGB(32,165,198))
       StopDrawing()
       
For C=1 To 16 Step 2
              CopySprite(1,2500+C)
Next C
For C=2 To 16 Step 2
              CopySprite(2,2500+C)
Next C
EndProcedure

valuesx=64           ;x speed
valuesy=48           ;y speed
stpx.f=(#PI*2)/valuesx
stpy.f=(#PI*2)/valuesy

InitCircle()

Repeat
ClearScreen(0)
x.f+stpx/1.5                ;circle speed x
y.f+stpy.f/1.5              ;circle speed y
cxpos=(300+(Sin(x.f)*320))
cypos=(200+(Sin(y.f)*180))
DrawCircle(cxpos,cypos)
FlipBuffers()
If GetAsyncKeyState_(#VK_ESCAPE):End:EndIf
ForEver
« Last Edit: July 23, 2013 by KrazyK »
Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 978
  • Karma: 258
    • View Profile
Nice! Thanks for sharing. K++ :)
Challenge Trophies Won:

Offline emook

  • C= 64
  • **
  • Posts: 88
  • Karma: 12
    • View Profile
Lovely work, very smooth - keep em comming :)

 :clap:
----

R Tape loading error, 0:1

Offline jace_stknights

  • Amiga 1200
  • ****
  • Posts: 399
  • Karma: 32
  • PEEK & POKE are not MOVEM!
    • View Profile
    • ST Knights WebSite
 :clap:
Thanx!
Challenge Trophies Won: