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);
  }
 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;
 }
Пример #3
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);
  }
  @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;
  }
Пример #5
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);
  }
Пример #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
  /**
   * 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);
  }
Пример #8
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

          }
        });
  }
Пример #9
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) {}
        });
  }
  @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);
  }
Пример #12
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;
  }
Пример #13
0
  public Bullet() {
    sprite =
        new Rectangle(0, 0, 2, 5, BaseActivity.getSharedInstance().getVertexBufferObjectManager());

    sprite.setColor(0.01904f, 0.00113f, 0.00086f);
  }
Пример #14
0
  @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);
  }
Пример #15
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);
    }
  }