Ejemplo n.º 1
0
  public boolean areColliding() {
    circle.setPosition(circle.getX(), circle.getY() + squareSpeed);
    rectangle.setPosition(rectangle.getX(), rectangle.getY() - circleSpeed);

    if (circle.getY() + circle.getHeight() > C.SCREEN_HEIGHT || rectangle.getY() < 0) {
      C.SCENE.detachChild(circle);
      C.SCENE.detachChild(rectangle);
      createShapes();
    }

    if (rectangle.collidesWith(circle)) {
      // if(PixelPerfectCollisionChecker.checkCollision(circle, null, square, null)) {
      // square.setColor(1, 0, 0);
      // circle.setColor(1, 0, 0);
    } else {
      // square.setColor(0, 1, 0);
      // circle.setColor(0, 1, 0);
    }

    return rectangle.collidesWith(circle);
  }
Ejemplo n.º 2
0
 private void createAim() {
   aim =
       new Sprite(0, 0, resourcesManager.aimTextureRegion, vbom) {
         @Override
         protected void preDraw(GLState pGLState, Camera pCamera) {
           super.preDraw(pGLState, pCamera);
           pGLState.enableDither();
         }
       };
   aim.setPosition(camera.getXMin() + camera.getWidth() / 2, camera.getHeight() / 2);
   aim.setSize(40, 40);
   getChildByIndex(1).attachChild(aim);
 }
  @Override
  public void tact(long now, long period) {
    final float nextStep = MathUtils.distance(mPoint.x, mPoint.y, mNextPoint.x, mNextPoint.y);
    if (nextStep > 10) {
      float distance = (float) period / 1000 * mSpeed;
      float m = nextStep - distance;
      float x = (m * mPoint.x + distance * mNextPoint.x) / nextStep;
      float y = (m * mPoint.y + distance * mNextPoint.y) / nextStep;

      mPoint.x = x;
      mPoint.y = y;
    }

    mSprite.setPosition(mPoint.x - mPointOffset.x, mPoint.y - mPointOffset.y);
    mSpriteShadow.setPosition(mSprite.getX() + mPointShadow.x, mSprite.getY() + mPointShadow.y);
  }
Ejemplo n.º 4
0
  @Override
  public void createScene() {

    splash =
        new Sprite(0, 0, resourcesManager.splashRegion, vbom) {

          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }
        };

    splash.setScale(1.5f);
    splash.setPosition(35, 200);
    // attachChild(splash);
  }
Ejemplo n.º 5
0
    /*
     * Attach the LevelTile's text to itself based on whether it's locked or
     * not. If not, then the level number will be displayed on the level
     * tile.
     */
    public void attachStar() {

      /* Determine the tile's string based on whether it's locked or not*/
      if (this.mIsLocked) {
        mStar.setCurrentTileIndex(0);

      } else {
        mStar.setCurrentTileIndex(mNumStars);
      }

      /* Setup the text position to be placed in the center-bottom of the tile */
      final float starPositionX = LevelSelector.this.TILE_DIMENSION / 6 + 5;
      final float starPositionY = LevelSelector.this.TILE_DIMENSION - 15;

      /* Attach the mStar to the LevelTile */
      StarSprite =
          new Sprite(0, 0, mStar, LevelSelector.this.mEngine.getVertexBufferObjectManager());
      this.attachChild(StarSprite);
      StarSprite.setPosition(starPositionX, starPositionY + 15);
    }
Ejemplo n.º 6
0
  @Override
  public void crearEscena() {
    // Creamos el sprite de manera óptima
    spriteFondo =
        new Sprite(0, 0, admRecursos.regionSplash, admRecursos.vbom) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }
        };
    // Configuración de la imagen
    spriteFondo.setPosition(ControlJuego.ANCHO_CAMARA / 2, ControlJuego.ALTO_CAMARA / 2);
    spriteFondo.setScale(0.7f);

    // Crea el fondo de la pantalla
    SpriteBackground fondo = new SpriteBackground(0, 0, 0.60f, spriteFondo);
    setBackground(fondo);
    setBackgroundEnabled(true);
  }
