private Rectangle makeColoredRectangle(
     final float pX, final float pY, final float pRed, final float pGreen, final float pBlue) {
   final Rectangle coloredRect =
       new Rectangle(pX, pY, 180, 180, this.getVertexBufferObjectManager());
   coloredRect.setColor(pRed, pGreen, pBlue);
   return coloredRect;
 }
示例#2
0
  public LightVisual() {
    mBackgroundRectangle =
        new Rectangle(-W * .5f, -H * .5f, W, H, ResourcesManager.getInstance().vbom);
    mBackgroundRectangle.setScaleX(0.0f);
    mBackgroundRectangle.setColor(0.6f, 1.0f, 1.0f, .3f);

    this.attachChild(mBackgroundRectangle);
  }
示例#3
0
  private void rectangle(int b) {

    if (b > 50) one.detachSelf();

    if (b > 75) two.detachSelf();

    if (b > 100) three.detachSelf();

    if (b > 125) four.detachSelf();

    if (b > 150) five.detachSelf();
  }
  @Override
  public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    this.mScene = new Scene();

    this.mScene.setOnAreaTouchTraversalFrontToBack();

    Rectangle easyRect =
        new Rectangle(
            FIRST_SPACE,
            FIRST_SPACE + TOP_BORDER,
            CAMERA_WIDTH * (1 - (2 * BORDER_SIZE)),
            (CAMERA_WIDTH * (1 - (2 * BORDER_SIZE))),
            this.getVertexBufferObjectManager());
    easyRect.setColor(1, 1, 1);

    this.mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

    mScene.attachChild(easyRect);

    ;
    float pos_at = FIRST_SPACE;
    for (int i = 0; i <= NUM_ROWSCOLS; i++) {
      Line boardLineVert =
          new Line(
              pos_at,
              FIRST_SPACE + TOP_BORDER,
              pos_at,
              (CAMERA_WIDTH * (1 - BORDER_SIZE)) + TOP_BORDER,
              this.getVertexBufferObjectManager());
      Line boardLineHorz =
          new Line(
              FIRST_SPACE,
              pos_at + TOP_BORDER,
              CAMERA_WIDTH * (1 - BORDER_SIZE),
              pos_at + TOP_BORDER,
              this.getVertexBufferObjectManager());
      boardLineVert.setColor(0, 0, 0);
      boardLineHorz.setColor(0, 0, 0);
      mScene.attachChild(boardLineHorz);
      mScene.attachChild(boardLineVert);
      pos_at = pos_at + SPACING;
    }

    hudLoader.addTouchToScene(mScene, mZoomCamera);

    this.mScene.setTouchAreaBindingOnActionDownEnabled(true);

    return this.mScene;
  }
  private void addRectangleWithTension(final Scene pScene, final float pTension, float pDelay) {
    final Rectangle rectangle =
        new Rectangle(-SIZE, -SIZE, SIZE, SIZE, this.getVertexBufferObjectManager());
    rectangle.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
    if (pTension < 0) {
      rectangle.setColor(1 - pTension, 0, 0, 0.5f);
    } else {
      rectangle.setColor(pTension, 0, 0, 0.5f);
    }

    final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig1 =
        new CardinalSplineMoveModifierConfig(
            CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension);
    final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig2 =
        new CardinalSplineMoveModifierConfig(
            CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension);

    for (int i = 0; i < CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length; i++) {
      catmullRomMoveModifierConfig1.setControlPoint(
          i,
          CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS[i] - SIZE / 2,
          CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2);
      catmullRomMoveModifierConfig2.setControlPoint(
          i,
          CardinalSplineMoveModifierExample.CONTROLPOINT_2_XS[i] - SIZE / 2,
          CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2);
    }

    rectangle.registerEntityModifier(
        new SequenceEntityModifier(
            new DelayModifier(pDelay),
            new LoopEntityModifier(
                new SequenceEntityModifier(
                    new ParallelEntityModifier(
                        new CardinalSplineMoveModifier(
                            CardinalSplineMoveModifierExample.DURATION,
                            catmullRomMoveModifierConfig1,
                            EaseLinear.getInstance()),
                        new RotationModifier(
                            CardinalSplineMoveModifierExample.DURATION, -45, -315)),
                    new ParallelEntityModifier(
                        new CardinalSplineMoveModifier(
                            CardinalSplineMoveModifierExample.DURATION,
                            catmullRomMoveModifierConfig2,
                            EaseLinear.getInstance()),
                        new RotationModifier(
                            CardinalSplineMoveModifierExample.DURATION, 45, 315))))));

    pScene.attachChild(rectangle);
  }
示例#6
0
  public void disable() {
    enabled = false;

    this.detachChild(fgText);
    this.detachChild(fgRect);
    this.detachChild(bgRect);

    fgRect.clearEntityModifiers();
    fgRect.setColor(FGRECT_COLOR_DISABLED);

    mScene.unregisterTouchArea(bgRect);

    this.attachChild(bgRect);
    this.attachChild(fgRect);
    this.attachChild(fgText);
  }
示例#7
0
  public void onFinish() {

    if (mFinished) return;

    final float scale_x_fromValue = mBackgroundRectangle.getScaleX();
    final float scale_x_toValue = 0;
    final float duration = HIDE_DURATION * (scale_x_fromValue / 1.0f);

    if (mStopModifier == null) {
      mStopModifier =
          new SingleValueSpanEntityModifier(
              duration,
              scale_x_fromValue,
              scale_x_toValue,
              new IEntityModifierListener() {

                @Override
                public void onModifierStarted(
                    final IModifier<IEntity> pModifier, final IEntity pItem) {

                  //							unregisterEntityModifier(mStartModifier);
                }

                @Override
                public void onModifierFinished(
                    final IModifier<IEntity> pModifier, final IEntity pItem) {

                  mFinished = true;
                }
              }) {

            @Override
            protected void onSetInitialValue(final IEntity pItem, final float pValue) {

              mBackgroundRectangle.setScaleX(pValue);
            }

            @Override
            protected void onSetValue(
                final IEntity pItem, final float pPercentageDone, float pValue) {

              mBackgroundRectangle.setScaleX(pValue);
            }

            @Override
            public SingleValueSpanEntityModifier deepCopy()
                throws org.andengine.util.modifier.IModifier.DeepCopyNotSupportedException {
              return null;
            }
          };
      mStopModifier.setAutoUnregisterWhenFinished(false);
      this.registerEntityModifier(mStopModifier);
    } else {
      mStopModifier.reset(duration, scale_x_fromValue, scale_x_toValue);
    }
  }
示例#8
0
  private void rectangle(int b) {

    if (b == 0) {
      one.setVisible(true);
      two.setVisible(true);
      three.setVisible(true);
      four.setVisible(true);
      five.setVisible(true);
    }

    if (b > 50) one.setVisible(false);

    if (b > 75) two.setVisible(false);

    if (b > 100) three.setVisible(false);

    if (b > 125) four.setVisible(false);

    if (b > 150) five.setVisible(false);
  }
示例#9
0
  public void enable() {
    enabled = true;

    this.detachChild(fgText);
    this.detachChild(fgRect);
    this.detachChild(bgRect);

    fgRect.setColor(FGRECT_COLOR);

    mScene.registerTouchArea(bgRect);

    this.attachChild(bgRect);
    this.attachChild(fgRect);
    this.attachChild(fgText);
  }
