import processing.sound.*;

float previous;
float current;
float delay;
float mothX;
float mothY;
float lampX;
float lampY;
boolean run;
PImage moth;
PImage lamp;
SoundFile lampWav;
SoundFile ohNoWav;
SoundFile boopWav;

// the moth's name is George


void setup() {
  size(1000, 700);
  background(153, 204, 255);
  moth = loadImage("moth.png");
  lamp = loadImage("lamp.png");
  lampWav = new SoundFile(this, "lamp.wav");
  ohNoWav = new SoundFile(this, "ohno.wav");
  boopWav = new SoundFile(this, "boop.wav");
  boopWav.loop();
  
}

void draw() {
  background(153, 204, 255);
  
  if (mothX == lampX && mothY == lampY) {
    lampWav.play();
    delay(1019);
    delay(30);
    //ohNoWav.play();
    //delay(1463);
    lampX = int (random(0, 800));
    lampY = int (random(0, 400));
    scale(2);
    image (lamp, lampX, lampY);
  } else {
    image (lamp, lampX, lampY);
  }
  
// draw moth, check moth co-ordinates, change co-ordinates
  image (moth, mothX, mothY);

  if (mothX > lampX) {
    mothX --;
  }
  if (mothX < lampX) {
    mothX ++;
  }
  if (mothY > lampY) {
    mothY --;
  }
  if (mothY < lampY) {
    mothY ++;
  }
}