protected void createExplosionMark(float x, float y) {

    final Sprite MARK =
        new TextureManagedSprite(
            0,
            0,
            HudRegions.region_explosion_mark,
            EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) {
          private float elapsedAliveTime;

          @Override
          protected void onManagedUpdate(float pSecondsElapsed) {
            this.elapsedAliveTime += pSecondsElapsed;

            if (this.elapsedAliveTime >= SessionScene.TARGET_ALIVE_EXPLOSION_MARK_TIME) {
              this.setAlpha(this.getAlpha() - 0.002f);
              if ((int) (this.getAlpha() * 1000) <= 0) EntityUtils.safetlyDetachAndDispose(this);
            }

            super.onManagedUpdate(pSecondsElapsed);
          }
        };
    MARK.setScale(2f);
    MARK.setX(x - MARK.getWidth() / 2f);
    MARK.setY(y - MARK.getHeight() / 2f);

    this.attachChild(MARK);
  }
Exemplo n.º 2
0
  public void addTarget() {
    Random rand = new Random();

    int minX = 0;
    int maxX = (int) (mCamera.getWidth() - activity.enemySprite.getWidth());
    int rangeX = maxX - minX;
    int y = (int) -activity.enemySprite.getHeight();
    int x = rand.nextInt(rangeX) - minX;

    Sprite target = new Sprite(x, y, activity.enemyRegion, activity.getVertexBufferObjectManager());
    target.setSize(
        activity.mCamera.getWidth() / 10.8f * 1.5f, activity.mCamera.getWidth() / 10.8f * 1.5f);

    target.setZIndex(3);

    attachChild(target);

    int minDuration = 3;
    int maxDuration = 6;
    int rangeDuration = maxDuration - minDuration;
    int actualDuration = rand.nextInt(rangeDuration) + minDuration;
    int actualMoveX = rand.nextInt((int) (mCamera.getWidth() - target.getWidth()));

    MoveModifier mod =
        new MoveModifier(
            actualDuration,
            target.getX(),
            actualMoveX,
            target.getY(),
            mCamera.getHeight() + target.getHeight());

    target.registerEntityModifier(mod.deepCopy());

    enemiesToBeAdded.add(target);
  }
  private void effectRate(Rate mRate) {
    // Log.e(tag, "effectRate");

    Sprite sprite = fastSprite;

    switch (mRate) {
      case FAST:
        sprite = new Sprite(0, 0, Region.fast, vbom);
        break;
      case SUPER_FAST:
        sprite = new Sprite(0, 0, Region.superFast, vbom);
        break;
      case COMPLETE:
        sprite = new Sprite(0, 0, Region.complete, vbom);
        break;
      case WRONG:
        sprite = new Sprite(0, 0, Region.wrong, vbom);
        break;
      case SLOW:
        sprite = new Sprite(0, 0, Region.slow, vbom);
        break;
    }

    setToCenter(sprite);
    sprite.setScale(0);
    attachChild(sprite);

    sprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(0.2f, 0, 1, sprite.getWidth() / 2, sprite.getHeight() / 2),
            new AlphaModifier(0.3f, 1, 1),
            new AlphaModifier(0.1f, 1, 0)));
  }
 private void checkForCollisionsWithTowers(Ring ring) {
   Stack stack = null;
   Sprite tower = null;
   if (ring.collidesWith(mTower1)
       && (mStack1.size() == 0 || ring.getmWeight() < ((Ring) mStack1.peek()).getmWeight())) {
     stack = mStack1;
     tower = mTower1;
   } else if (ring.collidesWith(mTower2)
       && (mStack2.size() == 0 || ring.getmWeight() < ((Ring) mStack2.peek()).getmWeight())) {
     stack = mStack2;
     tower = mTower2;
   } else if (ring.collidesWith(mTower3)
       && (mStack3.size() == 0 || ring.getmWeight() < ((Ring) mStack3.peek()).getmWeight())) {
     stack = mStack3;
     tower = mTower3;
   } else {
     stack = ring.getmStack();
     tower = ring.getmTower();
   }
   ring.getmStack().remove(ring);
   if (stack != null && tower != null && stack.size() == 0) {
     ring.setPosition(
         tower.getX() + tower.getWidth() / 2 - ring.getWidth() / 2,
         tower.getY() + tower.getHeight() - ring.getHeight());
   } else if (stack != null && tower != null && stack.size() > 0) {
     ring.setPosition(
         tower.getX() + tower.getWidth() / 2 - ring.getWidth() / 2,
         ((Ring) stack.peek()).getY() - ring.getHeight());
   }
   stack.add(ring);
   ring.setmStack(stack);
   ring.setmTower(tower);
 }