示例#10
0
  /**
   * This initializes each of the Tower buttons within the HUD
   *
   * @param region
   * @param number
   */
  public TowerTile(BaseTextureRegion region) {
    T = towerMap.get(region);
    isTouched = false;
    InflatableDefenseActivity activity = InflatableDefenseActivity.getSharedInstance();
    ZoomCamera camera = activity.getCamera();
    VertexBufferObjectManager vbom = activity.getVertexBufferObjectManager();
    TMXTiledMap map = GameScene.getSharedInstance().getTMXTiledMap();

    Float height = camera.getHeight() - map.getTileRows() * map.getTileHeight();
    frame =
        new Rectangle(0.0f, 0.0f, height, height, vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.isActionDown()) isTouched = true;
            else if (pSceneTouchEvent.isActionMove()) {
              isMoved = true;
            }
            return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    frame.setColor(Color.WHITE);
    sprite = new Sprite(0, 0, region, vbom);
  }
  @Override
  public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) {

    mPhysicsWorld =
        new FixedStepPhysicsWorld(
            60, new Vector2(0f, -SensorManager.GRAVITY_EARTH * 2), false, 8, 3);
    mScene.registerUpdateHandler(mPhysicsWorld);
    final FixtureDef WALL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
    final Rectangle ground =
        new Rectangle(
            cameraWidth / 2f, 6f, cameraWidth - 4f, 8f, this.getVertexBufferObjectManager());
    final Rectangle roof =
        new Rectangle(
            cameraWidth / 2f,
            cameraHeight - 6f,
            cameraWidth - 4f,
            8f,
            this.getVertexBufferObjectManager());
    final Rectangle left =
        new Rectangle(
            6f, cameraHeight / 2f, 8f, cameraHeight - 4f, this.getVertexBufferObjectManager());
    final Rectangle right =
        new Rectangle(
            cameraWidth - 6f,
            cameraHeight / 2f,
            8f,
            cameraHeight - 4f,
            this.getVertexBufferObjectManager());
    ground.setColor(0f, 0f, 0f);
    roof.setColor(0f, 0f, 0f);
    left.setColor(0f, 0f, 0f);
    right.setColor(0f, 0f, 0f);
    groundWallBody =
        PhysicsFactory.createBoxBody(
            this.mPhysicsWorld, ground, BodyType.StaticBody, WALL_FIXTURE_DEF);
    roofWallBody =
        PhysicsFactory.createBoxBody(
            this.mPhysicsWorld, roof, BodyType.StaticBody, WALL_FIXTURE_DEF);
    leftWallBody =
        PhysicsFactory.createBoxBody(
            this.mPhysicsWorld, left, BodyType.StaticBody, WALL_FIXTURE_DEF);
    rightWallBody =
        PhysicsFactory.createBoxBody(
            this.mPhysicsWorld, right, BodyType.StaticBody, WALL_FIXTURE_DEF);
    this.mScene.attachChild(ground);
    this.mScene.attachChild(roof);
    this.mScene.attachChild(left);
    this.mScene.attachChild(right);

    Rectangle GravityRect =
        new Rectangle(300f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager());
    GravityRect.setColor(0f, 0.7f, 0f);
    mScene.attachChild(GravityRect);
    mScene.registerTouchArea(GravityRect);
    gravityBody =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, GravityRect, BodyType.DynamicBody, boxFixtureDef);
    gravityBody.setLinearDamping(0.4f);
    gravityBody.setAngularDamping(0.6f);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(GravityRect, gravityBody));

    Rectangle AntiGravityRect =
        new Rectangle(500f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager()) {
          @Override
          protected void onManagedUpdate(final float pSecondsElapsed) {
            super.onManagedUpdate(pSecondsElapsed);
            antigravityBody.applyForce(
                -mPhysicsWorld.getGravity().x * antigravityBody.getMass(),
                -mPhysicsWorld.getGravity().y * antigravityBody.getMass(),
                antigravityBody.getWorldCenter().x,
                antigravityBody.getWorldCenter().y);
          }
        };
    AntiGravityRect.setColor(0f, 0f, 0.7f);
    mScene.attachChild(AntiGravityRect);
    mScene.registerTouchArea(AntiGravityRect);
    antigravityBody =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, AntiGravityRect, BodyType.DynamicBody, boxFixtureDef);
    antigravityBody.setLinearDamping(0.4f);
    antigravityBody.setAngularDamping(0.6f);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(AntiGravityRect, antigravityBody));

    mScene.setOnSceneTouchListener(this);
    pOnPopulateSceneCallback.onPopulateSceneFinished();
  }
  @Override
  public void onLoadLayer() {
    if (this.mHasLoaded) {
      return;
    }
    this.mHasLoaded = true;

    this.setTouchAreaBindingOnActionDownEnabled(true);
    this.setTouchAreaBindingOnActionMoveEnabled(true);

    final Rectangle fadableBGRect =
        new Rectangle(
            0f,
            0f,
            ResourceManager.getInstance().cameraWidth,
            ResourceManager.getInstance().cameraHeight,
            ResourceManager.getActivity().getVertexBufferObjectManager());
    fadableBGRect.setColor(0f, 0f, 0f, 0.5f);
    this.attachChild(fadableBGRect);

    this.attachChild(
        this.mLayerBG =
            new Sprite(
                0f,
                (ResourceManager.getInstance().cameraHeight / 2f)
                    + (ResourceManager.gameLevelLayerBGTR.getHeight() / 2f),
                ResourceManager.gameLevelLayerBGTR,
                ResourceManager.getActivity().getVertexBufferObjectManager()));
    this.mLayerBG.setScale(1.5f / ResourceManager.getInstance().cameraScaleFactorY);

    final GrowButton BackToLevelSelectButton =
        new GrowButton(128.2f, 75f, ResourceManager.gameLevelLayerButtonLevelSelectTR, false) {
          @Override
          public void onClick() {
            LevelWonLayer.this.mIsGoingToRestartLevel = false;
            LevelWonLayer.this.mIsGoingToNextLevel = false;
            LevelWonLayer.this.onHideLayer();
          }
        };
    this.mLayerBG.attachChild(BackToLevelSelectButton);
    this.registerTouchArea(BackToLevelSelectButton);

    final GrowButton RestartLevelButton =
        new GrowButton(256f, 75f, ResourceManager.gameLevelLayerButtonRestartLevelTR, false) {
          @Override
          public void onClick() {
            LevelWonLayer.this.mIsGoingToRestartLevel = true;
            LevelWonLayer.this.mIsGoingToNextLevel = false;
            LevelWonLayer.this.onHideLayer();
          }
        };
    this.mLayerBG.attachChild(RestartLevelButton);
    this.registerTouchArea(RestartLevelButton);

    final GrowButton NextLevelButton =
        new GrowButton(383f, 75f, ResourceManager.gameLevelLayerButtonNextLevelTR, false) {
          @Override
          public void onClick() {
            LevelWonLayer.this.mIsGoingToRestartLevel = false;
            LevelWonLayer.this.mIsGoingToNextLevel = true;
            LevelWonLayer.this.onHideLayer();
          }
        };
    this.mLayerBG.attachChild(NextLevelButton);
    this.registerTouchArea(NextLevelButton);

    this.mLayerBG.attachChild(
        new Sprite(
            365f,
            148f,
            ResourceManager.gameLevelLayerStarsBGTR,
            ResourceManager.getActivity().getVertexBufferObjectManager()));
    this.mLayerBG.attachChild(
        this.mStarsTiledSprite =
            new TiledSprite(
                365f,
                148f,
                ResourceManager.gameLevelLayerStarsTTR,
                ResourceManager.getActivity().getVertexBufferObjectManager()));

    this.mMainText =
        new Text(
            0f,
            0f,
            ResourceManager.fontDefaultMagneTank48,
            "LEVEL *** SUCCESS!",
            ResourceManager.getActivity().getVertexBufferObjectManager());
    this.mMainText.setScale(Math.min(390f / this.mMainText.getWidth(), 1f));
    this.mMainText.setPosition(256f, 205f);
    this.mMainText.setColor(0.31f, 0.35f, 0.31f);
    this.mLayerBG.attachChild(this.mMainText);

    this.mScoreText =
        new Text(
            0f,
            0f,
            ResourceManager.fontDefaultMagneTank48,
            "SCORE: *****",
            ResourceManager.getActivity().getVertexBufferObjectManager());
    this.mScoreText.setAnchorCenterX(0f);
    this.mScoreText.setScale(Math.min(203f / this.mScoreText.getWidth(), 1f));
    this.mScoreText.setPosition(80f, 155f);
    this.mScoreText.setColor(0.31f, 0.35f, 0.31f);
    this.mLayerBG.attachChild(this.mScoreText);

    this.mHighScoreText =
        new Text(
            0f,
            0f,
            ResourceManager.fontDefaultMagneTank48,
            "HIGHSCORE: *****",
            ResourceManager.getActivity().getVertexBufferObjectManager());
    this.mHighScoreText.setAnchorCenterX(0f);
    this.mHighScoreText.setScale(Math.min(203f / this.mHighScoreText.getWidth(), 1f));
    this.mHighScoreText.setPosition(80f, 128f);
    this.mHighScoreText.setColor(0.31f, 0.35f, 0.31f);
    this.mLayerBG.attachChild(this.mHighScoreText);

    this.setPosition(
        ResourceManager.getInstance().cameraWidth / 2f,
        ResourceManager.getInstance().cameraHeight / 2f);
  }
