Esempio n. 1
0
 private void spawnCar(final float screenWidth, final float screenHeight) {
   lane = r.nextInt(6) + 1;
   final Sprite car = new Sprite(-300, 0, carTR, this.activity.getVertexBufferObjectManager());
   car.setRotation(180);
   MoveModifier moveModifier =
       new MoveModifier(
           4,
           lane * GameManager.lengthOfTile,
           lane * GameManager.lengthOfTile,
           -GameManager.lengthOfTile * 2,
           screenHeight + GameManager.lengthOfTile * 2) {
         @Override
         protected void onModifierFinished(IEntity pItem) {
           super.onModifierFinished(pItem);
           lane = r.nextInt(6) + 1;
           this.reset(
               4,
               lane * GameManager.lengthOfTile,
               lane * GameManager.lengthOfTile,
               -GameManager.lengthOfTile * 2,
               screenHeight + GameManager.lengthOfTile * 2);
         }
       };
   car.registerEntityModifier(moveModifier);
   menuScene.attachChild(car);
 }
Esempio n. 2
0
  public org.andengine.entity.scene.menu.MenuScene createScene() {
    float screenWidth = camera.getWidth();
    float screenHeight = camera.getHeight();
    menuScene = new org.andengine.entity.scene.menu.MenuScene(camera);

    // BACKGROUND SETUP
    map.loadMap(menuScene);
    // menuScene.attachChild(map.createScene(10));

    spawnCar(screenWidth, screenHeight);

    // BANNER/LOGO & banner animation
    final Sprite banner =
        new Sprite(
            (screenWidth - dodgecarsTR.getWidth()) / 2,
            (screenHeight / 7) / 2,
            dodgecarsTR,
            this.activity.getVertexBufferObjectManager());
    rotBan = false;
    scaBan = false;
    banner.registerEntityModifier(
        new ScaleModifier(scaleDuration, startScale, endScale) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            super.onModifierFinished(pItem);
            if (scaBan) {
              this.reset(scaleDuration, startScale, endScale, startScale, endScale);
              scaBan = !scaBan;
            } else {
              this.reset(scaleDuration, endScale, startScale, endScale, startScale);
              scaBan = !scaBan;
            }
          }
        });
    banner.registerEntityModifier(
        new RotationModifier(rotDuration, startRot, endRot) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            super.onModifierFinished(pItem);
            if (!rotBan) {
              this.reset(rotDuration, endRot, startRot);
              rotBan = !rotBan;
            } else {
              this.reset(rotDuration, startRot, endRot);
              rotBan = !rotBan;
            }
          }
        });

    // MENU ITEMS
    final IMenuItem buttonPlay =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(PLAY_BTN_ID, playTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    final IMenuItem buttonHighScore =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(
                HIGHSCORE_BTN_ID, highscoreTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    final IMenuItem buttonCredits =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(
                CREDITS_BTN_ID, creditsTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    buttonPlay.setPosition((screenWidth - playTR.getWidth()) / 2, screenHeight / 7 * 3);
    buttonHighScore.setPosition((screenWidth - highscoreTR.getWidth()) / 2, screenHeight / 7 * 4);
    buttonCredits.setPosition((screenWidth - creditsTR.getWidth()) / 2, screenHeight / 7 * 5);

    // Sound and Music on/off buttons
    soundOnBtn =
        new Sprite(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            soundsOnTR,
            this.activity.getVertexBufferObjectManager());
    soundOffBtn =
        new Sprite(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            soundsOffTR,
            this.activity.getVertexBufferObjectManager());
    musicOnBtn =
        new Sprite(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            musicOnTR,
            this.activity.getVertexBufferObjectManager());
    musicOffBtn =
        new Sprite(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            musicOffTR,
            this.activity.getVertexBufferObjectManager());

    menuScene.attachChild(banner);
    menuScene.addMenuItem(buttonPlay);
    menuScene.addMenuItem(buttonHighScore);
    menuScene.addMenuItem(buttonCredits);

    if (sounds.playMusic) {
      menuScene.attachChild(musicOffBtn);
      menuScene.attachChild(musicOnBtn);
      musicOffBtn.setVisible(false);
      musicOnBtn.setVisible(true);
    } else {
      menuScene.attachChild(musicOnBtn);
      menuScene.attachChild(musicOffBtn);
      musicOnBtn.setVisible(false);
      musicOffBtn.setVisible(true);
    }

    if (sounds.playSounds) {
      menuScene.attachChild(soundOffBtn);
      menuScene.attachChild(soundOnBtn);
      soundOffBtn.setVisible(false);
      soundOnBtn.setVisible(true);
    } else {
      menuScene.attachChild(soundOnBtn);
      menuScene.attachChild(soundOffBtn);
      soundOnBtn.setVisible(false);
      soundOffBtn.setVisible(true);
    }

    final Rectangle soundRec =
        new Rectangle(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            GameManager.lengthOfTile,
            GameManager.lengthOfTile,
            this.activity.getVertexBufferObjectManager()) {
          public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y) {
            if (touchEvent.isActionDown()) {
              if (sounds.playSounds) {
                sounds.setSoundsEnable(false);
                soundOnBtn.setVisible(false);
                soundOffBtn.setVisible(true);
              } else {
                sounds.setSoundsEnable(true);
                soundOffBtn.setVisible(false);
                soundOnBtn.setVisible(true);
              }
            }
            return true;
          };
        };
    final Rectangle musicRec =
        new Rectangle(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            GameManager.lengthOfTile,
            GameManager.lengthOfTile,
            this.activity.getVertexBufferObjectManager()) {
          public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y) {
            if (touchEvent.isActionDown()) {
              if (sounds.playMusic) {
                sounds.setMusicEnable(false);
                sounds.pauseMusic();
                musicOnBtn.setVisible(false);
                musicOffBtn.setVisible(true);
              } else {
                sounds.setMusicEnable(true);
                sounds.playMusic();
                musicOffBtn.setVisible(false);
                musicOnBtn.setVisible(true);
              }
            }
            return true;
          };
        };
    soundRec.setAlpha(255);
    musicRec.setAlpha(255);
    menuScene.registerTouchArea(soundRec);
    menuScene.registerTouchArea(musicRec);
    menuScene.attachChild(soundRec);
    menuScene.attachChild(musicRec);

    menuScene.setOnMenuItemClickListener(
        new IOnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClicked(
              org.andengine.entity.scene.menu.MenuScene pMenuScene,
              IMenuItem pMenuItem,
              float pMenuItemLocalX,
              float pMenuItemLocalY) {

            switch (pMenuItem.getID()) {
              case PLAY_BTN_ID:
                sounds.playCarStart();
                sceneManager.createGameScene();
                sceneManager.setCurrentSence(AllScenes.GAME);
                break;
              case HIGHSCORE_BTN_ID:
                sounds.playBlop();
                sceneManager.createHighScoreScene();
                sceneManager.setCurrentSence(AllScenes.HIGHSCORE);
                break;
              case CREDITS_BTN_ID:
                sounds.playBlop();
                sceneManager.createCreditScene();
                sceneManager.setCurrentSence(AllScenes.CREDITS);
                break;
            }

            return false;
          }
        });

    return menuScene;
  }
