Pacman and ghost

edited April 2016 in Questions about Code

Hello people!

We are doing a pacman with some friends. Unfortunately we can't manage to find out how to program the death of the pacman. We have also the same problem for "eating the coins". We know where our error is ! But we don't know how to solve it We have the position of the pacman (positionX/positionY) and of the ghost (positionF1X/positionF1Y)

if(positionX==positionF1X && positionY==positionF1Y){ background(0);
textSize(40); text("GAME OVER",200,200); text("SCORE FINAL ="+score,170,140); fill(255); }

if(positionX==positionF2X && positionY==positionF2Y){ background(0);
textSize(40); text("GAME OVER",200,200); text("SCORE FINAL ="+score,170,140); fill(255); }

if(positionX==positionF3X && positionY==positionF3Y){ background(0);
textSize(40); text("GAME OVER",200,200); text("SCORE FINAL ="+score,170,140); fill(255); }

if(positionX==positionF4X && positionY==positionF4Y){ background(0);
textSize(40); text("GAME OVER",200,200); text("SCORE FINAL ="+score,170,140); fill(255);

BUT! the position of the pacman is never completely and just superpose with the ghost! So we would like to know if there is a way to create an "if" with an interval of values (for example if positionX is nearly as positionF1X, at 10 pixels near).

Is there a solution? Thanks you so much for your help!

TeamPac

Tagged:

Answers

  • you could use the command dist()

    OR

    take the difference between the two and take its abs() and then check whether that is < a value like 18

    see reference on dist OR abs

Sign In or Register to comment.