示例#13
0
  public ChromaButton(float x, float y, int fontSize, String text, boolean e, Scene s) {
    super(0, 0);

    mScene = s;
    fgText =
        new ChromaText(fontSize)
            .getText(text, x + (BGRECT_MARGIN_WIDTH), y + (BGRECT_MARGIN_HEIGHT), TEXT_LEFT);

    posX = x;
    posY = y;

    textHeight = fgText.getHeightScaled();
    textWidth = fgText.getWidthScaled();

    enabled = e;

    fgRect =
        new Rectangle(
            x + FGRECT_MARGIN_WIDTH,
            y + FGRECT_MARGIN_HEIGHT,
            textWidth + (FGRECT_MARGIN_WIDTH * 2),
            textHeight + (FGRECT_MARGIN_HEIGHT * 2),
            ChromaTools.mVBO) {};

    bgRect =
        new Rectangle(
            x,
            y,
            textWidth + (BGRECT_MARGIN_WIDTH * 2),
            textHeight + (BGRECT_MARGIN_HEIGHT * 2),
            ChromaTools.mVBO) {
          @Override
          public boolean onAreaTouched(
              final TouchEvent pSceneTouchEvent,
              final float pTouchAreaLocalX,
              final float pTouchAreaLocalY) {

            int action = pSceneTouchEvent.getAction();

            if (action == TouchEvent.ACTION_DOWN) {
              ColorModifier cm = new ColorModifier(1, FGRECT_COLOR_PRESSED, FGRECT_COLOR);
              fgRect.clearEntityModifiers();
              fgRect.registerEntityModifier(cm);
              onTouch();
            }

            return true;
          }
        };

    if (enabled) {
      fgRect.setColor(FGRECT_COLOR);
    } else {
      fgRect.setColor(FGRECT_COLOR_DISABLED);
    }

    bgRect.setColor(BGRECT_COLOR);

    this.attachChild(bgRect);
    this.attachChild(fgRect);
    this.attachChild(fgText);

    if (enabled) {
      mScene.registerTouchArea(bgRect);
    }
  }
示例#14
0
 public float getVisionWidth() {
   return mBackgroundRectangle.getWidthScaled();
 }
示例#15
0
 public void onInit() {
   mBackgroundRectangle.setScaleX(0.0f);
   mFinished = true;
 }
示例#16
0
 public void setY(float pY) {
   bgRect.setY(pY);
   fgRect.setY(pY + FGRECT_MARGIN_WIDTH);
   fgText.setY(pY + BGRECT_MARGIN_WIDTH);
 }
  private void init(KeyListenScene pBaseScene) {
    // 共通ウィンドウを作成
    CommonWindowRectangle comonWindowRectangle =
        new CommonWindowRectangle(
            0,
            0,
            pBaseScene.getWindowWidth(),
            pBaseScene.getWindowHeight(),
            Color.BLACK,
            0.8f,
            pBaseScene);
    attachChild(comonWindowRectangle);
    // タイトル
    float titleY = 12;
    Font titleFont = pBaseScene.createFont(Typeface.DEFAULT_BOLD, 30, Color.WHITE);
    Text titleText =
        new Text(
            10,
            10,
            titleFont,
            "〜 経験値振り分け 〜",
            pBaseScene.getBaseActivity().getVertexBufferObjectManager());
    pBaseScene.placeToCenterX(titleText, titleY);
    attachChild(titleText);

    float titleLineY = titleText.getY() + titleText.getHeight() + 4;

    Line line =
        new Line(
            10,
            titleLineY,
            pBaseScene.getWindowWidth() - 16,
            titleLineY,
            pBaseScene.getBaseActivity().getVertexBufferObjectManager());
    line.setLineWidth(1);
    line.setColor(Color.WHITE);
    line.setAlpha(1.0f);
    attachChild(line);

    TextLogic textLogic = new TextLogic();
    Font defaultFont = pBaseScene.createFont(Typeface.SANS_SERIF, 16, Color.WHITE);
    Font paramFont = pBaseScene.createFont(Typeface.DEFAULT, 16, Color.YELLOW);
    // Font upParamFont = pBaseScene.createFont(Typeface.DEFAULT, 16, Color.BLUE);
    // Expの表示
    float expY = titleLineY + 4;
    Rectangle totalExpTextRect =
        textLogic.createTextRectangle(
            "所持経験値:",
            defaultFont,
            "100 Exp",
            paramFont,
            pBaseScene.getBaseActivity().getVertexBufferObjectManager());
    attachChild(totalExpTextRect);

    Rectangle afterExpTextRect =
        textLogic.createTextRectangle(
            "振り分け後経験値:",
            defaultFont,
            "0 Exp",
            paramFont,
            pBaseScene.getBaseActivity().getVertexBufferObjectManager());
    attachChild(afterExpTextRect);

    totalExpTextRect.setPosition(
        pBaseScene.getWindowWidth() / 2
            - (totalExpTextRect.getX()
                    + totalExpTextRect.getWidth()
                    + 50
                    + afterExpTextRect.getWidth())
                / 2,
        expY);

    afterExpTextRect.setPosition(
        totalExpTextRect.getX() + totalExpTextRect.getWidth() + 50, totalExpTextRect.getY());

    float expLineY = totalExpTextRect.getY() + totalExpTextRect.getHeight() + 4;
    Line expLine =
        new Line(
            10,
            expLineY,
            pBaseScene.getWindowWidth() - 16,
            expLineY,
            pBaseScene.getBaseActivity().getVertexBufferObjectManager());
    expLine.setLineWidth(1);
    expLine.setColor(Color.WHITE);
    expLine.setAlpha(1.0f);
    attachChild(expLine);

    // プレイヤー情報
    float playerX = 12;
    float playerY = expLineY + 12;

    ActorPlayerLogic actorPlayerLogic = new ActorPlayerLogic();
    ActorPlayerDto actorPlayerDto = actorPlayerLogic.createActorPlayerDto(pBaseScene, 1);

    PlayerStatusRectangle playerStatusRectangle =
        new PlayerStatusRectangle(
            pBaseScene,
            defaultFont,
            actorPlayerDto,
            ActorSpriteUtil.getFaceFileName(actorPlayerDto.getImageResId()),
            playerX,
            playerY);
    playerStatusRectangle.show(PlayerStatusRectangleType.MINI_STATUS);
    attachChild(playerStatusRectangle);
  }
  @Override
  public void onLoadLayer() {
    if (this.mHasLoaded) {
      return;
    }
    this.mHasLoaded = true;

    this.setTouchAreaBindingOnActionDownEnabled(true);
    this.setTouchAreaBindingOnActionMoveEnabled(true);

    final Rectangle fadableBGRect =
        new Rectangle(
            0f,
            0f,
            ResourceManager.getInstance().cameraWidth / 2,
            ResourceManager.getInstance().cameraHeight / 2,
            ResourceManager.getActivity().getVertexBufferObjectManager());
    fadableBGRect.setColor(0f, 0f, 0f, 0.8f);
    this.attachChild(fadableBGRect);

    this.attachChild(
        this.LayerBG =
            new Sprite(
                0f,
                (ResourceManager.getInstance().cameraHeight / 2f)
                    + (ResourceManager.gameLevelLayerBGTR.getHeight() / 2f),
                ResourceManager.gameLevelLayerBGTR,
                ResourceManager.getActivity().getVertexBufferObjectManager()));
    this.LayerBG.setScale(1.5f / ResourceManager.getInstance().cameraScaleFactorY);

    this.TitleText =
        new Text(
            0f,
            0f,
            ResourceManager.fontDefaultMagneTank48,
            "OPTIONS",
            ResourceManager.getActivity().getVertexBufferObjectManager());
    this.TitleText.setScale(Math.min(390f / this.TitleText.getWidth(), 1f));
    this.TitleText.setPosition(256f, 225f);
    this.TitleText.setColor(0.31f, 0.35f, 0.31f);
    this.LayerBG.attachChild(this.TitleText);

    this.SoundEnabledText =
        new GrowToggleTextButton(
            256f,
            197.2f,
            "SOUND: ENABLED",
            "SOUND: DISABLED",
            ResourceManager.fontDefaultMagneTank48,
            !SFXManager.isSoundMuted()) {
          @Override
          public boolean checkState() {
            return !SFXManager.isSoundMuted();
          }

          @Override
          public void onClick() {
            SFXManager.toggleSoundMuted();
          }
        };
    this.SoundEnabledText.setScales(
        Math.min(390f / this.SoundEnabledText.getWidth(), 0.85f),
        Math.min(390f / this.SoundEnabledText.getWidth(), 0.85f) * 1.4f);
    this.SoundEnabledText.setColor(0.212f, 0.275f, 0.212f);
    this.LayerBG.attachChild(this.SoundEnabledText);
    this.registerTouchArea(this.SoundEnabledText);

    this.MusicEnabledText =
        new GrowToggleTextButton(
            256f,
            169.4f,
            "MUSIC: ENABLED",
            "MUSIC: DISABLED",
            ResourceManager.fontDefaultMagneTank48,
            !SFXManager.isMusicMuted()) {
          @Override
          public boolean checkState() {
            return !SFXManager.isMusicMuted();
          }

          @Override
          public void onClick() {
            SFXManager.toggleMusicMuted();
          }
        };
    this.MusicEnabledText.setScales(
        Math.min(390f / this.MusicEnabledText.getWidth(), 0.85f),
        Math.min(390f / this.MusicEnabledText.getWidth(), 0.85f) * 1.2f);
    this.MusicEnabledText.setColor(0.212f, 0.275f, 0.212f);
    this.LayerBG.attachChild(this.MusicEnabledText);
    this.registerTouchArea(this.MusicEnabledText);

    this.GraphicsQualityText =
        new GrowToggleTextButton(
            256f,
            141.6f,
            "GRAPHICS: HIGH",
            "GRAPHICS: NORMAL",
            ResourceManager.fontDefaultMagneTank48,
            ResourceManager.isUsingHighQualityGraphics()) {
          @Override
          public boolean checkState() {
            return ResourceManager.isUsingHighQualityGraphics();
          }

          @Override
          public void onClick() {
            ResourceManager.getInstance().switchQuality();
          }
        };
    this.GraphicsQualityText.setScales(
        Math.min(390f / this.GraphicsQualityText.getWidth(), 0.85f),
        Math.min(390f / this.GraphicsQualityText.getWidth(), 0.85f) * 1.2f);
    this.GraphicsQualityText.setColor(0.212f, 0.275f, 0.212f);
    this.LayerBG.attachChild(this.GraphicsQualityText);
    this.registerTouchArea(this.GraphicsQualityText);

    this.ResetText =
        new GrowToggleTextButton(
            256f, 113.8f, "RESET DATA", "", ResourceManager.fontDefaultMagneTank48, true) {
          @Override
          public boolean checkState() {
            return true;
          }

          @Override
          public void onClick() {
            ResourceManager.getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        final AlertDialog.Builder builder =
                            new AlertDialog.Builder(ResourceManager.getActivity());
                        builder.setTitle("Reset Game Data?");
                        builder.setIcon(R.drawable.icon);
                        builder
                            .setMessage(
                                "This will reset all scores and stars that you've achieved. Continue?")
                            .setPositiveButton(
                                "Reset Data",
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(final DialogInterface dialog, final int id) {
                                    final int ActivityStartCount =
                                        TimelessWarriorsActivity.getIntFromSharedPreferences(
                                            TimelessWarriorsActivity
                                                .SHARED_PREFS_ACTIVITY_START_COUNT);
                                    final int MusicMuted =
                                        TimelessWarriorsActivity.getIntFromSharedPreferences(
                                            TimelessWarriorsActivity.SHARED_PREFS_MUSIC_MUTED);
                                    final boolean Quality =
                                        TimelessWarriorsActivity.getBooleanFromSharedPreferences(
                                            TimelessWarriorsActivity
                                                .SHARED_PREFS_HIGH_QUALITY_GRAPHICS);
                                    final int MarketRated =
                                        TimelessWarriorsActivity.getIntFromSharedPreferences(
                                            TimelessWarriorsActivity.SHARED_PREFS_RATING_SUCCESS);
                                    final int SoundMuted =
                                        TimelessWarriorsActivity.getIntFromSharedPreferences(
                                            TimelessWarriorsActivity.SHARED_PREFS_SOUNDS_MUTED);
                                    ResourceManager.getActivity()
                                        .getSharedPreferences(
                                            TimelessWarriorsActivity.SHARED_PREFS_MAIN, 0)
                                        .edit()
                                        .clear()
                                        .putInt(
                                            TimelessWarriorsActivity
                                                .SHARED_PREFS_ACTIVITY_START_COUNT,
                                            ActivityStartCount)
                                        .putInt(
                                            TimelessWarriorsActivity.SHARED_PREFS_MUSIC_MUTED,
                                            MusicMuted)
                                        .putBoolean(
                                            TimelessWarriorsActivity
                                                .SHARED_PREFS_HIGH_QUALITY_GRAPHICS,
                                            Quality)
                                        .putInt(
                                            TimelessWarriorsActivity.SHARED_PREFS_RATING_SUCCESS,
                                            MarketRated)
                                        .putInt(
                                            TimelessWarriorsActivity.SHARED_PREFS_SOUNDS_MUTED,
                                            SoundMuted)
                                        .apply();
                                    MainMenu.getInstance().RefreshLevelStars();
                                  }
                                })
                            .setNegativeButton(
                                "Cancel",
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(final DialogInterface dialog, final int id) {}
                                })
                            .setCancelable(false);
                        final AlertDialog alert = builder.create();
                        alert.show();
                      }
                    });
          }
        };
    this.ResetText.setScales(
        Math.min(390f / this.ResetText.getWidth(), 0.85f),
        Math.min(390f / this.ResetText.getWidth(), 0.85f) * 1.2f);
    this.ResetText.setColor(0.212f, 0.275f, 0.212f);
    this.LayerBG.attachChild(this.ResetText);
    this.registerTouchArea(this.ResetText);

    final GrowButton BackToTitleButton =
        new GrowButton(0f, 0f, ResourceManager.menuArrow2TR, false) {
          @Override
          public void onClick() {
            OptionsLayer.this.onHideLayer();
          }
        };
    BackToTitleButton.setFlippedHorizontal(true);
    this.LayerBG.attachChild(BackToTitleButton);
    BackToTitleButton.setPosition(256f, 66f);
    this.registerTouchArea(BackToTitleButton);

    this.setPosition(
        ResourceManager.getInstance().cameraWidth / 2f,
        ResourceManager.getInstance().cameraHeight / 2f);
  }
