Answered step by step
Verified Expert Solution
Question
1 Approved Answer
hello I made a game of pac man and the ghost models i used were not good enough. My teacher gave me this code to
hello I made a game of pac man and the ghost models i used were not good enough. My teacher gave me this code to replace the ghost models but I dont know how to add it to my code.
MODEL FOR THE TWO GHOSTS:
PShape ghost, eyes;
void setup
size;
ghostloadShapeghostsvg;
eyesloadShapeeyessvg;
void draw
Draw default svg ghost to left with reducedsize eyes on top
ghost.enableStyle;
shapeghost;
shapeeyes;
Disable style of ghost and draw same ghost and eyes to right
ghost.disableStyle;
shapeghost;
shapeeyes;
Change fill to red and draw same ghost and eyes to right
fill;
shapeghost;
shapeeyes;
noFill;
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
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 PacPMan
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, ;
This is using processing code
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