# Maze Game trying to display scary image

**URL:** <https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641>\
**Category:** Coding Questions\
**Created:** [April 25, 2019, 8:44pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641 "2019-04-25T20:44:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuerillaGirl](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@GuerillaGirl](https://discourse.processing.org/u/GuerillaGirl)\
**Post date:** [April 25, 2019, 8:44pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641/1 "2019-04-25T20:44:01Z")

</div>

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!

```auto
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--;
}
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 25, 2019, 10:25pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641/2 "2019-04-25T22:25:28Z")

</div>

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

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

```

before setup

boolean showScary=false;

untested

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 25, 2019, 10:25pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641/3 "2019-04-25T22:25:40Z")

</div>

or look a the dist () command

---

<div class="post-metadata">

**Author:** ![GuerillaGirl](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@GuerillaGirl](https://discourse.processing.org/u/GuerillaGirl)\
**Post date:** [April 29, 2019, 8:24pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641/4 "2019-04-29T20:24:46Z")

</div>

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?

```auto
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--;
  }
}

```

---

<div class="post-metadata">

**Author:** ![GuerillaGirl](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@GuerillaGirl](https://discourse.processing.org/u/GuerillaGirl)\
**Post date:** [April 29, 2019, 8:35pm UTC](https://discourse.processing.org/t/maze-game-trying-to-display-scary-image/10641/5 "2019-04-29T20:35:41Z")

</div>

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

```auto
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--;
  }
}

```
