Maze Game trying to display scary image

Hey - we are trying to get this maze to display a scary image if a player hits the edge but everything we have tried is not working. We pasted the code below. We thought if we used an if statement inside of draw it would work but it only displayed the image for a second. Please help, we are beginners!

PImage GreenMaze;
PImage LaLloronaDoe;
int x = 162;
int y = 162;
void setup(){
GreenMaze = loadImage("GreenMaze.gif"); 
LaLloronaDoe = loadImage("LaLloronaDoe.png");
size(290,290);

}

void draw() 
{
  float touch = red(get(x,y));

background(255);
image(GreenMaze,0,0);
if((x > 155) && (x < 180) && (y < 15)){
textSize(48);
textAlign(CENTER);
fill(255,0,0);
text("YOU WIN!",width/2,height/2);
println(mouseX + "," + mouseY);
}

fill(255, 0, 0);
noStroke();
ellipse(x,y, 10, 10);
if(touch <= 200){
x = 162;
y = 162;
//println(mouseX + "," + mouseY);
}

if(touch !=136 && touch ==255) {
image(LaLloronaDoe,0,0);
}
println(red(get(x,y)));
}

void keyPressed(){
if ((key == CODED) && (keyCode == UP)){
y--;
} 
if ((key == CODED) && (keyCode == DOWN)){
y++;
} 
if ((key == CODED) && (keyCode == RIGHT)){
x++;
} 

if ((key == CODED) && (keyCode == LEFT)){
x--;
}
}
1 Like

he’s probably running over the red spot or something?

if(showScary || ( touch !=136 && touch ==255)) {
    image(LaLloronaDoe,0,0);
    showScary=true; 
}

before setup

boolean showScary=false;

untested

2 Likes

or look a the dist () command

1 Like

Hey! Thanks for your help. Unfortunately it didn’t work and the red dot still moves over the green line without showing the scary image.

Do you think you could look at our code again?

PImage GreenMaze;
PImage LaLloronaDoe;
int x = 162;
int y = 162;
boolean showScary= false;


void setup() {
  GreenMaze = loadImage("GreenMaze.gif"); 
  LaLloronaDoe = loadImage("LaLloronaDoe.png");
  size(290, 290);
}

void draw() 
{
  float touch = red(get(x, y));

  if (showScary || ( touch !=136 && touch ==255)) {
    image(LaLloronaDoe, 0, 0);
    showScary=true;
  }

  background(255);
  image(GreenMaze, 0, 0);
  if ((x > 155) && (x < 180) && (y < 15)) {
    textSize(48);
    textAlign(CENTER);
    fill(255, 0, 0);
    text("YOU WIN!", width/2, height/2);
    println(mouseX + "," + mouseY);
  }

  fill(255, 0, 0);
  noStroke();
  ellipse(x, y, 10, 10);
  if (touch <= 200) {
    x = 162;
    y = 162;
    println(mouseX + "," + mouseY);
  }



  //if(touch !=136 && touch !=200) {
  //image(LaLloronaDoe,0,0);
  //}
  println(red(get(x, y)));
}

void keyPressed() {
  if ((key == CODED) && (keyCode == UP)) {
    y--;
  } 
  if ((key == CODED) && (keyCode == DOWN)) {
    y++;
  } 
  if ((key == CODED) && (keyCode == RIGHT)) {
    x++;
  } 

  if ((key == CODED) && (keyCode == LEFT)) {
    x--;
  }
}

We also tried this but unfortunately using distance this way did not work.

PImage GreenMaze;
PImage LaLloronaDoe;
int x = 162;
int y = 162;
boolean showScary= false;


void setup() {
  GreenMaze = loadImage("GreenMaze.gif"); 
  LaLloronaDoe = loadImage("LaLloronaDoe.png");
  size(290, 290);
}

void draw() 
{
  float touch = red(get(x, y));

  if (showScary || ( touch !=136 && touch ==255)) {
    image(LaLloronaDoe, 0, 0);
    showScary=true;
  }

  background(255);
  image(GreenMaze, 0, 0);
  if ((x > 155) && (x < 180) && (y < 15)) {
    textSize(48);
    textAlign(CENTER);
    fill(255, 0, 0);
    text("YOU WIN!", width/2, height/2);
  //  println(mouseX + "," + mouseY);
  }

  fill(255, 0, 0);
  noStroke();
  ellipse(x, y, 10, 10);
  if (touch <= 200) {
    x = 162;
    y = 162;
  }

float f = dist(x,y, touch, touch);
if (f > 134.38005 || f > 32.526913 && f < 129.52187 ){
      image(LaLloronaDoe, 0, 0);

}
    println(x,y, f);


  //if(touch !=136 && touch !=200) {
  //image(LaLloronaDoe,0,0);
  //}
 // println(red(get(x, y)));
}

void keyPressed() {
  if ((key == CODED) && (keyCode == UP)) {
    y--;
  } 
  if ((key == CODED) && (keyCode == DOWN)) {
    y++;
  } 
  if ((key == CODED) && (keyCode == RIGHT)) {
    x++;
  } 

  if ((key == CODED) && (keyCode == LEFT)) {
    x--;
  }
}