예제 #1
0
  public void loadResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    TA =
        new BuildableBitmapTextureAtlas(
            this.activity.getTextureManager(),
            1024,
            1024,
            BitmapTextureFormat.RGBA_4444,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    map.loadResources(TA);

    creditsTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(TA, activity, "menu/credits.png");
    homeTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(TA, activity, "home.png");
    gamebyTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            TA, this.activity, "credits/game by.png");
    zarokhanTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            TA, this.activity, "credits/zarokhan.png");
    robinTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            TA, this.activity, "credits/robin.png");
    musicbyTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            TA, this.activity, "credits/music by.png");
    alexTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            TA, this.activity, "credits/alexander.png");

    font =
        FontFactory.create(
            this.activity.getFontManager(),
            this.activity.getTextureManager(),
            256,
            256,
            Typeface.create(Typeface.DEFAULT, Typeface.NORMAL),
            GameManager.lengthOfTile);
    font.load();

    try {
      TA.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(1, 1, 0));
      TA.load();
    } catch (TextureAtlasBuilderException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  public void loadResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/menu/");

    menuTA =
        new BuildableBitmapTextureAtlas(
            this.activity.getTextureManager(),
            1024,
            1024,
            BitmapTextureFormat.RGBA_4444,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    dodgecarsTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTA, this.activity, "dodgethecars.png");
    playTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTA, this.activity, "play.png");
    highscoreTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTA, this.activity, "highscore.png");
    creditsTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTA, this.activity, "credits.png");

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    mapTA =
        new BuildableBitmapTextureAtlas(
            this.activity.getTextureManager(),
            1024,
            1024,
            BitmapTextureFormat.RGBA_4444,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    carTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(mapTA, this.activity, "player.png");
    map.loadResources(mapTA);

    soundsOnTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mapTA, this.activity, "sound on.png");
    soundsOffTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mapTA, this.activity, "sound off.png");
    musicOnTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mapTA, this.activity, "music on.png");
    musicOffTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mapTA, this.activity, "music off.png");

    font =
        FontFactory.create(
            this.activity.getFontManager(),
            this.activity.getTextureManager(),
            256,
            256,
            Typeface.create(Typeface.DEFAULT, Typeface.NORMAL),
            32 * 3f);
    font.load();

    sounds.loadResources();

    try {
      menuTA.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
      menuTA.load();
      mapTA.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 1));
      mapTA.load();
    } catch (TextureAtlasBuilderException e) {
      e.printStackTrace();
    }
  }
예제 #3
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;
  }
예제 #4
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;
  }