News:

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

Main Menu

Draw Pacman Using Filled Shape

Started by kevin, December 20, 2013, 12:39:38 AM

Previous topic - Next topic

kevin

  Draw Pacman Using Filled Shape

     This example draws a Pacman styled character by using the shape commands.  The function takes two angles and creates a circular outline from the starting angle towards the end.   These vertex are then joined as edges and the shape filler does the rest.  

PlayBASIC Code: [Select]
      loadfont "veranda", 1, 48

setfps 60

do

cls $223355

if spacekey()
angle=wrapangle(Angle+10)
endif


BiteSize=32+cos(BiteAngle)*30

lockbuffer
ink $ff40a020
Draw_PacMan(Xpos,300,200,angle+BiteSize,angle-BiteSize)

Xpos2=Xpos-150
Ypos=450
Radius=60
for kidlp=1 to 10
ink $ff607080
Draw_PacMan(Xpos2,Ypos,Radius,angle+BiteSize,angle-BiteSize)
Xpos2-=50
Radius-=3
next

lockbuffer

BiteAngle=wrapangle(BiteAngle+5)


Xpos+=5
if XPos>1500 then Xpos=-500

ink $eeeeee
centertext 400,10,"PacMan and family"

Sync
loop



Function Draw_PacMan(Xpos,Ypos,Radius,ArcStart,ArcEnd)

If ArcEnd<ArcStart then ArcEnd+=360

AngleDiff=ArcEnd-ArcStart

Segs=36
Segs*=Radius/30.0

VertexCount=Segs+4

ThisShape=NewShape(VertexCount,VertexCount)

Edge=0
Vertex=0
FirstVertex=Vertex
SetShapeVertex ThisShape,Vertex,0,0 : Vertex++

AngleStep#=float(AngleDiff)/Segs

For lp = 0 to Segs-1
LastVertex=Vertex
Vertex++
Angle#=ArcStart+(lp*angleStep#)
X=Cos(Angle#)*RAdius
Y=Sin(Angle#)*RAdius
SetShapeVertex ThisShape,Vertex,X,Y
SetShapeEdge ThisShape,Edge,LastVertex,Vertex
edge++
next

X=Cos(ArcEnd)*RAdius
Y=Sin(ArcEnd)*RAdius
SetShapeVertex ThisShape,Vertex,X,Y
SetShapeEdge ThisShape,Edge,Vertex,FirstVertex

// draw filled
drawshape ThisShape,Xpos,Ypos,2
// draw outlines
OldRGB=GetInk()
Ink RGBFade(oldRgb,50)
drawshape ThisShape,Xpos,Ypos,1

deleteshape ThisSHape

EndFunction





ATLUS