Question: Hello, I tried to execute this code on processing but it does not work. Can I please get help for the game to run correctly?

Hello, I tried to execute this code on processing but it does not work. Can I please get help for the game to run correctly? you can modify the game however you like just as long as its working
CODE FOR MY GAME:
PShape ghost1, ghost2, eyes1, eyes2;
int pacX, pacY; // Position of Pac-Man
int pacSize =40; // Size of Pac-Man
int dotSize =15; // Size of dots
int dotSpacing =50; // Spacing between dots
int numDots =20; // Number of dots
int score =0; // Score
int ghost1X, ghost1Y; // Position of Ghost 1
int ghost2X, ghost2Y; // Position of Ghost 2
int ghostSpeed =1; // Ghosts' movement speed
boolean mouthOpen = true; // Controls Pac-Man's chomping animation
void setup(){
size(1000,1000);
pacX = width /2;
pacY = height /2;
// Initialize ghost positions
ghost1X = width /4;
ghost1Y = height /2;
ghost2X =3* width /4;
ghost2Y = height /2;
// Load ghost and eyes models
ghost1= loadShape("ghost.svg");
eyes1= loadShape("eyes.svg");
ghost2= loadShape("ghost.svg");
eyes2= loadShape("eyes.svg");
}
void draw(){
background(0);
// Draw dots
for (int i =0; i < numDots; i++){
int dotX = i * dotSpacing + dotSpacing /2;
int dotY = height /2;
fill(250);
ellipse(dotX, dotY, dotSize, dotSize);
}
// Draw Ghosts
drawGhost(ghost1, eyes1, ghost1X, ghost1Y);
drawGhost(ghost2, eyes2, ghost2X, ghost2Y);
// Draw Pac-Man with chomping animation
fill(255,255,0);
arc(pacX, pacY, pacSize, pacSize, mouthOpen ?0.2 : PI *1.8, mouthOpen ? TWO_PI -0.2 : PI *2.2);
// Chomping animation
if (frameCount %30==0){
mouthOpen =!mouthOpen;
}
// Move Pac-Man
pacX =(pacX +1)% width;
// Move Ghosts towards Pac-Man
moveGhostTowardsPacman(ghost1X, ghost1Y);
moveGhostTowardsPacman(ghost2X, ghost2Y);
// Check for collisions
checkCollision();
// Show score
displayScore();
}
void drawGhost(PShape ghost, PShape eyes, int x, int y){
// Draw default ghost with reduced-size eyes on top
ghost.enableStyle();
shape(ghost, x, y);
shape(eyes, x +50, y +30,100,100);
// Disable style of ghost and draw same ghost and eyes
ghost.disableStyle();
shape(ghost, x +150, y);
shape(eyes, x +200, y +30,100,100);
// Change fill to red and draw same ghost and eyes
fill(255,0,0);
shape(ghost, x +300, y);
shape(eyes, x +350, y +30,100,100);
noFill();
}
void moveGhostTowardsPacman(int ghostX, int ghostY){
if (ghostX < pacX){
ghostX += ghostSpeed;
} else {
ghostX -= ghostSpeed;
}
}
void checkCollision(){
// Check collisions with Pac-Man
//...
}
void displayScore(){
fill(255);
textSize(20);
text("Score: "+ score, 20,30);
}
void keyPressed(){
if (keyCode == UP){
pacY -=10; // Shift Pac-Man up
} else if (keyCode == DOWN){
pacY +=10; // Shift Pac-Man down
} else if (keyCode == LEFT){
pacX -=10; // Shift Pac-Man left
} else if (keyCode == RIGHT){
pacX +=10; // Shift Pac-Man right
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!