Ejemplo n.º 1
0
  public GameEngine(Activity activity) {
    super((Context) activity);
    this.parentActivity = activity;
    this.context = (Context) activity;
    this.setFocusableInTouchMode(true);
    this.setOnKeyListener(this);

    _renderer = new GameRenderer(context);

    setRenderer(_renderer);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    // rejestracja listernerów
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    Sensor sensor;
    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
    GameEventBus.getInstance()
        .attachToEventBus(EngineEventListener.class, new EngineEventHandler(this));

    this.generateLists();

    player = new AsyncPlayer("GameEngine->AudioPlayer");

    LvLBuilder lvLBuilder = new LvLBuilder(lvlList, context);
    lvlIter = lvLBuilder.iterator();
    if (lvlIter.hasNext()) {

      Level lvl = (Level) lvlIter.next();
      currentLvLName = lvl.getName();
      List<Stage> stages = lvl.getStages();

      stagesIter = stages.iterator();
      if (stages != null && stagesIter.hasNext()) {
        Stage stage = (Stage) stagesIter.next();
        currentStageName = stage.getName();
        _renderer.setAlienObjectsList(stage.getShips());
      }
      Log.d("Current Level: ", currentLvLName);
      Log.d("Current Stage: ", currentStageName);
    }
    this.refresh = new Refresher(this);
    ((Thread) refresh).start();
    this.audio = new AudioService2(context);
    ((Thread) audio).start();
  }
Ejemplo n.º 2
0
  /**
   * Implementacja obsługi zdarzeń które muszą zostać wykonane przez silnik
   *
   * @see
   *     com.mmm.ztp.event.engineEvents.EngineEventListener#onEngineEvent(com.mmm.ztp.event.engineEvents.EngineEventObject)
   */
  @Override
  public void onEngineEvent(EngineEventObject obj) {
    if (obj.getType() == EngineEventObject.TYPE_NEXT_LEVEL) {
      Intent menu = new Intent(context, LevelMenu.class);

      if (stagesIter.hasNext()) {
        this.renderPause();
        Stage stage = (Stage) stagesIter.next();
        currentStageName = stage.getName();
        _renderer.setAlienObjectsList(stage.getShips());

        Log.d("Current Level: ", currentLvLName);
        Log.d("Current Stage: ", currentStageName);

        this.parentActivity.runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                Toast.makeText(
                        context,
                        "Level: " + currentLvLName + " Stage:" + currentStageName,
                        Toast.LENGTH_SHORT)
                    .show();
              }
            });
        this.renderResume();
      } else if (lvlIter.hasNext()) {
        this.renderPause();
        GameEventBus.getInstance()
            .fireEvent(
                AudioEventListener.class,
                new AudioEventObject(AudioEventObject.TYPE_NEXT_LVL, null));

        Level lvl = (Level) lvlIter.next();
        currentLvLName = lvl.getName();
        List<Stage> stages = lvl.getStages();
        stagesIter = stages.iterator();

        if (stages != null && stagesIter.hasNext()) {
          Stage stage = (Stage) stagesIter.next();
          currentStageName = stage.getName();
          _renderer.setAlienObjectsList(stage.getShips());
          Log.d("Current Level: ", currentLvLName);
          Log.d("Current Stage: ", currentStageName);
        }
        menu.putExtra("level", currentLvLName);
        menu.putExtra("stage", currentStageName);
        context.startActivity(menu);
        this.renderResume();
      } else {
        this.renderPause();
        GameEventBus.getInstance()
            .fireEvent(
                EngineEventListener.class,
                new EngineEventObject(EngineEventObject.TYPE_GAMEOVER, null));
      }
    }
    if (obj.getType() == EngineEventObject.TYPE_GAMEOVER) {
      Intent finish = new Intent(context, GameOver.class);
      context.startActivity(finish);
    }
  }