Esempio n. 3
0
  public org.andengine.entity.scene.menu.MenuScene createScene() {
    scene = new org.andengine.entity.scene.menu.MenuScene(camera);
    map.loadMap(scene);

    int padding = 50;

    final Sprite credits =
        new Sprite(
            (camera.getWidth() - creditsTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2,
            creditsTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite gameby =
        new Sprite(
            (camera.getWidth() - gamebyTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2 + creditsTR.getHeight() + padding * 2,
            gamebyTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite robin =
        new Sprite(
            (camera.getWidth() - robinTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + padding * 3,
            robinTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite musicby =
        new Sprite(
            (camera.getWidth() - musicbyTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + robinTR.getHeight()
                + padding * 5,
            musicbyTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite alex =
        new Sprite(
            (camera.getWidth() - alexTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + robinTR.getHeight()
                + musicbyTR.getHeight()
                + padding * 6,
            alexTR,
            this.activity.getVertexBufferObjectManager());

    scene.attachChild(gameby);
    scene.attachChild(alex);
    scene.attachChild(musicby);
    scene.attachChild(robin);

    final IMenuItem buttonHome =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(HOME_BTN_ID, homeTR, this.activity.getVertexBufferObjectManager()),
            1,
            1);
    buttonHome.setPosition(
        camera.getWidth() / 2 - homeTR.getWidth() / 2, camera.getHeight() - homeTR.getHeight() * 2);
    scene.addMenuItem(buttonHome);

    scene.setOnMenuItemClickListener(
        new IOnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClicked(
              org.andengine.entity.scene.menu.MenuScene pMenuScene,
              IMenuItem pMenuItem,
              float pMenuItemLocalX,
              float pMenuItemLocalY) {

            switch (pMenuItem.getID()) {
              case HOME_BTN_ID:
                sounds.playBlop();
                sceneManager.createMenuScene();
                sceneManager.setCurrentSence(AllScenes.MENU);
                break;
            }

            return false;
          }
        });

    scene.attachChild(credits);
    return scene;
  }