Vuyani Vorslag Rocks PacMan

And now with text … See Vuyani’s code here

vuyani's pacman

vuyani’s pacman

To display a text label on PacMan, Vuyani had to change the PacMan function – notice that when he calls the function he adds a string label (“Vuyani Vorslag Rocks Pacman”) as the final parameter.

//use for loop to draw pacman across the screen
for(x=0;x<width;x+=radius){
 drawPacman(x, y, ngwevu, female, radius, 1, 
"Vuyani Vorslag Rocks PacMan"); 
 }

For that function call to work, Vuyani also had to add the label to the PacMan function itself. Notice that he defines the function with “String msg” as the final parameter.

void drawPacman(float pacX, float pacY, color clr, Boolean ms,
 int pacRadius, int direction, String msg){
[function goes here]
}

This mean he can draw the text with the following code.

fill(lubhelu);
text(msg,100,100);

Here is the whole function:

void drawPacman(float pacX, float pacY, color clr, Boolean ms,
 int pacRadius, int direction, String msg)
{
fill(clr);
noStroke();
if (direction==1)
 {
 //draw pacman facing right
 arc(pacX, pacY, radius,radius, radians(45), radians(315));
 }
else
 {
 //draw pacman facing left
 arc(pacX, pacY, radius,radius, radians(225), radians(360+135));
 }
//draw eyes
fill(0);
ellipse(pacX,pacY-radius/3,radius/5,radius/5);
if (female == true)
 {
 //draw ribbon for ms pacman
 fill(255, 0, 0, 200);
 triangle(pacX,pacY-radius/2,pacX+radius/3,pacY-(radius/3)*2,
pacX+radius/3,pacY-radius/3);
 triangle(pacX-radius/3,pacY-(radius/3)*2,pacX,pacY-radius/2,
pacX-radius/3,pacY-radius/3);
 }

fill(lubhelu);
text(msg,pacX,pacY);
}
Advertisements

One thought on “Vuyani Vorslag Rocks PacMan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s