示例#19
0
  public BLevel4() {

    setBackground(new Background(0, 0, 0));
    setOnSceneTouchListener(this);
    activity = World2Activity.getSharedInstance();
    Camera mCamera = activity.mCamera;
    W1LSMenu.bPhysicsWorld =
        new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_THE_ISLAND), false);
    mPhysicsWorld = W1LSMenu.bPhysicsWorld;
    menu = (activity.createMenuScene());
    Sprite bg = new Sprite(0, 0, activity.menuBgTexture, activity.getVertexBufferObjectManager());
    setBackground(new SpriteBackground(bg));

    // PhysicsWorld bPhysicsWorld = new PhysicsWorld(new Vector2(0,
    // SensorManager.GRAVITY_THE_ISLAND), false);
    final VertexBufferObjectManager vertexBufferObjectManager =
        activity.getVertexBufferObjectManager();
    final Rectangle ground =
        new Rectangle(0, mCamera.getHeight() - 2, mCamera.getWidth(), 2, vertexBufferObjectManager);
    final Rectangle roof = new Rectangle(0, 0, mCamera.getWidth(), 2, vertexBufferObjectManager);
    final Rectangle left = new Rectangle(0, 0, 2, mCamera.getHeight(), vertexBufferObjectManager);
    final Rectangle right =
        new Rectangle(mCamera.getWidth() - 2, 0, 2, mCamera.getHeight(), vertexBufferObjectManager);
    final Rectangle reset = new Rectangle(0, 0, 200, 20, vertexBufferObjectManager);

    ground.setColor(Color.RED);
    roof.setColor(Color.RED);
    right.setColor(Color.RED);

    // final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
    Body Ground =
        PhysicsFactory.createBoxBody(mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
    Body Roof =
        PhysicsFactory.createBoxBody(mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
    Body Left =
        PhysicsFactory.createBoxBody(mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
    Body Right =
        PhysicsFactory.createBoxBody(mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);
    Body Reset =
        PhysicsFactory.createBoxBody(mPhysicsWorld, reset, BodyType.StaticBody, wallFixtureDef);

    Ground.setUserData("ground");
    Roof.setUserData("ground");
    Left.setUserData("wall");
    Right.setUserData("ground");
    Reset.setUserData("tw");

    attachChild(ground);
    attachChild(roof);
    attachChild(left);
    attachChild(right);

    activity.menu = 3;
    x = 3;

    final DelayModifier dMod =
        new DelayModifier(
            2,
            new IEntityModifierListener() {
              @Override
              public void onModifierStarted(IModifier arg0, IEntity arg1) {}

              public void onModifierFinished(IModifier arg0, IEntity arg1) {
                destroy(0);
              }
            });

    final Text elapsedText =
        new Text(
            600, 10, activity.mFont, "Score:0123456789", activity.getVertexBufferObjectManager());
    registerUpdateHandler(
        new TimerHandler(
            1 / 10.0f,
            true,
            new ITimerCallback() {
              @Override
              public void onTimePassed(final TimerHandler pTimerHandler) {

                score = (score - Math.round(activity.mCurrentScene.getSecondsElapsedTotal()));
                elapsedText.setText("Time :" + score);
              }
            }));

    attachChild(elapsedText);

    final Rectangle bL = new Rectangle(350, 365, 50, 20, vertexBufferObjectManager);
    final Rectangle bB = new Rectangle(325, 355, 50, 10, vertexBufferObjectManager);
    final Rectangle bR = new Rectangle(375, 355, 50, 10, vertexBufferObjectManager);
    final Rectangle finish = new Rectangle(350, 360, 50, 20, vertexBufferObjectManager);
    bR.setRotation(90);
    bB.setRotation(90);

    final Rectangle gate = new Rectangle(325, 330, 100, 10, vertexBufferObjectManager);
    // gate.setRotation(90);
    final Body Gate =
        PhysicsFactory.createBoxBody(mPhysicsWorld, gate, BodyType.StaticBody, wallFixtureDef);
    Gate.setUserData("gate");
    gate.setColor(Color.GREEN);
    attachChild(gate);

    final Rectangle power = new Rectangle(650, 250, 15, 15, vertexBufferObjectManager);
    final Body Power =
        PhysicsFactory.createBoxBody(mPhysicsWorld, power, BodyType.StaticBody, wallFixtureDef);
    power.setColor(Color.BLUE);
    Power.setUserData("power");
    attachChild(power);

    one = new Rectangle(765, 290, 25, 38, vertexBufferObjectManager);
    two = new Rectangle(765, 330, 25, 38, vertexBufferObjectManager);
    three = new Rectangle(765, 370, 25, 38, vertexBufferObjectManager);
    four = new Rectangle(765, 410, 25, 38, vertexBufferObjectManager);
    five = new Rectangle(765, 445, 25, 38, vertexBufferObjectManager);

    one.setColor(Color.GREEN);
    two.setColor(Color.GREEN);
    three.setColor(Color.YELLOW);
    four.setColor(Color.YELLOW);
    five.setColor(Color.RED);

    attachChild(one);
    attachChild(two);
    attachChild(three);
    attachChild(four);
    attachChild(five);

    Body bod = PhysicsFactory.createBoxBody(mPhysicsWorld, bL, BodyType.StaticBody, wallFixtureDef);
    Body lbod =
        PhysicsFactory.createBoxBody(mPhysicsWorld, bR, BodyType.StaticBody, wallFixtureDef);
    Body rbod =
        PhysicsFactory.createBoxBody(mPhysicsWorld, bB, BodyType.StaticBody, wallFixtureDef);
    Body Finish =
        PhysicsFactory.createBoxBody(mPhysicsWorld, finish, BodyType.StaticBody, wallFixtureDef);

    Rectangle help = new Rectangle(0, 150, 300, 10, vertexBufferObjectManager);
    Body Help =
        PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody, wallFixtureDef);

    Rectangle block = new Rectangle(290, 100, 250, 10, vertexBufferObjectManager);
    block.setRotation(-25);

    Body Block =
        PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody, wallFixtureDef);

    Block.setUserData("block");
    bod.setUserData("body");
    rbod.setUserData("body");
    lbod.setUserData("body");
    Finish.setUserData("finish");
    Help.setUserData("Help");
    bL.setColor(Color.WHITE);
    block.setColor(Color.WHITE);
    bR.setColor(Color.WHITE);
    bB.setColor(Color.WHITE);
    help.setColor(Color.WHITE);
    finish.setColor(0, 0, 1);
    finish.setVisible(false);

    attachChild(block);
    attachChild(bL);
    attachChild(bR);
    attachChild(bB);
    attachChild(help);
    attachChild(finish);

    // final ButtonSprite button = new ButtonSprite(5, 5, activity.mMenuResetTextureRegion,
    // vertexBufferObjectManager);
    // attachChild(button);

    // FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(0.0f,
    //     0.0f, 0.0f);

    FixtureDef FIXTURE_DEF2 = PhysicsFactory.createFixtureDef(1, .9f, 0.5f);
    final int blue = activity.faceSelected(1);

    if (blue == 1)
      face = new AnimatedSprite(05, 50, activity.redFace, activity.getVertexBufferObjectManager());
    else if (blue == 2)
      face = new AnimatedSprite(05, 50, activity.blueFace, activity.getVertexBufferObjectManager());
    else if (blue == 3)
      face =
          new AnimatedSprite(05, 50, activity.yellowFace, activity.getVertexBufferObjectManager());
    else if (blue == 4) {
      activity.grav = 5;
      face = new AnimatedSprite(05, 50, activity.hairFace, activity.getVertexBufferObjectManager());
    } else if (blue == 5)
      face = new AnimatedSprite(05, 50, activity.djFace, activity.getVertexBufferObjectManager());
    else if (blue == 6) {
      activity.grav = 2;
      face = new AnimatedSprite(05, 50, activity.jetFace, activity.getVertexBufferObjectManager());
    } else if (blue == 7)
      face = new AnimatedSprite(05, 50, activity.slowFace, activity.getVertexBufferObjectManager());
    else if (blue == 8)
      face = new AnimatedSprite(05, 50, activity.fastFace, activity.getVertexBufferObjectManager());
    else
      face = new AnimatedSprite(05, 50, activity.redFace, activity.getVertexBufferObjectManager());

    if (blue == 5)
      body =
          PhysicsFactory.createCircleBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF2);
    else if (blue == 6)
      body = PhysicsFactory.createBoxBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);
    else
      body =
          PhysicsFactory.createCircleBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);

    body.setUserData("face");
    face.animate(200);

    attachChild(face);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));

    registerUpdateHandler(mPhysicsWorld);

    Rectangle pauseBtn =
        new Rectangle(0, 0, 130, 130, activity.getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP) {

              activity.menu = 4;
              setChildScene(menu, false, true, true);
            }
            return true;
          }
        };

    pauseBtn.setVisible(false);
    // pauseBtn.setColor(0,0,1);
    attachChild(pauseBtn);
    registerTouchArea(pauseBtn);

    final Text resetText =
        new Text(
            10,
            10,
            activity.mFont,
            "Pause",
            new TextOptions(HorizontalAlign.CENTER),
            vertexBufferObjectManager);
    attachChild(resetText);

    mPhysicsWorld.setContactListener(
        new ContactListener() {
          @Override
          public void beginContact(final Contact contact) {

            final Fixture A = contact.getFixtureA();
            final Fixture B = contact.getFixtureB();

            final Body bodyA = A.getBody();
            final Body bodyB = B.getBody();

            String abe = bodyA.getUserData().toString();
            String be = bodyB.getUserData().toString();

            if (abe == "power" || be == "power") {
              power.setVisible(false);
              Power.setActive(false);
              Gate.setActive(false);
              gate.setColor(Color.TRANSPARENT);

            } else if (abe == "ground" || be == "ground") {
              activity.gameToast("You ran into a fire wall");
              destroy(1);

            } else if (abe == "finish" || be == "finish") {
              bB.setColor(0, 0, 1);
              bL.setColor(0, 0, 1);
              bR.setColor(0, 0, 1);

              registerEntityModifier(dMod);

            } else if (abe == "ground" || be == "ground") {
              activity.gameToast("You fell into a pit try again");
              destroy(1);
            }
          }

          @Override
          public void endContact(final Contact pContact) {
            /* Do something... */
          }

          @Override
          public void preSolve(Contact contact, Manifold oldManifold) {}

          @Override
          public void postSolve(Contact contact, ContactImpulse impulse) {
            // TODO Auto-generated method stub

          }
        });
  }
  /**
   * 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;
  }
 @Override
 public void onScrollFinished(
     ScrollDetector pScollDetector, int pPointerID, float pDistanceX, float pDistanceY) {
   mBossSlider.clearEntityModifiers();
   if (directionPath > 0f) {
     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));
     }
   } else {
     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));
     }
   }
 }
 @Override
 public void onScroll(
     ScrollDetector pScollDetector, int pPointerID, float pDistanceX, float pDistanceY) {
   float f1 = mBossSlider.getX() + pDistanceX;
   mBossSlider.setPosition(f1, mBossSlider.getY());
 }
示例#23
0
  public Level21() {

    setBackground(new Background(0, 0, 0));
    setOnSceneTouchListener(this);
    activity = World1Activity.getSharedInstance();
    Camera mCamera = activity.mCamera;
    Level1.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
    mPhysicsWorld = Level1.mPhysicsWorld;
    Sprite bg = new Sprite(0, 0, activity.menuBgTexture6, activity.getVertexBufferObjectManager());
    setBackground(new SpriteBackground(bg));
    // activity.gameToast("The bugs have morphed and can travel through lines");
    // PhysicsWorld bPhysicsWorld = new PhysicsWorld(new Vector2(0,
    // SensorManager.GRAVITY_THE_ISLAND), false);
    final VertexBufferObjectManager vertexBufferObjectManager =
        activity.getVertexBufferObjectManager();
    final Rectangle ground =
        new Rectangle(0, mCamera.getHeight() - 2, mCamera.getWidth(), 2, vertexBufferObjectManager);
    final Rectangle roof = new Rectangle(0, 0, mCamera.getWidth(), 2, vertexBufferObjectManager);
    final Rectangle left = new Rectangle(0, 0, 2, mCamera.getHeight(), vertexBufferObjectManager);
    final Rectangle right =
        new Rectangle(mCamera.getWidth() - 2, 0, 2, mCamera.getHeight(), vertexBufferObjectManager);
    final Rectangle reset = new Rectangle(0, 0, 200, 20, vertexBufferObjectManager);

    ground.setColor(0, 255, 255);
    // right.setColor(Color.RED);

    //	final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f, false,
    // CATEGORYBIT_WALL, MASKBITS_WALL, (short)0);
    Body Ground =
        PhysicsFactory.createBoxBody(mPhysicsWorld, ground, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body Roof =
        PhysicsFactory.createBoxBody(mPhysicsWorld, roof, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body Left =
        PhysicsFactory.createBoxBody(mPhysicsWorld, left, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body Right =
        PhysicsFactory.createBoxBody(mPhysicsWorld, right, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body Reset =
        PhysicsFactory.createBoxBody(mPhysicsWorld, reset, BodyType.StaticBody, WALL_FIXTURE_DEF);

    Ground.setUserData("ground");
    Roof.setUserData("roof");
    Left.setUserData("left");
    Right.setUserData("right");
    Reset.setUserData("tw");

    attachChild(ground);
    attachChild(roof);
    attachChild(left);
    attachChild(right);

    Rectangle help = new Rectangle(50, 220, 250, 10, vertexBufferObjectManager);
    Body Help =
        PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody, WALL_FIXTURE_DEF);
    final Rectangle help2 = new Rectangle(0, 220, 50, 10, vertexBufferObjectManager);
    final Body Help2 =
        PhysicsFactory.createBoxBody(mPhysicsWorld, help2, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Help2.setUserData("help");
    help2.setColor(Color.WHITE);
    attachChild(help2);
    Rectangle block = new Rectangle(180, 220, 250, 10, vertexBufferObjectManager);
    block.setRotation(90);

    Body Block =
        PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody, WALL_FIXTURE_DEF);

    Block.setUserData("block");
    Help.setUserData("help");
    block.setColor(Color.WHITE);
    help.setColor(Color.WHITE);
    attachChild(help);
    attachChild(block);

    //	 final FixtureDef objectFixtureDef2 = PhysicsFactory.createFixtureDef(10, 0.2f, 0.5f,false,
    // CATEGORYBIT_WALL, MASKBITS_WALL, (short)0);

    final Text elapsedText =
        new Text(
            600, 10, activity.mFont3, "Score:0123456789", activity.getVertexBufferObjectManager());
    registerUpdateHandler(
        new TimerHandler(
            1 / 10f,
            true,
            new ITimerCallback() {
              @Override
              public void onTimePassed(final TimerHandler pTimerHandler) {

                if (score > 2501) {
                  score = (score - Math.round(activity.mCurrentScene.getSecondsElapsedTotal()));
                  elapsedText.setText("Score:" + score);
                } else {
                  score = 2500;
                  elapsedText.setText("Score:" + score);
                }
              }
            }));
    attachChild(elapsedText);

    final DelayModifier dMod =
        new DelayModifier(
            2,
            new IEntityModifierListener() {
              @Override
              public void onModifierStarted(IModifier arg0, IEntity arg1) {}

              public void onModifierFinished(IModifier arg0, IEntity arg1) {
                destroy(0);
              }
            });

    final Rectangle bL = new Rectangle(150, 365, 50, 20, vertexBufferObjectManager);
    final Rectangle bB = new Rectangle(125, 355, 50, 10, vertexBufferObjectManager);
    final Rectangle bR = new Rectangle(175, 355, 50, 10, vertexBufferObjectManager);
    final Rectangle finish = new Rectangle(150, 360, 50, 20, vertexBufferObjectManager);
    bR.setRotation(90);
    bB.setRotation(90);

    one = new Rectangle(765, 290, 25, 35, vertexBufferObjectManager);
    two = new Rectangle(765, 330, 25, 35, vertexBufferObjectManager);
    three = new Rectangle(765, 370, 25, 35, vertexBufferObjectManager);
    four = new Rectangle(765, 410, 25, 35, vertexBufferObjectManager);
    five = new Rectangle(765, 450, 25, 35, vertexBufferObjectManager);

    one.setColor(Color.GREEN);
    two.setColor(Color.GREEN);
    three.setColor(Color.YELLOW);
    four.setColor(Color.YELLOW);
    five.setColor(Color.RED);

    attachChild(one);
    attachChild(two);
    attachChild(three);
    attachChild(four);
    attachChild(five);

    Rectangle laser = new Rectangle(350, 200, 20, 20, vertexBufferObjectManager);
    laser.setColor(Color.RED);
    attachChild(laser);
    final Line lase = new Line(350, 205, 805, 200, 5, vertexBufferObjectManager);
    final Body Lase = PhysicsFactory.createLineBody(mPhysicsWorld, lase, WALL_FIXTURE_DEF);
    Lase.setUserData("laser");
    lase.setColor(Color.RED);
    lase.setVisible(false);
    Lase.setActive(false);
    attachChild(lase);

    registerUpdateHandler(
        new IUpdateHandler() {
          @Override
          public void onUpdate(float pSecondsElapsed) {
            x = x + 1;
            if (x == 50) {
              lase.setVisible(true);
              Lase.setActive(true);
            } else if (x == 100) {
              lase.setVisible(false);
              Lase.setActive(false);
              x = 0;
            }
          }

          @Override
          public void reset() {
            // TODO Auto-generated method stub

          }
        });

    final Rectangle powerup = new Rectangle(665, 050, 15, 15, vertexBufferObjectManager);
    powerup.setColor(Color.RED);
    final Body power =
        PhysicsFactory.createBoxBody(mPhysicsWorld, powerup, BodyType.StaticBody, WALL_FIXTURE_DEF);
    powerup.setVisible(true);
    power.setActive(true);

    Body bod =
        PhysicsFactory.createBoxBody(mPhysicsWorld, bL, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body lbod =
        PhysicsFactory.createBoxBody(mPhysicsWorld, bR, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body rbod =
        PhysicsFactory.createBoxBody(mPhysicsWorld, bB, BodyType.StaticBody, WALL_FIXTURE_DEF);
    Body Finish =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, finish, BodyType.StaticBody, CIRCLE_FIXTURE_DEF);

    // Rectangle help = new Rectangle(0, 220, 300, 10, vertexBufferObjectManager);
    // Body Help = PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody,
    // wallFixtureDef);

    // Rectangle block = new Rectangle(180, 220, 250, 10, vertexBufferObjectManager);
    // block.setRotation(90);

    // Body Block = PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody,
    // wallFixtureDef);

    // Block.setUserData("block");
    bod.setUserData("body");
    rbod.setUserData("body");
    lbod.setUserData("body");
    Finish.setUserData("finish");
    power.setUserData("power");
    //	Help.setUserData("Help");
    bL.setColor(Color.WHITE);
    //	block.setColor(255, 0, 0);
    bR.setColor(Color.WHITE);
    bB.setColor(Color.WHITE);
    //	help.setColor(255, 0, 0);
    finish.setColor(0, 0, 1);
    finish.setVisible(false);

    //	attachChild(block);
    attachChild(bL);
    attachChild(bR);
    attachChild(bB);
    // attachChild(help);
    attachChild(finish);
    attachChild(powerup);

    // centerText = new Text(320, 40, activity.mFont, "IMPORTANT!!! Keep an eye \n out for powerups
    // \n to help you through \n the level \n (touch anywhere to make \n this message dissapear)",
    // new TextOptions(HorizontalAlign.CENTER), vertexBufferObjectManager);
    // attachChild(centerText);
    // final ButtonSprite button = new ButtonSprite(5, 5, activity.mMenuResetTextureRegion,
    // vertexBufferObjectManager);
    // attachChild(button);

    final int blue = activity.faceSelected(1);

    if (blue == 1)
      face = new AnimatedSprite(05, 150, activity.redFace, activity.getVertexBufferObjectManager());
    else if (blue == 2)
      face =
          new AnimatedSprite(05, 150, activity.blueFace, activity.getVertexBufferObjectManager());
    else if (blue == 3)
      face =
          new AnimatedSprite(05, 150, activity.yellowFace, activity.getVertexBufferObjectManager());
    else if (blue == 4)
      face =
          new AnimatedSprite(05, 150, activity.hairFace, activity.getVertexBufferObjectManager());
    else if (blue == 5)
      face = new AnimatedSprite(05, 150, activity.djFace, activity.getVertexBufferObjectManager());
    else if (blue == 6)
      face = new AnimatedSprite(05, 150, activity.jetFace, activity.getVertexBufferObjectManager());
    else if (blue == 7)
      face =
          new AnimatedSprite(05, 150, activity.slowFace, activity.getVertexBufferObjectManager());
    else if (blue == 8)
      face =
          new AnimatedSprite(05, 150, activity.fastFace, activity.getVertexBufferObjectManager());
    else
      face = new AnimatedSprite(05, 150, activity.redFace, activity.getVertexBufferObjectManager());

    body =
        PhysicsFactory.createCircleBody(
            mPhysicsWorld, face, BodyType.DynamicBody, FACE_FIXTURE_DEF);

    body.setUserData("face");
    face.animate(200);

    attachChild(face);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));
    registerUpdateHandler(mPhysicsWorld);
    Random r = new Random();
    int i = r.nextInt(4 - 1) + 1;
    if (i == 1) {
      enemy = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager());
      enemy2 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager());
      enemy3 = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager());
    } else if (i == 2) {
      enemy = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager());
      enemy2 = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager());
      enemy3 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager());
    } else if (i == 3) {
      enemy = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager());
      enemy2 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager());
      enemy3 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager());
    } else enemy = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager());
    enemy2 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager());
    enemy3 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager());

    // final Rectangle enemy = new Rectangle(600,400, 15, 15,
    // activity.getVertexBufferObjectManager());
    Enemy =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, enemy, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF);
    Enemy.setUserData("enemy");
    attachChild(enemy);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy, Enemy, true, true));

    // final Rectangle enemy2 = new Rectangle(500,400, 15, 15,
    // activity.getVertexBufferObjectManager());
    Enemy2 =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, enemy2, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF);
    Enemy2.setUserData("enemy");
    attachChild(enemy2);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy2, Enemy2, true, true));

    //	final Rectangle enemy3 = new Rectangle(400,400, 15, 15,
    // activity.getVertexBufferObjectManager());
    Enemy3 =
        PhysicsFactory.createBoxBody(
            mPhysicsWorld, enemy3, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF);
    Enemy3.setUserData("enemy");
    attachChild(enemy3);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy3, Enemy3, true, true));
    // Enemy.setLinearVelocity(10, -10);

    /*final AnimatedSprite windArea = new AnimatedSprite(200, 0, 50, 500, activity.mBoxFaceTextureRegion, activity.getVertexBufferObjectManager())
        {
            @Override
            protected void onManagedUpdate(float pSecondsElapsed)
            {
                if (face.collidesWith(this))
                {
                    body.applyLinearImpulse(new Vector2(0, -10f), body.getWorldCenter());
                }
            };
        };
      //  windArea.setVisible(false);
        attachChild(windArea);

    */

    Rectangle pauseBtn =
        new Rectangle(10, 10, 100, 100, activity.getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP) {

              Scene menu = (activity.createMenuScene());
              activity.menu = 21;
              setChildScene(menu, false, true, true);
            }
            return true;
          }
        };

    pauseBtn.setVisible(false);
    // pauseBtn.setColor(0,0,1);
    attachChild(pauseBtn);
    registerTouchArea(pauseBtn);

    final Text resetText =
        new Text(
            10,
            10,
            activity.mFont3,
            "Pause",
            new TextOptions(HorizontalAlign.CENTER),
            vertexBufferObjectManager);
    attachChild(resetText);

    mPhysicsWorld.setContactListener(
        new ContactListener() {
          @Override
          public void beginContact(final Contact contact) {

            final Fixture A = contact.getFixtureA();
            final Fixture B = contact.getFixtureB();

            final Body bodyA = A.getBody();
            final Body bodyB = B.getBody();

            String abe = bodyA.getUserData().toString();
            String be = bodyB.getUserData().toString();

            if (abe == "left" || be == "left") {

              Enemy.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter());
              Enemy2.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter());
              Enemy3.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter());
            } else if (abe == "power" && be != "enemy") {

              l = -5;
              activity.gameToast("Nice super shield active. Resetting line....");
              linesDrawn = 0;
              rectangle(linesDrawn);
              powerup.setVisible(false);
              power.setActive(false);
              help2.setVisible(false);
              Help2.setActive(false);
            }

            if (abe == "finish" && be == "face") {
              bB.setColor(0, 0, 1);
              bL.setColor(0, 0, 1);
              bR.setColor(0, 0, 1);
              // lase.setVisible(false);
              // Lase.setActive(false);
              // x = 500;

              registerEntityModifier(dMod);
            }

            if (abe == "laser" && be == "face") {

              if (l >= 0) {
                l = l + 1;
                activity.gameToast("Shield only blocks one laser hit-Hit #" + l);

                if (l == 2) destroy(1);
              } else if (l < 0) {
                activity.gameToast("Super Shield active");
                l = l + 1;
              }
            } else if (abe == "roof" || be == "roof") {
              Enemy.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter());
              Enemy2.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter());
              Enemy3.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter());
            } else if (abe == "right" || be == "right") {
              Enemy.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter());
              Enemy2.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter());
              Enemy3.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter());
            } else if (abe == "ground" || be == "ground") {
              Enemy.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter());
              Enemy2.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter());
              Enemy3.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter());
            } else if (abe == "enemy" && be == "face") {

              if (l >= 0) {
                l = l + 1;
                activity.gameToast("Hit #" + l);
                if (l == 3) destroy(1);
              } else if (l < 0) {

                if (dead == 0) {
                  enemy.setVisible(false);
                  Enemy.setActive(false);
                  dead = dead + 1;
                  l = l + 1;
                  activity.gameToast("Enemy eleminated");
                } else if (dead == 1) {
                  enemy2.setVisible(false);
                  Enemy2.setActive(false);
                  l = l + 1;
                  dead = dead + 1;
                  activity.gameToast("Enemy 2 eleminated");
                } else if (l == -3) {
                  enemy3.setVisible(false);
                  Enemy3.setActive(false);
                  l = l + 1;
                  dead = dead + 1;
                  activity.gameToast("Enemy 3 eleminated");
                } else {
                  l = l + 1;
                }
              }
            }
          }

          @Override
          public void endContact(final Contact pContact) {}

          @Override
          public void preSolve(Contact contact, Manifold oldManifold) {}

          @Override
          public void postSolve(Contact contact, ContactImpulse impulse) {}
        });
  }
