Answered step by step
Verified Expert Solution
Question
1 Approved Answer
hi , I have an error in my Processing code can you please help identify the error? code: int currentAnimation = 0 ; / /
hi I have an error in my Processing code can you please help identify the error?
code:
int currentAnimation ; Variable to keep track of the current animation
float animationStartTime; Variable to store the start time of each animation
void setup
size;
animationStartTime millis; Initialize the start time
void draw
background;
Check if it's time to switch to the next animation
if millis animationStartTime
currentAnimation; Move to the next animation
if currentAnimation
currentAnimation ; Reset to the first animation if we've reached the end
animationStartTime millis; Reset the start time for the new animation
Draw the current animation
switch currentAnimation
case :
drawAnimation;
break;
case :
drawAnimation;
break;
case :
drawAnimation;
break;
void drawAnimation
int pacX, pacY; Position of PacMan
int pacSize ; Size of PacMan
int dotSize ; Size of dots
int dotSpacing ; Spacing between dots
int numDots ; Number of dots
int score ; Score
int ghostX ghostY; Position of Ghost
int ghostX ghostY; Position of Ghost
int ghostSpeed ; Ghosts' movement speed
boolean mouthOpen true; Controls PacMan's chomping animation
void setup
size;
pacX width ;
pacY height ;
Initialize ghost positions
ghostX width ;
ghostY height ;
ghostX width ;
ghostY height ;
void draw
background;
Draw dots
for int i ; i numDots; i
int dotX i dotSpacing dotSpacing ;
int dotY height ;
fill;
ellipsedotX dotY, dotSize, dotSize;
Draw Ghosts struggled to add ghosts.svg and eyes.svg because they froze and did not move so I had to remove it
fill; Red color for Ghost
ellipseghostX ghostY pacSize, pacSize;
fill; Blue color for Ghost
ellipseghostX ghostY pacSize, pacSize;
Draw PacMan with chomping animation
fill;
arcpacX pacY, pacSize, pacSize, mouthOpen : PI ;
Chomping animation
if frameCount
mouthOpen mouthOpen;
Moves PacMan
pacX pacX width;
Moves Ghosts towards PacMan
if ghostX pacX
ghostX ghostSpeed;
else
ghostX ghostSpeed;
if ghostX pacX
ghostX ghostSpeed;
else
ghostX ghostSpeed;
Checks for collisions
checkCollision;
Shows score
displayScore;
void checkCollision
for int i ; i numDots; i
int dotX i dotSpacing dotSpacing ;
int dotY height ;
float distance distpacX pacY, dotX, dotY;
Check collision with PacMan
if distance pacSize dotSize
score;
Check collision with Ghosts
float ghostDistance distpacX pacY, ghostX ghostY;
float ghostDistance distpacX pacY, ghostX ghostY;
if ghostDistance pacSize ghostDistance pacSize
Game over text
printlnGame Over! Your score: score;
noLoop; Stop the draw loop
Allows player to control the Pacman with the basic arrow keys
void keyPressed
if keyCode UP
pacY ; Shift PacMan up
else if keyCode DOWN
pacY ; Shift PacMan down
else if keyCode LEFT
pacX ; Shift PacMan left
else if keyCode RIGHT
pacX ; Shift PacMan right
Shows score
void displayScore
fill;
textSize;
textScore: score, ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started