Ejemplo n.º 7
0
  // Creer la scene affiche e l'ecran.
  private void initSplashScene() {
    mCurrentScene = new Scene();
    // Sprite qui va contenir le logo
    Sprite splash =
        new Sprite(0, 0, manager.mSplashLogo, mEngine.getVertexBufferObjectManager()) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }
        };
    splash.setScale(0.8f);
    // Ajoute le sprite splash e la scene.
    splash.setPosition(
        (mCamera.getWidth() - splash.getWidth()) * 0.5f,
        (mCamera.getHeight() - splash.getHeight() - 150f) * 0.5f);
    mCurrentScene.attachChild(splash);

    // Attache le titre
    mCurrentScene.attachChild(mTitle1);
    mCurrentScene.attachChild(mTitle2);
  }
  @Override
  public void onLoadScene() {
    // mCurrentBoss = 1;
    // SFXManager.getInstance().loadSound("t_ko", ResourceManager.getActivity().getSoundManager(),
    // ResourceManager.getActivity());
    System.out.println("mCurrentBoss --> " + mCurrentBoss);
    Sprite themeBGSprite = new Sprite(0f, 0f, ResourceManager.themeBG, mVertexBufferObjectManager);
    // themeBGSprite.setScale(ResourceManager.getInstance().cameraHeight /
    // ResourceManager.themeBG.getHeight());
    themeBGSprite.setSize(mCameraWidth, mCameraHeight);
    themeBGSprite.setPosition(mCameraWidth / 2f, mCameraHeight / 2f);
    themeBGSprite.setZIndex(-90);
    attachChild(themeBGSprite);

    if (mScrollDetector == null) {
      mScrollDetector = new SurfaceScrollDetector(this);
    }
    mScrollDetector.setTriggerScrollMinimumDistance(10f);
    mBossSlider = getScensSlider();
    attachChild(mBossSlider);
    if (isKO) {
      themeRInitX = themeRInitX - mCameraWidth * (mCurrentBoss - 1);
      // mBossSlider.registerEntityModifier(new MoveXModifier(0.3F, mBossSlider.getX(),
      // themeRInitX));
      mBossSlider.setX(themeRInitX);
    }

    // 后退按钮
    ButtonSprite backBS =
        new ButtonSprite(0f, 0f, ResourceManager.backTR, mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, backBS);
    backBS.setPosition(10f + backBS.getWidth() / 2f, mCameraHeight - 10f - backBS.getHeight() / 2f);
    attachChild(backBS);
    backBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(ThemeScene.getInstance());
          }
        });
    registerTouchArea(backBS);

    // 主页按钮
    ButtonSprite homeBS =
        new ButtonSprite(0f, 0f, ResourceManager.homeTR, mVertexBufferObjectManager);
    homeBS.setSize(backBS.getWidth(), backBS.getHeight());
    homeBS.setPosition(mCameraWidth - 10f - homeBS.getWidth() / 2f, backBS.getY());
    attachChild(homeBS);
    homeBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(MainMenuScene.getInstance());
          }
        });
    registerTouchArea(homeBS);

    // 向左箭头
    ButtonSprite arrowLeftSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(0), mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, arrowLeftSprite);
    arrowLeftSprite.setPosition(backBS.getX(), mCameraHeight / 2f);
    attachChild(arrowLeftSprite);
    arrowLeftSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == 1) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), mBossSlider.getWidth() / 2f));
            } else {
              mCurrentBoss--;
              themeRInitX = themeRInitX + mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowLeftSprite);
    // 向右箭头
    ButtonSprite arrowRightSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(1), mVertexBufferObjectManager);
    arrowRightSprite.setSize(arrowLeftSprite.getWidth(), arrowLeftSprite.getHeight());
    arrowRightSprite.setPosition(homeBS.getX(), mCameraHeight / 2f);
    attachChild(arrowRightSprite);
    arrowRightSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == bossPics.length) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(
                      0.3F,
                      mBossSlider.getX(),
                      mBossSlider.getWidth() / 2f - mCameraWidth * (bossPics.length - 1)));
            } else {
              mCurrentBoss++;
              themeRInitX = themeRInitX - mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowRightSprite);
  }
  /**
   * BOSS滑块
   *
   * @author zuowhat 2013-11-25
   * @since 1.0
   */
  private Rectangle getScensSlider() {
    bossPics = new AnimatedButtonSprite[ResourceManager.mxdBoss_TTRArray.length];
    Sprite[] bossBlackBG = new Sprite[bossPics.length];
    // Sprite[] bossInfo = new Sprite[bossPics.length];
    float themeRWidth = mCameraWidth * bossPics.length;
    themeRInitX = themeRWidth / 2f;
    Rectangle themeR =
        new Rectangle(
            themeRWidth / 2f,
            mCameraHeight / 2f,
            themeRWidth,
            mCameraHeight * (2f / 3f),
            mVertexBufferObjectManager);
    themeR.setAlpha(0f);
    int themeSceneOneBossTotal =
        BangYouScreenActivity.getIntFromSharedPreferences(DataConstant.SHARED_PREFS_THEME_MXD);
    for (int i = 0; i < ResourceManager.mxdBoss_TTRArray.length; i++) {
      if (i < themeSceneOneBossTotal) {
        if (isKO) {
          if (i != (mCurrentBoss - 1)) {
            // KO标志
            Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
            EntityUtil.setSize("width", 1f / 4f, s);
            s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
            themeR.attachChild(s);
          } else {
            // KO动画
            Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
            EntityUtil.setSize("width", 1f / 4f, s);
            s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
            themeR.attachChild(s);
            ScaleAtModifier highestPicScale =
                new ScaleAtModifier(0.5f, 25f, 1f, 0.5f, 0.5f); // 实体缩放
            FadeInModifier highestPicFadeIn = new FadeInModifier(0.5f); // 在0.5秒内改变透明度由0f变为1f
            ParallelEntityModifier highestPicParalle =
                new ParallelEntityModifier(
                    new IEntityModifierListener() {

                      @Override
                      public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                        SFXManager.getInstance().playSound("t_ko");
                      }

                      @Override
                      public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                        // TODO Auto-generated method stub

                      }
                    },
                    highestPicScale,
                    highestPicFadeIn); // 同时执行修饰符
            s.registerEntityModifier(highestPicParalle);
          }
        } else {
          // KO标志
          Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
          EntityUtil.setSize("width", 1f / 4f, s);
          s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
          themeR.attachChild(s);
        }
      }
      if (ResourceManager.mxdBoss_TTRArray[i] != null) {

        // BOSS动画
        bossPics[i] =
            new AnimatedButtonSprite(
                0f, 0f, ResourceManager.mxdBoss_TTRArray[i], mVertexBufferObjectManager);
        EntityUtil.setSize("height", 1f / 2f, bossPics[i]);
        // BOSS简介
        // bossInfo[i] = new Sprite(0f, 0f,ResourceManager.mxdBoss_InfoTRArray[i],
        // mVertexBufferObjectManager);
        // EntityUtil.setSize("height", 1f/2f, bossInfo[i]);
        if (i == 0) {
          bossPics[i].setPosition(mCameraWidth / 4f, themeR.getHeight() / 2f);
          // bossInfo[i].setPosition(3f*mCameraWidth/4f, themeR.getHeight()/2f);
        }
        if (i == 7) {
          long[] frameDur = new long[2];
          Arrays.fill(frameDur, 300);
          bossPics[i].animate(frameDur, 0, 1, true);
        } else {
          bossPics[i].animate(100, true);
        }

        bossPics[i].setOnClickListenerABS(
            new OnClickListenerABS() {
              @Override
              public void onClick(
                  AnimatedButtonSprite pButtonSprite,
                  float pTouchAreaLocalX,
                  float pTouchAreaLocalY) {
                SFXManager.getInstance().playSound("a_click");
                SFXManager.getInstance().stopMusic();
                SceneManager.getInstance()
                    .showScene(
                        new GameLevel(
                            DataConstant.getMXDBoss(mCurrentBoss), DataConstant.getPlayerModel()));
              }
            });
        // BOSS图片和简介的位置
        if (i > 0) {
          bossPics[i].setPosition(mCameraWidth + bossPics[i - 1].getX(), themeR.getHeight() / 2f);
          // bossInfo[i].setPosition(mCameraWidth+bossInfo[i-1].getX(), themeR.getHeight()/2f);
        }
        themeR.attachChild(bossPics[i]);
        registerTouchArea(bossPics[i]);
        // themeR.attachChild(bossInfo[i]);
      } else {
        bossBlackBG[i] =
            new Sprite(
                0f,
                0f,
                ResourceManager.bossBlackBG.getTextureRegion(i),
                mVertexBufferObjectManager);
        EntityUtil.setSize("height", 1f / 2f, bossBlackBG[i]);
        bossBlackBG[i].setPosition(mCameraWidth * (i + 1f / 4f), themeR.getHeight() / 2f);

        switch (i) {
          case 0:
            break;

          case 1:
            break;
        }
        themeR.attachChild(bossBlackBG[i]);
      }
    }

    return themeR;
  }
