Main Menu

2d orbit

Started by ATLUS, October 21, 2008, 09:23:31 AM

Previous topic - Next topic

ATLUS

 :) useful to arcade game 8)
PlayBASIC Code: [Select]
; 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

kevin

#1
 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.

PlayBASIC Code: [Select]
   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





ATLUS

Wow now very nice!! Thanks Kevin!!!!!!!

kevin

#3
   Here's a version that will draw/manage a batch of orbiting objects.

PlayBASIC Code: [Select]
   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






ATLUS

 :) Attrakcion "wheel of the review"=)

micky4fun

Nice demo , gyruss springs to mine

Great Stuff  ;D

micky4fun

hi all

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

thanks for code ,

mick ;D