Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello i made this code with processing that shows a pacman eating circles and I am hoping if you can help me modify this code

hello i made this code with processing that shows a pacman eating circles and I am hoping if you can help me modify this code by having two ghosts chasing the pac man left and right. I would also be happy if you were able to make the pac man chomp. The code is shown below:
int pacX, pacY; // Position of Pac-Man
int pacSize =90; // Size of Pac-Man
int dotSize =20; // Size of dots
int dotSpacing =50; // Spacing between dots
int numDots =10; // Number of dots
int score =0; // Score
void setup(){
size(400,400);
pacX = width /2;
pacY = height /2;
}
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 Pac-Man
fill(255,255,0);
arc(pacX, pacY, pacSize, pacSize, 0.2, PI *1.8); // Chomping animation
// Move Pac-Man
pacX =(pacX +1)% width; // Pac-Man moves to the right
delay(100); // Slow down animation
}
void checkCollision(){
for (int i =0; i < numDots; i++){
int dotX = i * dotSpacing + dotSpacing /2;
int dotY = height /2;
float distance = dist(pacX, pacY, dotX, dotY);
if (distance < pacSize /2+ dotSize /2){
score++;
// Remove dot from the screen
// Optional: You can also play a sound effect
}
}
}
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
}
}
void displayScore(){
fill(255);
textSize(20);
text("Score: "+ score, 20,30);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions