import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import processing.sound.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class moth_lamp extends PApplet {



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


public void setup() {
  
  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();
  
}

public void draw() {
  background(153, 204, 255);
  
  if (mothX == lampX && mothY == lampY) {
    lampWav.play();
    delay(1019);
    delay(30);
    //ohNoWav.play();
    //delay(1463);
    lampX = PApplet.parseInt (random(0, 800));
    lampY = PApplet.parseInt (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 ++;
  }
}
  public void settings() {  size(1000, 700); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "--present", "--window-color=#666666", "--stop-color=#cccccc", "moth_lamp" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
