import java.applet.*;
import java.awt.*;
import Raster;
import Sprite;
import AnimatedSprite;
import Playfield;

public class GaseousEarth extends Applet implements Runnable {
  Playfield girl;
  Sprite teapot1, teapot2;
  AnimatedSprite earth1, earth2;
  Image output;
  Thread animate;

  public void init(){
    girl = new Playfield(getImage(getDocumentBase(), "girl.jpg"), 4);
    // instantiate sprites here - we're almost done! 
    teapot1 = new Sprite(getImage(getDocumentBase(), "tpicon.gif"), 100, 100, 1, 2);
    girl.addSprite(0, teapot1);
    teapot2 = new Sprite(getImage(getDocumentBase(), "tpicon.gif"), 150, 150, 1, 1);
    girl.addSprite(1, teapot2);
    earth1 = new AnimatedSprite(getImage(getDocumentBase(), "WrldAni.gif"), 12, 100, 150, 1, -1);
    //earth1.x = 100;
    //earth1.y = 150;
    earth1.addTrack();
    earth1.addState(0, 0, 1);
    earth1.addState(0, 1, 1);
    earth1.addState(0, 2, 1);
    earth1.addState(0, 3, 1);
    earth1.addState(0, 4, 1);
    earth1.addState(0, 5, 1);
    earth1.addState(0, 6, 1);
    earth1.addState(0, 7, 1);
    earth1.addState(0, 8, 1);
    earth1.addState(0, 9, 1);
    earth1.addState(0, 10, 1);
    earth1.addState(0, 11, 1);
    earth1.setTrack(0);
    girl.addSprite(2, earth1);
    earth2 = new AnimatedSprite(getImage(getDocumentBase(), "WrldAni.gif"), 12, 300, 300, 1, 3);
    earth2.addTrack();
    earth2.addState(0, 0, 2);
    earth2.addState(0, 11, 2);
    earth2.addState(0, 10, 2);
    earth2.addState(0, 9, 2);
    earth2.addState(0, 8, 2);
    earth2.addState(0, 7, 2);
    earth2.addState(0, 6, 2);
    earth2.addState(0, 5, 2);
    earth2.addState(0, 4, 2);
    earth2.addState(0, 3, 2);
    earth2.addState(0, 2, 2);
    earth2.addState(0, 1, 2);
    earth2.setTrack(0);
    girl.addSprite(3, earth2);


    render();


  }
  public void start() {
    animate = new Thread(this);
    animate.start();
  }

  public void stop() {
    animate = null;
  }

  public void run() {
    while (true){
      try {
	animate.sleep(100);
      } catch(InterruptedException e) {
      }
      render();
    }
  }
  public void render(){
    //System.out.println("Rendering");
    girl.Step();
    girl.Draw();
    output = girl.toImage();
    repaint();
  }

  public void update(Graphics g)
  {
    paint(g);
  }

  public void paint(Graphics g)
  { 
    g.drawImage(output, 0, 0, this);
  }

  public boolean mouseUp(Event e, int x, int y){
    //System.out.println("Mouse click");
    girl.MouseThis(x,y);
    repaint();
    return true;
  }
}
  