Exemplo n.º 5
0
  public boolean birdUnderAim(Bird obj) {

    float x = (aim.getX() + aim.getX() + aim.getWidth()) / 2;
    float y = (aim.getY() + aim.getY() + aim.getHeight()) / 2;
    if (x > obj.getX() && x < obj.getX() + obj.getWidth())
      if (y > obj.getY() && y < obj.getY() + obj.getHeight()) {
        return true;
      }
    return false;
  }
  private void effectReadyGo() {
    // Log.e(tag, "effectReadyGo");

    this.attachChild(readySprite);
    setToCenter(readySprite);
    readySprite.setScale(0);

    this.attachChild(goSprite);
    setToCenter(goSprite);
    goSprite.setScale(0);

    readySprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(
                0.7f, 0, 1, readySprite.getWidth() / 2, readySprite.getHeight() / 2),
            new AlphaModifier(0.75f, 1, 1),
            new AlphaModifier(0.3f, 1, 0)));

    goSprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(1.7f, 0, 0, goSprite.getWidth() / 2, goSprite.getHeight() / 2),
            new ScaleAtModifier(0.7f, 0, 1, goSprite.getWidth() / 2, goSprite.getHeight() / 2),
            new AlphaModifier(0.75f, 1, 1),
            new AlphaModifier(
                0.3f,
                1,
                0,
                new IEntityModifier.IEntityModifierListener() {
                  @Override
                  public void onModifierStarted(
                      IModifier<IEntity> iEntityIModifier, IEntity iEntity) {}

                  @Override
                  public void onModifierFinished(
                      IModifier<IEntity> iEntityIModifier, IEntity iEntity) {
                    // Log.e(tag, "onModifierFinished");
                    initTime();
                    taskInit();
                  }
                })));
  }
Exemplo n.º 7
0
  private void createBackground() {
    background =
        new Sprite(0, 0, resourcesManager.game_background_region, vbom) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }

          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            Log.e("GAME", "BACK_ON_TACH");
            return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    this.registerTouchArea(background);
    attachChild(background);
    camera.setCenter(background.getWidth() / 2, background.getHeight() / 2);
    camera.setBounds(0, 0, background.getWidth(), background.getHeight());
    camera.setBoundsEnabled(true);
  }
  public void effectMiss(int mPosition) {

    int[] x = {50, 150, 250};

    // Sprite sprite = new Sprite(0, 0, Region.miss, vbom);
    Sprite sprite = getMissFromPool();
    // if (sprite.getParent() != this) {
    this.attachChild(sprite);
    // }
    setToCenter(sprite);
    sprite.setX(x[mPosition]);

    sprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(0.3f, 0, 1, sprite.getWidth() / 2, sprite.getHeight() / 2),
            new AlphaModifier(0.3f, 1, 1),
            new AlphaModifier(0.3f, 1, 0)));
  }
Exemplo n.º 9
0
  public boolean areColliding() {
    circle.setPosition(circle.getX(), circle.getY() + squareSpeed);
    rectangle.setPosition(rectangle.getX(), rectangle.getY() - circleSpeed);

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

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

    return rectangle.collidesWith(circle);
  }
Exemplo n.º 10
0
  // Creer la scene affiche e l'ecran.
  private void initSplashScene() {
    mCurrentScene = new Scene();
    // Sprite qui va contenir le logo
    Sprite splash =
        new Sprite(0, 0, manager.mSplashLogo, mEngine.getVertexBufferObjectManager()) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }
        };
    splash.setScale(0.8f);
    // Ajoute le sprite splash e la scene.
    splash.setPosition(
        (mCamera.getWidth() - splash.getWidth()) * 0.5f,
        (mCamera.getHeight() - splash.getHeight() - 150f) * 0.5f);
    mCurrentScene.attachChild(splash);

    // Attache le titre
    mCurrentScene.attachChild(mTitle1);
    mCurrentScene.attachChild(mTitle2);
  }
