Answered step by step
Verified Expert Solution
Question
1 Approved Answer
hello, I have two codes and i want to make them run on the same scetch using processing. When the pac man game ends, it
hello, I have two codes and i want to make them run on the same scetch using processing. When the pac man game ends, it should go to the clock animation. this is homework i am struggling on
pacman game code:
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, ;
clock code:
void setup
size;
smooth;
void draw
background;
translatewidth height;
drawClock;
void drawClock
Draw clock face
noFill;
strokeWeight;
ellipse;
Calculate angles for hour, minute, and second hands
float hoursAngle maphour TWOPI HALFPI;
float minutesAngle mapminute TWOPI HALFPI;
float secondsAngle mapsecond TWOPI HALFPI;
hour hand
strokeWeight;
line coshoursAngle sinhoursAngle;
minute hand
strokeWeight;
line cosminutesAngle sinminutesAngle;
second hand
stroke; Brown color for seconds hand
strokeWeight;
line cossecondsAngle sinsecondsAngle;
center point
fill;
ellipse;
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