# Check if character sees other character

**URL:** https://discourse.processing.org/t/check-if-character-sees-other-character/32274
**Category:** Coding Questions
**Created:** [September 15, 2021, 5:28pm UTC](https://discourse.processing.org/t/check-if-character-sees-other-character/32274 "2021-09-15T17:28:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [September 15, 2021, 5:28pm UTC](https://discourse.processing.org/t/check-if-character-sees-other-character/32274/1 "2021-09-15T17:28:53Z")

</div>

how to check if enimy sees midas? if i3 is 1, enimy looks to the left and if its 2 he looks to the right.

```auto

//characters

int midashp= 30;

int enimyhp= 30;

PImage[] midas= new PImage[8];
PImage[] reversemidas= new PImage[8];
PImage[] daughter= new PImage[3];
PImage[] enemy= new PImage[3];
PImage[] reverseenemy= new PImage[8];
PImage battlescreen;

boolean showMidas1= true;

//coordinates
float midasx= 1;
float midasy= 1;

float daughterx= width;
float daughtery= height;

float enemyprevx;
float enemyx= width-(width/4);

//i's
int i=1;
int i2= 1;
int i3= 1;

//hpwidth
int hpwidth1= midashp*5.66666666667 ;
int hpwidth2= enimyhp*5.66666666667;

void setup() {
  size(600, 600);

  //load characters in
  midas[1] = loadImage("1.png");
  midas[2] = loadImage("2.png");
  midas[3] = loadImage("3.png");
  midas[4] = loadImage("4.png");
  midas[5] = loadImage("5.png");
  midas[6] = loadImage("6.png");
  midas[7] = loadImage("7.png");

  reversemidas[1] = loadImage("rev1.png");
  reversemidas[2] = loadImage("rev2.png");
  reversemidas[3] = loadImage("rev3.png");
  reversemidas[4] = loadImage("rev4.png");
  reversemidas[5] = loadImage("rev5.png");
  reversemidas[6] = loadImage("rev6.png");
  reversemidas[7] = loadImage("rev7.png");

  daughter[1] = loadImage("daughter.png");
  daughter[2] = loadImage("daughter gold.png");

  enemy[1]= loadImage("enemy1.png");
  enemy[2]= loadImage("revenimy.png");
	
	battlescreen=("battlescreen.png")
}
void draw() {
  background(0, 0, 0);
  tint(255, 255);
  //show and move the characters

  if (frameCount%120 == 0) {
    i3 = 1;
  }
  if (frameCount%120 == 60) {
    i3 = 2;
  }

  image(enemy[i3], enemyx, height-(height/4), 50, 80);

  if (dist(midasx, midasy, daughterx, daughtery) < 45) {
    i2=2;
  }

  image(daughter[i2], daughterx, daughtery, 40, 70);

  if (showMidas1==true&& ! keyPressed) {
    image(midas[1], midasx, midasy, 50, 80);
  } 
  if (keyPressed) {
    if (key == 'w') {
      midasy=midasy-10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 's') {
      midasy=midasy+10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 'a') {
      midasx=midasx-10;
      image(reversemidas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 'd') {
      midasx=midasx + 10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }

  if (i==7) {
    i=1;
  }

  i++;
}

void keyReleased() {
  showMidas1 = true;
}

```

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [September 15, 2021, 8:23pm UTC](https://discourse.processing.org/t/check-if-character-sees-other-character/32274/2 "2021-09-15T20:23:57Z")

</div>

Hey take a look at that:  
Time: 2:39 explanation

[![](https://img.youtube.com/vi/P_xJMH8VvAE/maxresdefault.jpg "5.1 Autonomous Steering Agents Introduction - The Nature of Code") ](https://www.youtube.com/watch?v=P_xJMH8VvAE)