示例#24
0
 public float getHeight() {
   return bgRect.getHeightScaled();
 }
示例#25
0
  /** TODO So ugly :( Maybe make it its own class? */
  @Override
  public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    final Float x = pSceneTouchEvent.getX();
    final Float y = pSceneTouchEvent.getY();

    currentTile = this.tmxLayer.getTMXTileAt(x, y);

    // if the user pinches or dragtouches the screen then...
    if (this.mPinchZoomDetector != null) {

      this.mPinchZoomDetector.onTouchEvent(pSceneTouchEvent);
      if (this.mPinchZoomDetector.isZooming()) {
        this.mScrollDetector.setEnabled(false);
      } else if (!towerMove) {
        if (pSceneTouchEvent.isActionDown()) {
          this.mScrollDetector.setEnabled(true);
        }
        this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
      }

    } else {
      this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
    }

    if (pSceneTouchEvent.isActionDown()) {
      downCoords.set(x, y);

      SubMenuManager.setReticalPosition(-500.0f, -500.0f);

      Log.i("Detaching now", "NOW");
      SubMenuManager.remove();
      this.unregisterTouchArea(SubMenuManager.getDeleteSprite());

      panel.detachTowerUpgradeDeleteText();
      panel.detachTowerTextDescription();
      panel.attachTowerTextDescription(pointOnTile(TouchEvent.ACTION_DOWN));
    }

    Class<?> tClass;
    if (pSceneTouchEvent.isActionMove()) {

      tClass = pointOnTile(TouchEvent.ACTION_MOVE);
      if (tClass != null && !towerMove) {
        dragTower = null;
        towerMove = true;
        if (tClass.equals(TurretTower.class) && canAfford(TurretTower.COST)) {
          dragTower = new TurretTower(x, y, resourceManager.getTurretTowerRegion());
        } else if (tClass.equals(DartTower.class) && canAfford(DartTower.COST)) {
          dragTower = new DartTower(x, y, resourceManager.getDartTowerRegion());
        } else if (tClass.equals(FlameTower.class) && canAfford(FlameTower.COST)) {
          dragTower = new FlameTower(x, y, resourceManager.getFlameTowerRegion());
        } else if (tClass.equals(IceTower.class) && canAfford(IceTower.COST)) {
          dragTower = new IceTower(x, y, resourceManager.getIceTowerRegion());
        } else if (tClass.equals(SpikeTower.class) && canAfford(SpikeTower.COST)) {
          dragTower = new SpikeTower(x, y, resourceManager.getSpikeTowerRegion());
        } else towerMove = false;

        if (dragTower != null) {
          dragTower.getEntity().setZIndex(2);
          dragTower.getEntity().setScale(0.5f);

          activity.runOnUpdateThread(
              new Runnable() {
                @Override
                public void run() {
                  attachChild(dragTower.getEntity());

                  try {
                    attachChild(SubMenuManager.getReticle(dragTower));
                  } catch (Exception e) {
                  }
                  sortChildren();
                }
              });
          tClass = null;
        }

      }

      // Moving an active drag tower
      else if (towerMove) {
        if (pointOnMap(x, y)) {

          dragTower.setPosition(
              currentTile.getTileX() - GameMap.getTileSize() / 2,
              currentTile.getTileY() - GameMap.getTileSize() / 2);

          if (highlightTile == null) {
            highlightTile =
                new Rectangle(
                    currentTile.getTileX(),
                    currentTile.getTileY(),
                    GameMap.getTileSize(),
                    GameMap.getTileSize(),
                    activity.getVertexBufferObjectManager());
            highlightTile.setTag(777);
            highlightTile.setZIndex(1);
            this.attachChild(highlightTile);
            this.sortChildren();
          } else {
            highlightTile.setPosition(currentTile.getTileX(), currentTile.getTileY());
          }

          if (!inLegitimatePosition(currentTile)) {
            highlightTile.setColor(Color.RED);
          } else {
            highlightTile.setColor(Color.BLUE);
          }

          // if you drag the dragtower off the map, and then back on, we need to be able to tag it
          // so we can display the highlight tile again
          if (this.getChildByTag(777) == null) {
            this.attachChild(highlightTile);
            this.sortChildren();
          }
        }
        // if point NOT on map
        else {
          if (highlightTile != null) {
            detachHighlightTile();
          }
          dragTower.setPosition(
              pSceneTouchEvent.getX() - dragTower.getEntity().getWidth() / 2,
              pSceneTouchEvent.getY() - dragTower.getEntity().getHeight() / 2);
        }
      }
    } else if (pSceneTouchEvent.isActionUp()) {

      if (zooming) {
        fingerOnSceneCount--;

        if (fingerOnSceneCount == 0) {
          zooming = false;
          setUserDataforTowerTiles("");

          for (TowerTile tile : panel.getTiles()) {
            tile.returnOnMoved();
          }
        }
      }

      if (towerMove) {
        towerMove = false;

        if (currentTile != null
            && highlightTile != null
            && highlightTile.getColor().equals(Color.BLUE)) {

          // Add the tile to the blocked list
          blockedTileList.add(currentTile);

          towers.add(dragTower);
          SubMenuManager.getReticle(dragTower).detachSelf();

          // need to get it out of the scene so that the next dragtower doesn't have to start with
          // it from where the
          // previous tower was placed
          SubMenuManager.setReticalPosition(-500.0f, -500.0f);

          // Nothing is free in this world
          this.payAmount(dragTower.getCost());

          // If we are in the middle of a wave, the AStarPath class must update
          // the path since there is now a new tower on the field
          updateAffectedEnemies(currentTile, aStarHelper.isNavigating());
        } else {
          removeCurrentTower(false);
        }

        if (highlightTile != null) {
          detachHighlightTile();
        }
      } else if (Math.abs(downCoords.x - x) < 15.0f && Math.abs(downCoords.y - y) < 15.0f) {

        final ITower tower = pointOnExistingTower(x, y);
        if (tower != null) {
          this.attachChild(SubMenuManager.display(tower));
          Log.i("Reticle", "Visible? " + SubMenuManager.getReticle(tower).isVisible() + "");
          panel.attachTowerUpgradeDeleteText(tower);

          if (camera.getZoomFactor() - 1.0f < 0.00005f && camera.getYMin() < 0.00005f) {

            final float displacement = tower.getRadius() - tower.getEntity().getHeightScaled() / 2;
            if (tower.getY() == -20.0f) {
              camera.set(
                  camera.getXMin(),
                  camera.getYMin() - displacement,
                  camera.getXMax(),
                  camera.getYMax() - displacement);
            } else if (tower.getY() == 340.0f) {
              camera.set(
                  camera.getXMin(),
                  camera.getYMin() + displacement,
                  camera.getXMax(),
                  camera.getYMax() + displacement);
            }
          }
        }
      }
    }
    return true;
  }
