Hello, here is my attempt at it any help would be much appreciated.
//The variables that control everything known about the pacman
float pacmanX, pacmanY; //The position of the pacman
final int PACMAN_DIAMETER = 50; //The diameter of the pacman
float pacmanAngle = 0.0; //The direction the pacman is facing
float pacmanMouth = 0.0; //The angle that the mouth is open
int directionX = 0;
int directionY = 0;
int speed = 3;
void setup() {
size(500, 500);
smooth();
pacmanX = width/2; //Start the pacman in the
pacmanY = height/2; //centre of the canvas
}
void draw() {
background(0); //draw a fresh frame each time
movePacman(); //Move the pacman toward the mouse
turnPacman(); //Turn it to face the mouse
animateMouth(); //Make the mouth open and close
drawPacman(); //And draw it
}
void drawPacman() {
fill(255, 255, 0); //yellow pacman
stroke(0); //with a black outline
strokeWeight(2); //that's a little thicker
arc(pacmanX, pacmanY, PACMAN_DIAMETER, PACMAN_DIAMETER,
pacmanAngle+pacmanMouth/2, pacmanAngle+TWO_PI-pacmanMouth/2, PIE);
}
void animateMouth() {
//This function changes the pacmanMouth variable so that it slowly
//increases from 0 to PACMAN_MAX_MOUTH, then snaps closed to 0 again.
final float PACMAN_MOUTH_SPEED = 0.08;
final float PACMAN_MAX_MOUTH = 1.5;
//Increase the mouth opening each time, but snap it shut at the maximum
pacmanMouth = (pacmanMouth + PACMAN_MOUTH_SPEED)%PACMAN_MAX_MOUTH;
}
void movePacman() {
//Change the pacman's position (paxmanX and pacmanY) by 1/Nth
//of the distance from the pacman to the mouse, in both X and Y.
// int N = 20; //Try moving 1/20th of the way each frame.
// float xChange = (mouseX-pacmanX)/N;
// float yChange = (mouseY-pacmanY)/N;
//Move the pacman by those amounts.
// pacmanX = pacmanX + xChange;
// pacmanY = pacmanY + yChange;
pacmanX += speed;
if (pacmanX > width) {
pacmanX = -PACMAN_DIAMETER;
}
if (pacmanY > height) {
pacmanY = -PACMAN_DIAMETER;
}
}
void turnPacman() {
//Set the pacmanAngle variable to be the angle from the pacman to the mouse
//The atan2() function can be found in the Processing reference pages
// pacmanAngle = atan2(pacmanY,pacmanX);
}
void keyPressed () {
if (key == CODED);
if (keyCode == RIGHT) {
directionX += 0 ;
if (keyCode == DOWN) {
directionY += 1 ;
}
if (keyCode == LEFT) {
directionX += 2 ;
}
if (keyCode == UP) {
directionY += 3 ;
}
}
}
type or paste code here