Exemplo n.º 11
0
  public GameDialogBox(HUD hud, String message, int back, boolean text, ButtonSprite... buttons) {
    super();
    dismissed = false;
    this.buttons = buttons;
    this.hud = hud;
    this.text = text;

    ResourcesManager resourcesManager = ResourcesManager.getInstance();

    // Attach Background
    switch (back) {
      case 1:
        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background, resourcesManager.vbom));
        break;

      case 2:
        if (resourcesManager.dialog_background2 == null) {
          Log.d("Null", "null");
        }

        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background2, resourcesManager.vbom));
        break;

      case 3:
        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background3, resourcesManager.vbom));
        break;
      default:
        break;
    }
    if (text) {

      messageText =
          new Text(
              240,
              400,
              resourcesManager.cartoon_font_white,
              message,
              new TextOptions(
                  AutoWrap.WORDS,
                  backgroundSprite.getWidth() - 100,
                  HorizontalAlign.CENTER,
                  Text.LEADING_DEFAULT),
              resourcesManager.vbom);

      hud.attachChild(messageText);
      if (400 + (backgroundSprite.getHeight() / 2) - 50 + (messageText.getHeight() / 2)
          > 400 + backgroundSprite.getHeight() / 2) {
        messageText.setPosition(240, 400 + backgroundSprite.getHeight() / 2 - 100);
        j = 400 + (backgroundSprite.getHeight() / 2 - 100) - messageText.getHeight() - 25;
      } else {
        messageText.setPosition(240, 400 + backgroundSprite.getHeight() / 2 - 50);
        j = 400 + (backgroundSprite.getHeight() / 2 - 50) - messageText.getHeight() - 25;
      }

    } else {
      j = 400 + ((buttons.length * 100) / 2);
    }

    int i = 0;
    for (ButtonSprite button : buttons) {
      hud.attachChild(button);
      button.setPosition(240, j - (100 * i));
      hud.registerTouchArea(button);
      i++;
    }

    // hud.registerTouchArea(okayButton);
  }
Exemplo n.º 12
0
  public void enemyCollide(Sprite _target, Iterator<Sprite> targets) {
    if (activity.isShield) {
      activity.isShield = false;
      detachChild(activity.shieldSprite);
      createExplosion(
          _target.getX() + _target.getWidth() / 2,
          _target.getY() + _target.getHeight() / 2,
          Color.RED,
          15,
          mCamera.getWidth() / 10);

      createExplosion(
          ball.sprite.getX() + ball.sprite.getWidth() / 2,
          ball.sprite.getY() + ball.sprite.getHeight() / 2,
          Color.BLUE,
          5,
          mCamera.getWidth() / 17);

      if (activity.isSfx()) activity.dropShieldSound.play();

      removeSprite(_target, targets);
      addTarget();
    } else {
      if (!isLoseNow) {
        if (activity.isMusic()) {
          activity.battleTheme.pause();
          activity.battleTheme.seekTo(0);
        }
        if (activity.isSfx()) {
          activity.explSound.play();
        }
        activity.score.onLose();
        activity.score.score -= 20;
        activity.editor.putInt("time", activity.prefs.getInt("time", 0) - 2);
        activity.editor.commit();

        activity.vibrator.vibrate(300);

        createExplosion(
            ball.sprite.getX() + ball.sprite.getWidth() / 2,
            ball.sprite.getY() + ball.sprite.getHeight() / 2,
            Color.RED,
            10,
            mCamera.getWidth() / 20);

        detachChild(ball.sprite);
        detachChild(scoreText);

        DelayModifier dMod =
            new DelayModifier(2) {
              @Override
              protected void onModifierFinished(IEntity pItem) {
                if (activity.isMusic()) activity.awesomeness.resume();
                restart();
              }
            };
        registerEntityModifier(dMod);
        isLoseNow = true;
      }
    }
  }
 private void setToCenter(Sprite mSprite) {
   mSprite.setPosition(
       Config.Camera.WIDTH / 2 - mSprite.getWidth() / 2,
       Config.Camera.HEIGHT / 2 - mSprite.getHeight() / 2);
 }