PushPushGame.java :  » Game » galatichero » net » narusas » game » pushpush » ui » Java Open Source

Java Open Source » Game » galatichero 
galatichero » net » narusas » game » pushpush » ui » PushPushGame.java
package net.narusas.game.pushpush.ui;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.io.IOException;

import net.narusas.game.pushpush.Map;
import net.narusas.game.pushpush.MapLoader;

import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;

public class PushPushGame extends Game {
  Map map;

  int stage = 1;

  ImageManager imageManager;

  private Scene scene;

  public int life = 3;

  @Override
  public void initResources() {
    imageManager = new ImageManager(this);
    loadStage();
    setFPS(60);
    scene = new TitleScene();
  }

  boolean loadStage() {
    MapLoader loader = new MapLoader();
    map = null;
    try {
      map = loader.load("LEVEL" + stage + ".txt");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return map != null;
  }

  @Override
  public void render(Graphics2D g) {
    scene.render(this, map, g);
  }

  @Override
  public void update(long elapsedTime) {
    if (scene.isSceneOver()) {
      scene = nextScene();
    }

    scene.update(this, map, elapsedTime);
  }

  private Scene nextScene() {
    if (scene == null) {
      System.out.println("TitleScene");
      return new TitleScene();
    }

    if (scene instanceof GameOverScene) {
      if (life > 0) {
        System.out.println("PlayingScene");
        return new PlayingScene();
      }
      life = 3;
      System.out.println("TitleScene");
      return new TitleScene();

    }
    if (scene instanceof TitleScene) {
      System.out.println("PlayingScene");
      return new PlayingScene();
    }
    if (scene instanceof PlayingScene) {
      PlayingScene s = (PlayingScene) scene;
      if (s.isGameClear()) {
        stage++;
        if (loadStage()) {
          System.out.println("StageClearScene");
          return new StageClearScene();

        }
        System.out.println("GameClearScene");
        return new GameClearScene();
      }

      return new GameOverScene();
    }
    if (scene instanceof StageClearScene) {
      return new PlayingScene();
    }

    return new TitleScene();
  }

  public static void main(String[] args) {
    GameLoader loader = new GameLoader();
    loader.setup(new PushPushGame(), new Dimension(800, 600), false);
    loader.start();
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.