Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have an issue with my code, It is about pac man but the ghosts wont follow the pacman and there are not enough dots
I have an issue with my code, It is about pac man but the ghosts wont follow the pacman and there are not enough dots on the screen. After i get a few dots, they do not respawn and the game does not end when the pac man colides with the ghosts despite me making a code for it
here is my code for the game:
PShape ghost ghost eyes eyes;
int pacX, pacY;
int pacSize ;
int dotSize ;
int dotSpacing ;
int numDots ;
int score ;
int ghostX ghostY;
int ghostX ghostY;
int ghostSpeed ;
boolean mouthOpen true;
void setup
size;
pacX width ;
pacY height ;
ghostX width ;
ghostY height ;
ghostX width ;
ghostY height ;
ghost loadShapeghostsvg;
eyes loadShapeeyessvg;
ghost loadShapeghostsvg;
eyes loadShapeeyessvg;
void draw
background;
for int i ; i numDots; i
int dotX i dotSpacing dotSpacing ;
int dotY height ;
fill;
ellipsedotX dotY, dotSize, dotSize;
drawGhostghost eyes ghostX ghostY;
drawGhostghost eyes ghostX ghostY;
fill;
arcpacX pacY, pacSize, pacSize, mouthOpen : PI mouthOpen TWOPI : PI ;
if frameCount
mouthOpen mouthOpen;
moveGhostTowardsPacmanghostX ghostY;
moveGhostTowardsPacmanghostX ghostY;
checkCollision;
displayScore;
void drawGhostPShape ghost, PShape eyes, int x int y
ghost.enableStyle;
shapeghost x y;
shapeeyes x y ;
ghost.disableStyle;
shapeghost x y;
shapeeyes x y ;
fill;
shapeghost x y;
shapeeyes x y ;
noFill;
void moveGhostTowardsPacmanint ghostX, int ghostY
if ghostX pacX
ghostX ghostSpeed;
else
ghostX ghostSpeed;
void checkCollision
if distpacX pacY, ghostX ghostY pacSize
gameOver;
if distpacX pacY, ghostX ghostY pacSize
gameOver;
for int i ; i numDots; i
int dotX i dotSpacing dotSpacing ;
int dotY height ;
if distpacX pacY, dotX, dotY pacSize
score;
numDots;
void gameOver
printlnGame over!";
void displayScore
fill;
textSize;
textScore: score, ;
void keyPressed
if keyCode UP
pacY ;
else if keyCode DOWN
pacY ;
else if keyCode LEFT
pacX ;
else if keyCode RIGHT
pacX ;
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