Ejemplo n.º 1
0
  private void initializeGame() {

    if (gameEngine == null) {
      Log.d(TAG, "Attempting to Load Level");
      gameEventManager = new GameEventManager();
      gameEventManager.addObserver(this);

      gameEngine =
          new GameEngine(drawingView.getWidth(), drawingView.getHeight(), gameEventManager);

      gameEngine.loadLevel(getResources().openRawResource(levelResourceId));

      drawGameRate = gameEngine.getLevelConfig().getDrawScreenRate();
      drawingView.intializeDrawView(gameEngine, gameEventManager);

      titleText = gameEngine.getLevelConfig().getLevelTitle() + " - Points: ";
      titleView.setText(titleText);
    }
  }
Ejemplo n.º 2
0
  public void pauseClick(View v) {

    if (gameEngine != null && gameEngine.hasBeenInitialized()) {
      if (gameEventManager.getGameState() == GAME_STATE.PLAYING) {
        Log.d(TAG, "un pausing Game");
        pauseButton.setText("Resume");
        gameEventManager.pauseGame();
      } else if (gameEventManager.getGameState() == GAME_STATE.PAUSED) {
        Log.d(TAG, "Pausing Game");
        pauseButton.setText("Pause");
        gameEventManager.unPauseGame();
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void update(Observable observable, Object data) {
    if (stepThread == null || timer == null || timerCancelled) {
      stepThread = new StepThread();
      timer = new Timer();
      timerCancelled = false;
    }

    if (data instanceof GAME_EVENT) {
      GAME_EVENT newGameState = (GAME_EVENT) data;

      if (newGameState == GAME_EVENT.STARTED) {
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
        timer.schedule(stepThread, 0, gameEngine.getStepRateMili());
        playBackgroundMusic();

      } else if (newGameState == GAME_EVENT.WIN) {
        stopStepThread();
        stopBackgroundMusic();
        drawingView.invalidate();
      } else if (newGameState == GAME_EVENT.LOSE) {
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_LOSE_DURATION);
        stopStepThread();
        stopBackgroundMusic();
        drawingView.invalidate();
      } else if (newGameState == GAME_EVENT.ADD_POINT) {
        addPointsToPointTextView();
      } else if (newGameState == GAME_EVENT.PAUSE) {
        // Invalidate to draw the PAUSED string
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
        timerPaused = true;
        stopBackgroundMusic();
        drawingView.invalidate();
      } else if (newGameState == GAME_EVENT.UNPAUSE) {
        playBackgroundMusic();
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
        timerPaused = false;
      } else if (newGameState == GAME_EVENT.BALL_LOST) {
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
      } else if (newGameState == GAME_EVENT.BALL_LOST) {
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
      } else if (newGameState == GAME_EVENT.BALL_EXPLOAD) {
        playSound(R.raw.explosion);
      } else if (newGameState == GAME_EVENT.EXIT) {
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VIBRATE_DURATION);
        this.finish();
      }
    }
  }
Ejemplo n.º 4
0
 public void onSensorChanged(SensorEvent event) {
   if (gameEngine != null && gameEngine.hasBeenInitialized()) {
     float yValue = event.values[1];
     gameEngine.setBallXVelocity(yValue);
   }
 }