Ejemplo n.º 1
0
  public Game() {
    rootObject = null;
    thread = null;

    addMouseListener(Input.getInstance());
    addMouseMotionListener(Input.getInstance());

    fade = 0;

    setRoot(new TitleMenu());
  }
Ejemplo n.º 2
0
  public void loadGame() {
    System.out.println("loading");
    FileInputStream finput = null;
    try {
      finput = new FileInputStream("save");

      ObjectInputStream in = new ObjectInputStream(finput);

      GameObject newRoot = (GameObject) in.readObject();

      @SuppressWarnings("unchecked")
      ArrayList<Button> buttons = (ArrayList<Button>) in.readObject();
      Input.getInstance().setButtons(buttons);

      transitionTo(newRoot);

      in.close();
      finput.close();

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  public void transitionTo(GameObject o) {
    nextRoot = o;
    Input.getInstance().setEnabled(false);

    FadeToAction fadeDown =
        new FadeToAction(
            this,
            1.0,
            FADE_TIME,
            new Observer() {

              public void notified(Observable sender) {

                setRoot(nextRoot);

                FadeToAction fadeUp = new FadeToAction(Game.this, 0, FADE_TIME, null);
                rootObject.addChild(fadeUp);
                fadeUp.start();

                Input.getInstance().setEnabled(true);
              }
            });

    rootObject.addChild(fadeDown);
    fadeDown.start();
  }
Ejemplo n.º 4
0
  private void setRoot(GameObject o) {
    if (rootObject != null) {
      rootObject.destroy();
    }

    if (DEBUG) {
      Input.getInstance().printNumButtons();
    }

    rootObject = o;
  }
Ejemplo n.º 5
0
  public void saveGame() {
    System.out.println("saving");
    FileOutputStream foutput = null;
    try {
      foutput = new FileOutputStream("save");
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      ObjectOutputStream out = new ObjectOutputStream(foutput);

      out.writeObject(rootObject);
      out.writeObject(Input.getInstance().getButtons());

      out.close();
      foutput.close();

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
 public void update() {
   Input.getInstance().update();
   rootObject.updateSelfAndChildren();
 }