News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

PlayBASICs - Shape Commands

Started by kevin, September 09, 2003, 12:53:25 PM

Previous topic - Next topic

kevin

Here's an simple example of PlayBASICs  Shapes routines.   This code not only creates the shapes and can rotate/zoom them. Moreover it also handles collision between shapes to points/lines/circles/regions and other shapes..


PlayBASIC Code: [Select]
   ThisShape=GetFreeShape()
CreateConvexShape ThisShape,100,5
ShiftShape ThisShape,50,50

CreateConvexShape 2,50,19

CreateConvexShape 19,35,3
CreateConvexShape 20,25,29
CreateConvexShape 21,100,3

ShiftShape 20,50,50
MergeShape 20,21
ShiftShape 20,-100,-100
MergeShape 20,21
MergeShape 19,21


CReate_Star_Shape(3,50,21)
MergeShape 3,2


OriginX#=50
OriginY#=50


Do
Cls 0

RotateShape ThisShape,Angle#,1
Angle#=wrapvalue(angle#,1)

mx#=mousex()
my#=mousey()




x#=400
y#=400

Ypos=50

if PointHitShape(mx#,my#,ThisShape,x#,y#)=1
ink $774422
M$="Point Hit Shape"
else
ink $ff0000
M$="Point Missed Shape"
endif
Ypos=Message(m$,ypos)



if LineHitShape(originx#,originy#,mx#,my#,ThisShape,x#,y#)=1
M$="Line Hit Shape"
ink $77ff22
else
M$="Line Missed Shape"
endif
Ypos=Message(m$,ypos)


if CircleHitShape(mx#,my#,10,ThisShape,x#,y#)=1
M$="Circle Hit Shape"
ink $773377
else
M$="Circle Missed Shape"
endif
Ypos=Message(m$,ypos)


bx1#=mx#+50
bx2#=mx#+150
by1#=my#
by2#=my#+100


if BoxHitShape(bx1#,by1#,bx2#,by2#,ThisShape,x#,y#)=1
M$="Boc Hit Shape"
ink $883322
else
M$="Box Missed Shape"
endif
Ypos=Message(m$,ypos)


testShapex#=mx#-100
testShapeY#=my#-100


if ShapeHitShape(2,testshapex#,TestShapey#,ThisShape,x#,y#)=1
M$="Shape Hit Shape"
ink $58a399
else
M$="Shape Missed Shape"
endif
Ypos=Message(m$,ypos)

DrawShape ThisShape,x#,y#,0



Linec Originx#,Originy#,mx#,my#,$448822
Circlec mx#,my#,10,1,$448822
Boxc bx1#,by1#,bx2#,by2#,$779822

DrawShape 2,testShapex#,testShapeY#,0

DrawShape 3,100,100,0

; ---------------------------------------; Rotate Zoom the custom shape; ---------------------------------------

ink $4470aa
RotateShape 21,Angle#,(1+sin(angle#))
DrawShape 21,400,300,0


If (MouseButton()&2)=2
OriginX#=MouseX()
OriginY#=MouseY()
EndIf
Sync
loop


Function Message(m$,Ypos)
text 20,Ypos,m$
ypos=ypos+20
EndFunction Ypos

Function CReate_Star_Shape(Shape,Radius,Points)
CreateShape Shape,Points+1,Points+1
Anglestep#=360.0/Points
Angle#=0
For lp=0 to points-1
r=Rnd(Radius)
x#=cosradius(angle#,r)
Y#=sinradius(angle#,r)
SetShapeVertex Shape,lp,X#,y#
Angle#=Angle#+AngleStep#
next
For lp=0 to points-1
lp2=lp+1
if lp2>(points-1) then lp2=0
SetShapeEdge Shape,lp,lp,lp2
next lp
EndFunction




las6

that looks great.
I love playing with 2d polygons. ;)

Although those shape commands aren't all that obvious.
system specs: Win XP pro, 2700+ (TB), 1024 Mb DDR, Radeon 9600 pro (128).