Ejemplo n.º 10
0
  private void createHUD() {
    minigameHUD = new HUD();

    // Textures
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    HUDTextureAtlas =
        new BitmapTextureAtlas(
            ResourcesManager.getInstance().activity.getTextureManager(), 256, 256);

    blueHeartTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            HUDTextureAtlas, ResourcesManager.getInstance().activity, "heartBlue.png", 0, 0);
    greenHeartTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            HUDTextureAtlas, ResourcesManager.getInstance().activity, "heartGreen.png", 50, 0);
    yellowHeartTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            HUDTextureAtlas, ResourcesManager.getInstance().activity, "heartYellow.png", 0, 50);
    redHeartTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            HUDTextureAtlas, ResourcesManager.getInstance().activity, "heartRed.png", 50, 50);
    timerTR =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            HUDTextureAtlas, ResourcesManager.getInstance().activity, "timer.png", 110, 110);

    timerSprite = new Sprite(0, 0, timerTR, vbom);
    redHeartSprite = new Sprite(0, 0, redHeartTR, vbom);
    yellowHeartSprite = new Sprite(0, 0, yellowHeartTR, vbom);
    greenHeartSprite = new Sprite(0, 0, greenHeartTR, vbom);
    blueHeartSprite = new Sprite(0, 0, blueHeartTR, vbom);

    timerSprite.setPosition(timerTR.getWidth() / 2, camera.getHeight() - timerTR.getHeight());

    if (PlayerManager.getInstance().player.getPlayerName().equalsIgnoreCase("Player 1")) {
      redHeartSprite.setPosition(
          2 + redHeartTR.getWidth() / 2, timerSprite.getY() - redHeartTR.getHeight() - 5);
      yellowHeartSprite.setPosition(
          camera.getWidth() - (yellowHeartTR.getWidth() / 2) - 2,
          camera.getHeight() - (yellowHeartTR.getHeight() / 2) - 2);
    } else {
      redHeartSprite.setPosition(
          camera.getWidth() - (yellowHeartTR.getWidth() / 2) - 2,
          camera.getHeight() - (yellowHeartTR.getHeight() / 2) - 2);
      yellowHeartSprite.setPosition(
          2 + redHeartTR.getWidth() / 2, timerSprite.getY() - redHeartTR.getHeight() - 5);
    }

    greenHeartSprite.setPosition(
        yellowHeartSprite.getX() - greenHeartTR.getWidth() - 5, yellowHeartSprite.getY());
    blueHeartSprite.setPosition(
        greenHeartSprite.getX() - blueHeartTR.getWidth() - 5, greenHeartSprite.getY());

    // Timer
    timeLeft = MinigameManager.TIMER_SECONDS;
    timerText =
        new Text(
            0, 0, resourcesManager.font, "0123456789", new TextOptions(HorizontalAlign.LEFT), vbom);
    timerText.setText(timeLeft + "");
    timerText.setPosition(50, camera.getHeight() - timerText.getHeight() / 2);

    // Player lives
    p1LivesLeft = 10;
    p2LivesLeft = 10;
    p3LivesLeft = 10;
    p4LivesLeft = 10;

    p1LivesText =
        new Text(
            0,
            0,
            resourcesManager.p1LivesFont,
            "0123456789",
            new TextOptions(HorizontalAlign.LEFT),
            vbom);
    p2LivesText =
        new Text(
            0,
            0,
            resourcesManager.p1LivesFont,
            "0123456789",
            new TextOptions(HorizontalAlign.LEFT),
            vbom);
    p3LivesText =
        new Text(
            0,
            0,
            resourcesManager.p1LivesFont,
            "0123456789",
            new TextOptions(HorizontalAlign.LEFT),
            vbom);
    p4LivesText =
        new Text(
            0,
            0,
            resourcesManager.p1LivesFont,
            "0123456789",
            new TextOptions(HorizontalAlign.LEFT),
            vbom);

    p1LivesText.setPosition(redHeartSprite.getX(), redHeartSprite.getY());
    p2LivesText.setPosition(blueHeartSprite.getX(), blueHeartSprite.getY());
    p3LivesText.setPosition(greenHeartSprite.getX(), greenHeartSprite.getY());
    p4LivesText.setPosition(yellowHeartSprite.getX(), yellowHeartSprite.getY());

    p1LivesText.setText(PlayerManager.getInstance().player1.getPlayerHearts() + "");

    // p3LivesText.setText(p3LivesLeft + "");
    // p4LivesText.setText(p4LivesLeft + "");

    // Attach
    HUDTextureAtlas.load();
    // minigameHUD.attachChild(blueHeartSprite);
    minigameHUD.attachChild(redHeartSprite);
    // minigameHUD.attachChild(greenHeartSprite);

    minigameHUD.attachChild(timerSprite);

    minigameHUD.attachChild(timerText);
    minigameHUD.attachChild(p1LivesText);
    // minigameHUD.attachChild(p2LivesText);
    // minigameHUD.attachChild(p3LivesText);

    if (PlayerManager.getInstance().player2 != null) {
      p4LivesText.setText(PlayerManager.getInstance().player2.getPlayerHearts() + "");
      minigameHUD.attachChild(yellowHeartSprite);
      minigameHUD.attachChild(p4LivesText);
    }

    camera.setHUD(minigameHUD);
  }
 private void setToCenter(Sprite mSprite) {
   mSprite.setPosition(
       Config.Camera.WIDTH / 2 - mSprite.getWidth() / 2,
       Config.Camera.HEIGHT / 2 - mSprite.getHeight() / 2);
 }
Ejemplo n.º 12
0
 public void setX(float x) {
   this.x = x;
   sprite.setPosition(x, sprite.getY());
 }