UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: ATLUS on October 21, 2008, 09:23:31 AM

Title: 2d orbit
Post by: ATLUS on October 21, 2008, 09:23:31 AM
 :) useful to arcade game 8)
[pbcode]; PROJECT : orbit
; AUTHOR  : ATLUS
; CREATED : 20.10.2008
; EDITED  : 21.10.2008
; ---------------------------------------------------------------------



setfps 75
mouse 0; hide mouse
a=-90 ; start angel
b=100 ; y radius
c=100 ; x radius
spd_rotate=3; speed rotate
do
   cls rgb(0,0,0)
x=MouseX()+b*Cos(a)
y=MouseY()+c*Sin(a)
;make object
circleC MouseX(),MouseY(),10,1,RGB(33, 225, 28)
circleC x,y,10,1,RGB(247, 18, 6)
;input path
if leftkey()=1 then b=b-1
if rightkey()=1 then b=b+1
if upkey()=1 then c=c+1
if downkey()=1 then c=c-1
;status screen
Print "use mouse to move green circle and arrow keys to chouse path"
Print "Y radius"+Str$(c)
Print "X radius"+Str$(b)
a=a+spd_rotate
sync
loop[/pbcode]
Title: Re: 2d orbit
Post by: kevin on November 04, 2008, 06:11:24 AM
 This version has a few variables renames (so they are more meaningful to the reader) but the main difference is just that it displays the moving objects path as ellipse.

[pbcode]
   setfps 75
   mouse 0; hide mouse

   Angle      =-90 ; start angel

   RadiusX   =200 ; X radius
   RadiusY   =100 ; Y radius

   spd_rotate=3; speed rotate

   do

         cls Rgb(0,0,0)

         ; Get Mouse position
            Mx=MouseX()
            My=MouseY()

         ; Calc the position of the oribiting object            
            OrbitX=mx+(Cos(Angle)*RadiusX)
            OrbitY=my+(Sin(Angle)*RadiusY)

         ;make object
            circleC mx,my,10,1,RGB(33, 225, 28)

         ; display the path as an ellipse
            EllipseC mx,my,RadiusX,RadiusY,false,RGB(33, 225, 28)

         ; display the moving object         
            circleC OrbitX,OrbitY,10,1,RGB(247, 18, 6)



         ;input path
            if leftkey()=1 then RadiusX=RadiusX-1
            if rightkey()=1 then RadiusX=RadiusX+1
            if upkey()=1 then RadiusY=RadiusY+1
            if downkey()=1 then RadiusY=RadiusY-1

         ;status screen
            Print "use mouse to move green circle and arrow keys to choose path"
            Print "Y radius"+Str$(RadiusY)
            Print "X radius"+Str$(RadiusX)
   
         ; Move the angle clockwise (forward) wrapping it between 0 to 360 degrees
            Angle=WrapAngle(Angle,spd_rotate)
      sync
   loop
[/pbcode]


Title: Re: 2d orbit
Post by: ATLUS on November 04, 2008, 07:02:43 AM
Wow now very nice!! Thanks Kevin!!!!!!!
Title: Re: 2d orbit
Post by: kevin on November 04, 2008, 07:59:05 AM
   Here's a version that will draw/manage a batch of orbiting objects.

[pbcode]
   setfps 75
   mouse 0; hide mouse

   Angle      =-90 ; start angel

   RadiusX   =200 ; X radius
   RadiusY   =100 ; Y radius

   spd_rotate=3; speed rotate

   ; Number of objects to draw
   NumberOfObjects=10

   do

         cls Rgb(0,0,0)

         ; Get Mouse position
            Mx=MouseX()
            My=MouseY()


         ;make object
            circleC mx,my,10,1,RGB(33, 225, 28)

         ; display the path as an ellipse
            EllipseC mx,my,RadiusX,RadiusY,false,RGB(33, 225, 28)
            
   
         ; DRaw group of Objects
            for lp=1 to NumberOfObjects

               ThisAngle=Angle+(360.0/NumberOfObjects)*lp            

            ; Calc the position of the oribiting object            
               OrbitX=mx+(Cos(ThisAngle)*RadiusX)
               OrbitY=my+(Sin(ThisAngle)*RadiusY)

            ; display the moving object         
               circleC OrbitX,OrbitY,10,1,RGB(247, 18, 6)

            next

         ;input path
            if leftkey()=1 then RadiusX=RadiusX-1
            if rightkey()=1 then RadiusX=RadiusX+1
            if upkey()=1 then RadiusY=RadiusY+1
            if downkey()=1 then RadiusY=RadiusY-1

         ;status screen
            Print "use mouse to move green circle and arrow keys to choose path"
            Print "Y radius"+Str$(RadiusY)
            Print "X radius"+Str$(RadiusX)
   
         ; Move the angle clockwise (forward) wrapping it between 0 to 360 degrees
            Angle=WrapAngle(Angle,spd_rotate)
      sync
   loop

[/pbcode]


Title: Re: 2d orbit
Post by: ATLUS on November 04, 2008, 08:21:26 AM
 :) Attrakcion "wheel of the review"=)
Title: Re: 2d orbit
Post by: micky4fun on November 04, 2008, 06:01:13 PM
Nice demo , gyruss springs to mine

Great Stuff  ;D
Title: Re: 2d orbit
Post by: micky4fun on May 02, 2011, 05:28:04 PM
hi all

very usefull keeping forums open , this code by ATLUS used in my Egg Selector game

thanks for code ,

mick ;D