示例#26
0
  /**
   * The constructor for the background class is where the background is created. It takes
   * parameters from the BaseLevel class, which are received from the JSON file for each level.. It
   * loads the textures in first. Then, a check is done to see what kind of level I am dealing with,
   * and if it is bonus, I set the walls, as the level uses the accelerometer. Otherwise I add the
   * background and it sets the parallax background.
   *
   * @param base_class
   * @param image -image passsed through from the JSON parser to be part of the background
   * @param sizeY - Y size of the image
   * @param sizeX - X size of the image
   * @param posX - X pos of the image
   * @param posY - Y pos of the image
   * @param pX - Parrallax
   * @param pY - Parralax
   */
  public Background(
      base_class my_base_class,
      String image,
      int sizeX,
      int sizeY,
      int posX,
      int posY,
      String pX,
      String pY) {
    base = my_base_class;

    float parallaxX = Float.parseFloat(pX);
    float parallaxY = Float.parseFloat(pY);

    /* Here I am loading in the background, I define the size and the image name and load it in to memory */
    backgroundTextureAtlas =
        new BitmapTextureAtlas(
            base.getTextureManager(), sizeX, sizeY, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    backgroundTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            backgroundTextureAtlas, base, image, 0, 0);
    backgroundTextureAtlas.load();

    if (BaseLevel.typeOfLevel.equals("bonus")) {
      /* This is the code to create a wall around the edge of the phone screen  */
      final Rectangle ground =
          new Rectangle(
              0, base.CAMERA_HEIGHT - 35, base.CAMERA_WIDTH, 0, base.vertexBufferObjectManager);
      final Rectangle roof =
          new Rectangle(0, 35, base.CAMERA_WIDTH, 0, base.vertexBufferObjectManager);
      final Rectangle left =
          new Rectangle(40, 0, 0, base.CAMERA_HEIGHT, base.vertexBufferObjectManager);
      final Rectangle right =
          new Rectangle(
              base.CAMERA_WIDTH - 40, 0, 0, base.CAMERA_HEIGHT, base.vertexBufferObjectManager);

      ground.setUserData("wall");
      roof.setUserData("wall");
      left.setUserData("wall");
      right.setUserData("wall");

      /* set the wall and then attach it to a scene */
      final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
      PhysicsFactory.createBoxBody(base.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef)
          .setUserData("wall");
      PhysicsFactory.createBoxBody(base.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef)
          .setUserData("wall");
      PhysicsFactory.createBoxBody(base.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef)
          .setUserData("wall");
      PhysicsFactory.createBoxBody(base.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef)
          .setUserData("wall");

      base.getEngine().getScene().attachChild(ground);
      base.getEngine().getScene().attachChild(roof);
      base.getEngine().getScene().attachChild(left);
      base.getEngine().getScene().attachChild(right);
    }

    BaseLevel.ParallaxBackground.attachParallaxEntity(
        new Parallax2dEntity(
            parallaxX,
            parallaxY,
            new Sprite(posX, posY, backgroundTextureRegion, base.getVertexBufferObjectManager()),
            false,
            false));
  }
  @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);
  }
示例#28
0
 public void setX(float pX) {
   bgRect.setX(pX);
   fgRect.setX(pX + FGRECT_MARGIN_WIDTH);
   fgText.setX(pX + BGRECT_MARGIN_WIDTH);
 }
示例#29
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;
  }
示例#30
0
  public Bullet() {
    sprite =
        new Rectangle(0, 0, 2, 5, BaseActivity.getSharedInstance().getVertexBufferObjectManager());

    sprite.setColor(0.01904f, 0.00113f, 0.00086f);
  }