@Override
  public void onPauseGame() {
    if (!isDrawView || !isPreView) {
      return;
    }
    Log.i(TAG, "-- onPauseGame --");
    this.unregisterUpdateHandler(updateHandler);
    CUBIC_SLOT[0] = false;
    CUBIC_SLOT[1] = false;
    mArrowSprite.setVisible(false);
    mSuzuAniSprite.stopAnimation(0);
    mShishiAniSprite.stopAnimation();
    mShishiAniSprite.clearEntityModifiers();
    mShishiAniSprite.resetLocalToFirst();
    mShishiAniSprite.setVisible(false);

    for (int i = 0; i < mCubicEntity.length; i++) {
      if (mCubicEntity[i] != null) {
        mCubicEntity[i].clearAll();
      }
    }

    if (faceSequenceEntityModifier != null) {
      this.unregisterEntityModifier(faceSequenceEntityModifier);
      faceSequenceEntityModifier = null;
    }

    for (int i = 1; i < mTabSprite.length; i++) {
      mTabSprite[i].setVisible(false);
    }
  }
示例#2
0
  public void explode(
      final BulleComponent bulleComponent,
      TiledTextureRegion textureRegionExplosion,
      final OnExplodeBulle onExplodeBulle) {
    final AnimatedSprite sprite =
        new AnimatedSprite(
            (bulleComponent.getWidth() * -0.15f) + bulleComponent.getX(),
            (bulleComponent.getHeight() * -0.15f + bulleComponent.getY()),
            textureRegionExplosion,
            this.getVertexBufferObjectManager());

    sprite.setSize(bulleComponent.getWidth() * 1.3f, bulleComponent.getHeight() * 1.3f);

    long[] frameDurration = {
      25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 50, 50, 50, 50, 50, 50, 50,
      50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
      50, 50
    };

    final int w = frameDurration.length / 2;

    sprite.animate(
        frameDurration,
        new IAnimationListener() {

          @Override
          public void onAnimationStarted(AnimatedSprite pAnimatedSprite, int pInitialLoopCount) {}

          @Override
          public void onAnimationFrameChanged(
              AnimatedSprite pAnimatedSprite, int pOldFrameIndex, int pNewFrameIndex) {
            if (pOldFrameIndex == 14) {
              bulleComponent.setVisible(false);
            }
          }

          @Override
          public void onAnimationLoopFinished(
              AnimatedSprite pAnimatedSprite, int pRemainingLoopCount, int pInitialLoopCount) {
            onExplodeBulle.onAnimationFinished();

            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    getEngine().getScene().unregisterTouchArea(sprite);
                    getEngine().getScene().detachChild(sprite);
                  }
                });
          }

          @Override
          public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {}
        });

    getEngine().getScene().attachChild(sprite);
  }
 public void nextTileAnimatedSprite(final AnimatedSprite pAnimatedSprite) {
   int index = pAnimatedSprite.getCurrentTileIndex();
   if (index >= pAnimatedSprite.getTileCount() - 1) {
     index = 0;
   } else {
     index++;
   }
   pAnimatedSprite.setCurrentTileIndex(index);
 }
示例#4
0
  private void toggleSpeedFactor() {
    speedFactor = (speedFactor == 0.5f) ? 1.0f : 0.5f;

    int startIndex = startButton.getCurrentTileIndex();

    if (startIndex < 2) startButton.setCurrentTileIndex((startIndex + 1) % 2);
    else {
      if (startIndex == 2) startButton.setCurrentTileIndex(3);
      else startButton.setCurrentTileIndex(2);
    }
  }
示例#5
0
 /**
  * Attaches the move modifiers to each of the enemies in the next wave and attaches the enemies to
  * the scene
  */
 private void startCurrentWave() {
   if (waveFinished) {
     startButton.setCurrentTileIndex(startButton.getCurrentTileIndex() + 2);
     Log.i("START WAVE", "START WAVE");
     waveFinished = false;
     initializedNewWave = false;
     waveGenerator.startWave();
     startInWaveUpdateHandlers();
   } else {
     toggleSpeedFactor();
   }
 }
    public CubicEntity(
        float pX,
        float pY,
        int pCubic,
        final ITiledTextureRegion pCubicStart,
        final ITiledTextureRegion pCubicTurn,
        final ITiledTextureRegion pCubicStop,
        final ITiledTextureRegion pCubicTurnOption[],
        ITextureRegion pTextureRegion) {
      super(pX, pY, pTextureRegion, mVertexBufferObjectManager);
      setAlpha(0.0f);
      TYPE = pCubic;
      mCubicStartAniSprite = new AnimatedSprite(0, 0, pCubicStart, mVertexBufferObjectManager);
      this.attachChild(mCubicStartAniSprite);
      mCubicStartAniSprite.setVisible(false);

      float turnX = getWidth() - pCubicTurn.getWidth();
      float turnY = getHeight() - pCubicTurn.getHeight();
      mCubicTurnAniSprite =
          new AnimatedSprite(turnX - 15, turnY - 15, pCubicTurn, mVertexBufferObjectManager);
      this.attachChild(mCubicTurnAniSprite);
      mCubicTurnAniSprite.setVisible(false);

      for (int i = 0; i < mCubicTurnOptionAniSprite.length; i++) {
        float turnOpX = getWidth() - pCubicTurnOption[i].getWidth();
        float turnOpY = getHeight() - pCubicTurnOption[i].getHeight();
        mCubicTurnOptionAniSprite[i] =
            new AnimatedSprite(turnOpX, turnOpY, pCubicTurnOption[i], mVertexBufferObjectManager);
        this.attachChild(mCubicTurnOptionAniSprite[i]);
        mCubicTurnOptionAniSprite[i].setVisible(false);
      }

      float stopX = getWidth() - pCubicTurn.getWidth();
      float stopY = getHeight() - pCubicTurn.getHeight();
      mCubicStopAniSprite =
          new AnimatedSprite(stopX - 15, stopY - 15, pCubicStop, mVertexBufferObjectManager);
      this.attachChild(mCubicStopAniSprite);
      mCubicStopAniSprite.setVisible(false);

      float scrollX = turnX + pCubicTurn.getWidth() / 2 - mScrollLeftTextureRegion.getWidth();
      float scrollY = turnY + pCubicTurn.getHeight() - mScrollLeftTextureRegion.getHeight();
      mScrollLeftSprite =
          new Sprite(scrollX, scrollY, mScrollLeftTextureRegion, mVertexBufferObjectManager);
      this.attachChild(mScrollLeftSprite);
      mScrollLeftSprite.setVisible(false);

      mScrollLeftSprite.registerEntityModifier(
          new LoopEntityModifier(
              new SequenceEntityModifier(
                  new AlphaModifier(0.5f, 0.2f, 1.0f), new AlphaModifier(0.5f, 1.0f, 0.2f))));
    }
    private void action(int action) {
      mCubicStartAniSprite.setVisible(false);
      mCubicStartAniSprite.stopAnimation(0);
      switch (action) {
        case ACTION_TURN_LEVEL_1:
        case ACTION_TURN_LEVEL_2:
        case ACTION_TURN_LEVEL_3:
          ACTION = action;
          final Body body = (Body) this.getUserData();
          final Vector2 vector2 = Vector2Pool.obtain(body.getPosition());
          int frame[] = new int[] {0, 1};
          body.setAngularDamping(1.2f);
          vector2.x = vector2.x / 3;
          vector2.y = vector2.y / 3;
          if (action == ACTION_TURN_LEVEL_2) {
            frame = new int[] {2, 3};
            body.setAngularDamping(2.2f);
            vector2.x = vector2.x / 2;
            vector2.y = vector2.y / 2;
          } else if (action == ACTION_TURN_LEVEL_3) {
            frame = new int[] {4, 5};
            body.setAngularDamping(3.2f);
          }
          Vol3Osyougatsu.OGG_A3_A_5_KOMATEI.play();
          mCubicTurnAniSprite.animate(new long[] {250, 250}, frame, -1);
          mCubicTurnAniSprite.setVisible(true);

          body.setActive(true);
          Log.i(TAG, "body.getPosition " + vector2);
          vector2.x = random(vector2.x) + new Random().nextFloat();
          vector2.y = random(vector2.y) + new Random().nextFloat();
          body.setLinearVelocity(vector2);
          Log.i(TAG, "body.getPosition change " + vector2);
          this.unregisterUpdateHandler(timerHandler);
          this.registerUpdateHandler(
              timerHandler =
                  new TimerHandler(
                      6f,
                      new ITimerCallback() {

                        @Override
                        public void onTimePassed(TimerHandler timerHandler) {
                          // Stop Turn
                          stopTurn();
                        }
                      }));
          break;
      }
    }
        @Override
        public boolean onAreaTouched(
            TouchEvent pSceneTouchEvent,
            ITouchArea pTouchArea,
            float pTouchAreaLocalX,
            float pTouchAreaLocalY) {
          newPlayerPositionX = pSceneTouchEvent.getX();
          newPlayerPositionY = pSceneTouchEvent.getY();
          oldPlayerPositionX = playerSprite.getX();
          oldPlayerPositionY = playerSprite.getY();

          System.out.println("NewPosition:" + newPlayerPositionX + "," + newPlayerPositionY);

          return true;
        }
  private void actionSuzuShiShi() {
    // If running return false
    if (mSuzuAniSprite.isAnimationRunning() || mShishiAniSprite.isAnimationRunning()) {
      return;
    }
    Vol3Osyougatsu.OGG_A3_A_4_SUZU2.play();
    mSuzuAniSprite.animate(
        new long[] {150, 150},
        new int[] {1, 2},
        4,
        new IAnimationListener() {

          @Override
          public void onAnimationStarted(AnimatedSprite arg0, int arg1) {}

          @Override
          public void onAnimationLoopFinished(AnimatedSprite arg0, int arg1, int arg2) {}

          @Override
          public void onAnimationFrameChanged(AnimatedSprite arg0, int arg1, int arg2) {}

          @Override
          public void onAnimationFinished(AnimatedSprite arg0) {
            mSuzuAniSprite.setCurrentTileIndex(0);
            mShishiAniSprite.animate(new long[] {300, 300});
            mShishiAniSprite.registerEntityModifier(
                new MoveXModifier(
                    4.5f,
                    mShishiAniSprite.getmXFirst(),
                    -mShishiAniSprite.getWidth(),
                    new IEntityModifierListener() {

                      @Override
                      public void onModifierStarted(IModifier<IEntity> arg0, IEntity arg1) {
                        mShishiAniSprite.setVisible(true);
                        Vol3Osyougatsu.OGG_A3_A_4_KACHI2.play();
                      }

                      @Override
                      public void onModifierFinished(IModifier<IEntity> arg0, IEntity arg1) {
                        mShishiAniSprite.stopAnimation();
                        mShishiAniSprite.resetLocalToFirst();
                        mShishiAniSprite.setVisible(false);
                      }
                    }));
          }
        });
  }
    // Function Stop Turn when out time and collision "shishi"
    public void stopTurn() {
      Vol3Osyougatsu.OGG_A3_A_5_KOMATEI.stop();
      ACTION = ACTION_TURN_STOP;
      for (int i = 0; i < mCubicTurnOptionAniSprite.length; i++) {
        mCubicTurnOptionAniSprite[i].stopAnimation();
        mCubicTurnOptionAniSprite[i].setVisible(false);
      }
      mCubicTurnAniSprite.stopAnimation(0);
      mCubicTurnAniSprite.setVisible(false);
      removePhysics(CubicEntity.this);
      mCubicStopAniSprite.animate(
          new long[] {200, 1000},
          new int[] {0, 1},
          0,
          new IAnimationListener() {

            @Override
            public void onAnimationStarted(AnimatedSprite arg0, int arg1) {
              mCubicStopAniSprite.setVisible(true);
            }

            @Override
            public void onAnimationLoopFinished(AnimatedSprite arg0, int arg1, int arg2) {}

            @Override
            public void onAnimationFrameChanged(AnimatedSprite arg0, int arg1, int arg2) {
              Log.i("XXX", arg1 + " Changed ID : " + arg2);
              int index = arg2;
              if (index == -1) {
                index = 0;
              }
              if (index >= 2) return;
              float width = mCubicStopAniSprite.getTiledTextureRegion().getWidth(index);
              float height = mCubicStopAniSprite.getTiledTextureRegion().getHeight(index);
              Log.i("XXX", width + " ~ " + height);
              mCubicStopAniSprite.setWidth(width);
              mCubicStopAniSprite.setHeight(height);
            }

            @Override
            public void onAnimationFinished(AnimatedSprite arg0) {
              CubicEntity.this.clearAll();
              mCubicChooseSpite[CubicEntity.this.TYPE].setVisible(true);
              CUBIC_SLOT[SLOT] = false;
              checkArrow();
            }
          });
    }
示例#11
0
  private void tvAction() {
    isTv = false;

    mTvAnimatedSprite.registerUpdateHandler(
        new TimerHandler(
            0.5f,
            true,
            new ITimerCallback() {
              int i = 1;

              @Override
              public void onTimePassed(TimerHandler pTimerHandler) {
                if (i < mTvAnimatedSprite.getTileCount()) {
                  mTvAnimatedSprite.setCurrentTileIndex(i);
                  if (i == 1) {
                    A19_05_ZA.play();
                    setVisibleHandDefault(false);
                    handAction(3);
                  } else if (i == 2) {
                    A19_05_DOMO4.play();
                  } else if (i == 3) {
                    A19_05_TYAIMASU.play();
                  } else if (i == 4) {
                    A19_05_ZAKU.play();
                  }
                  i++;
                } else {
                  mTvAnimatedSprite.setCurrentTileIndex(0);
                  mTvAnimatedSprite.clearUpdateHandlers();
                  isTv = true;
                  handDefault();
                }
              }
            }));
  }
    public void actionUp(final int action) {
      ACTION = ACTION_TURN_START;
      mScrollLeftSprite.setVisible(false);
      mScrollLeftSprite.clearEntityModifiers();
      mCubicStartAniSprite.animate(
          new long[] {300, 300, 300},
          new int[] {0, 1, 2},
          0,
          new IAnimationListener() {

            @Override
            public void onAnimationStarted(AnimatedSprite arg0, int arg1) {
              mCubicStartAniSprite.setVisible(true);
            }

            @Override
            public void onAnimationLoopFinished(AnimatedSprite arg0, int arg1, int arg2) {}

            @Override
            public void onAnimationFrameChanged(AnimatedSprite arg0, int arg1, int arg2) {}

            @Override
            public void onAnimationFinished(AnimatedSprite animatedSprite) {
              action(action);
            }
          });
    }
    private void touchToTurn(final int pAction) {
      Vol3Osyougatsu.OGG_A3_A_5_SPACE6.play();
      final int ran = new Random().nextInt(mCubicTurnOptionAniSprite.length);
      if (ran == 0) {
        ACTION = ACTION_TURN_GIRL;
      } else if (ran == 1) {
        ACTION = ACTION_TURN_BOY;
      } else if (ran == 2) {
        ACTION = ACTION_TURN_FUNGI;
      }
      mCubicTurnAniSprite.stopAnimation();
      mCubicTurnAniSprite.setVisible(false);
      mCubicTurnOptionAniSprite[ran].animate(
          new long[] {250, 250},
          new int[] {0, 1},
          2,
          new IAnimationListener() {

            @Override
            public void onAnimationStarted(AnimatedSprite arg0, int arg1) {
              mCubicTurnOptionAniSprite[ran].setVisible(true);
            }

            @Override
            public void onAnimationLoopFinished(AnimatedSprite arg0, int arg1, int arg2) {}

            @Override
            public void onAnimationFrameChanged(AnimatedSprite arg0, int arg1, int arg2) {}

            @Override
            public void onAnimationFinished(AnimatedSprite arg0) {
              mCubicTurnOptionAniSprite[ran].setVisible(false);
              mCubicTurnOptionAniSprite[ran].stopAnimation();
              ACTION = pAction;
              int frame[] = new int[] {0, 1};
              if (ACTION == ACTION_TURN_LEVEL_2) {
                frame = new int[] {2, 3};
              } else if (ACTION == ACTION_TURN_LEVEL_3) {
                frame = new int[] {4, 5};
              }
              // run back...
              mCubicTurnAniSprite.animate(new long[] {250, 250}, frame, -1);
              mCubicTurnAniSprite.setVisible(true);
            }
          });
    }
示例#14
0
  @Override
  public boolean onSceneTouchEvent(TouchEvent pSceneTouchEvent) {

    if (pSceneTouchEvent.isActionDown() && !personajeSaltando) {
      personajeSaltando = true;
      // Animar sprite central
      JumpModifier salto =
          new JumpModifier(
              1,
              spritePersonaje.getX(),
              spritePersonaje.getX(),
              spritePersonaje.getY(),
              spritePersonaje.getY(),
              -200);
      RotationModifier rotacion = new RotationModifier(1, 360, 0);
      ParallelEntityModifier paralelo =
          new ParallelEntityModifier(salto, rotacion) {
            @Override
            protected void onModifierFinished(IEntity pItem) {
              personajeSaltando = false;
              unregisterEntityModifier(this);
              super.onModifierFinished(pItem);
            }
          };
      spritePersonaje.registerEntityModifier(paralelo);
    }

    if (pSceneTouchEvent.isActionDown()) {
      // El usuario toca la pantalla
      float x = pSceneTouchEvent.getX();
      float y = pSceneTouchEvent.getY();
      spritePersonaje.setPosition(x, y);
    }
    if (pSceneTouchEvent.isActionMove()) {
      // El usuario mueve el dedo sobre la pantalla
      float x = pSceneTouchEvent.getX();
      float y = pSceneTouchEvent.getY();
      spritePersonaje.setPosition(x, y);
    }
    if (pSceneTouchEvent.isActionUp()) {
      // El usuario deja de tocar la pantalla
    }

    return super.onSceneTouchEvent(pSceneTouchEvent);
  }
 public static void clearEntityModifiers(AnimatedSprite s) {
   s.unregisterEntityModifiers(
       new IEntityModifier.IEntityModifierMatcher() {
         @Override
         public boolean matches(IModifier<IEntity> iEntityIModifier) {
           return true;
         }
       });
 }
示例#16
0
 @Override
 public void onPauseGame() {
   babyDontCry();
   this.mEngine.clearUpdateHandlers();
   this.mScene.clearUpdateHandlers();
   handDefault();
   mHandActionAniSprite.clearEntityModifiers();
   mTvAnimatedSprite.setCurrentTileIndex(0);
   mKaigaAnimatedSprite.setCurrentTileIndex(0);
   mDoorAnimatedSprite.setCurrentTileIndex(0);
   isTv = true;
   isClock = true;
   isDoor = true;
   isHand = true;
   isBabyCry = true;
   setTouchGimmic3(true);
   super.onPauseGame();
 }
示例#17
0
  @Override
  public void crearEscena() {
    // Lista de enemigos que aparecen del lado derecho
    listaEnemigos = new ArrayList<>();

    // Fondo animado
    AutoParallaxBackground fondoAnimado = new AutoParallaxBackground(1, 1, 1, 5);

    // Fondo atrás
    Sprite spriteFondoAtras =
        cargarSprite(ControlJuego.ANCHO_CAMARA / 2, ControlJuego.ALTO_CAMARA / 2, regionFondo);
    fondoAnimado.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(3, spriteFondoAtras));
    // Fondo frente
    Sprite spriteFondofrente =
        cargarSprite(
            ControlJuego.ANCHO_CAMARA / 2, ControlJuego.ALTO_CAMARA / 2, regionFondoFrente);
    fondoAnimado.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(8, spriteFondofrente));

    setBackground(fondoAnimado);

    // Personaje animado
    spritePersonaje =
        new AnimatedSprite(
            ControlJuego.ANCHO_CAMARA / 2,
            ControlJuego.ALTO_CAMARA / 2,
            regionPersonajeAnimado,
            actividadJuego.getVertexBufferObjectManager());
    spritePersonaje.animate(200); // 200ms entre frames, 1000/200 fps
    attachChild(spritePersonaje);

    // Crea el botón de PAUSA y lo agrega a la escena
    Sprite btnPausa =
        new Sprite(
            regionBtnPausa.getWidth(),
            ControlJuego.ALTO_CAMARA - regionBtnPausa.getHeight(),
            regionBtnPausa,
            actividadJuego.getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.isActionDown()) {
              pausarJuego();
            }
            return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    attachChild(btnPausa);
    registerTouchArea(btnPausa);

    // Crear la escena de PAUSA, pero NO lo agrega a la escena
    escenaPausa = new CameraScene(actividadJuego.camara);
    Sprite fondoPausa =
        cargarSprite(ControlJuego.ANCHO_CAMARA / 2, ControlJuego.ALTO_CAMARA / 2, regionPausa);
    escenaPausa.attachChild(fondoPausa);
    escenaPausa.setBackgroundEnabled(false);
  }
示例#18
0
  @Override
  public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
    if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
      int pX = (int) pSceneTouchEvent.getX();
      int pY = (int) pSceneTouchEvent.getY();

      if (mKaigaAnimatedSprite.contains(pX, pY)) {
        nextTileAnimatedSprite(mKaigaAnimatedSprite);
        A19_04_SAKUTON2.play();
      } else if (mTvAnimatedSprite.contains(pX, pY) && isTv && isHand) {
        isHand = false;
        tvAction();
        babyDontCry();
        resetBaby();
      } else if (checkContains(mClockAnimatedSprite, 29, 0, 171, 171, pX, pY) && isClock) {
        clockAction();
      } else if (checkContains(mDoorAnimatedSprite, 144, 26, 218, 383, pX, pY)
          && isDoor
          && isHand) {
        isHand = false;
        doorAction();
        babyDontCry();
        resetBaby();
      } else if (checkContains(mHandDefaultSprite, 227, 312, 454, 426, pX, pY) && isHand) {
        isHand = false;
        jankenAction();
        resetBaby();
      }
    }
    if (pSceneTouchEvent.isActionUp()) {
      if (mTempFringerAnimatedSprite != null) {
        if (mTempFringerAnimatedSprite.isAnimationRunning()) {
          mTempFringerAnimatedSprite.stopAnimation(0);
          mTempFringerAnimatedSprite = null;
        }
      }
      Log.d(TAG, " upup ,,,,,,,,,,,,,,,,,,,");
    }
    return true;
  }
示例#19
0
  // ===========================================================
  // Methods
  // ===========================================================
  private void addMario(final float pX, final float pY) {
    final Body body;

    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

    mario =
        new AnimatedSprite(pX, pY, this.mMarioTextureRegion, this.getVertexBufferObjectManager());
    mario.animate(new long[] {100, 100, 100}, 3, 5, true);
    body =
        PhysicsFactory.createBoxBody(
            this.mPhysicsWorld, mario, BodyType.DynamicBody, objectFixtureDef);

    marioRight =
        new AnimatedSprite(pX, pY, this.mMarioTextureRegion, this.getVertexBufferObjectManager());
    marioRight.animate(new long[] {100, 100, 100}, 3, 5, true);
    // bodyRight = PhysicsFactory.createBoxBody(this.mPhysicsWorld, marioRight,
    // BodyType.DynamicBody, objectFixtureDef);

    marioLeft =
        new AnimatedSprite(pX, pY, this.mMarioTextureRegion, this.getVertexBufferObjectManager());
    marioLeft.animate(new long[] {100, 100, 100}, 0, 2, true);
    // bodyLeft = PhysicsFactory.createBoxBody(this.mPhysicsWorld, marioLeft, BodyType.DynamicBody,
    // objectFixtureDef);

    // marioJump = new AnimatedSprite(pX, pY, this.mMarioJumpTextureRegion,
    // this.getVertexBufferObjectManager());
    // marioJump.animate(new long[] { 100, 1000 }, 0, 1, true);

    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mario, body, true, true));
    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(marioRight, body, true, true));
    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(marioLeft, body, true, true));
    // this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(marioJump, body, true,
    // true));

    mario.setUserData(body);
    this.mScene.attachChild(mario);

    marioRight.setUserData(body);
    this.mScene.attachChild(marioRight);

    marioLeft.setUserData(body);
    this.mScene.attachChild(marioLeft);

    // marioJump.setUserData(body);
    // this.mScene.attachChild(marioJump);

    marioRight.setVisible(false);
    marioLeft.setVisible(false);
    // marioJump.setVisible(false);
  }
示例#20
0
  /** Initializes paths and move modifiers of all enemies in the next wave */
  public void initializeNextWave() {

    Log.i("Init wave", "here");

    // If the previous wave was eliminated even before all enemies technically started, the time
    // handler
    // that handles their first move modifier would never get unregistered, putting the game in
    // limbo
    this.unregisterUpdateHandler(waveGenerator.getTimeHandler());

    if (startButton.getCurrentTileIndex() > 1)
      startButton.setCurrentTileIndex(startButton.getCurrentTileIndex() - 2);

    // The player wins the game!!
    if (waveCount == 70 && lives != 0) {
      displayWinScreen();
      return;
    }

    waveGenerator.initWave(waveCount);
    currentWave = waveGenerator.get(waveCount);
    enemies = (CopyOnWriteArrayList<Enemy>) currentWave.getEnemies();
    waveCount++;
    panel.setWaveText(waveCount);

    this.aStarHelper.finishWave();
    this.deadEnemies = 0;

    /** Just for debugging */
    for (Enemy enemy : currentWave.getEnemies()) {
      if (enemy == null) continue;
      enemy.setUserData(null);
      enemy.returnHealthToNormal();
    }
    for (ITower tower : towers) {
      tower.onWaveEnd();
    }
  }
示例#21
0
  @Override
  public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
    // TODO Auto-generated method stub

    this.mEngine.registerUpdateHandler(new FPSLogger());

    // createPopUpMenuScene();
    createStaticMenuScene();
    sprBanana = new AnimatedSprite(0, 0, regBanana, this.getVertexBufferObjectManager());
    sprBanana.setPosition(140, 120);

    this.mainMenuScene = new Scene();
    this.mainMenuScene.setBackground(new Background(0, 0, 0));

    Sprite menuBack =
        new Sprite(0, 0, this.mMenuTextureRegion, this.getVertexBufferObjectManager());

    this.mainMenuScene.attachChild(menuBack);
    this.mainMenuScene.getLastChild().attachChild(sprBanana);
    sprBanana.animate(100);
    this.mainMenuScene.setChildScene(mStaticMenuScene);
    pOnCreateSceneCallback.onCreateSceneFinished(mainMenuScene);
  }
示例#22
0
  private void doorAction() {
    final int ran = new Random().nextInt(DoorFrame.length);
    isDoor = false;
    A19_07_KONKON.play();
    this.mScene.registerUpdateHandler(
        new TimerHandler(
            1.0f,
            new ITimerCallback() {

              @Override
              public void onTimePassed(TimerHandler pTimerHandler) {
                handAction(ran);
                if (ran == 2) {
                  A19_07_KEIKOKUON.play();
                }
              }
            }));
    mDoorAnimatedSprite.animate(
        DoorDuration[ran],
        DoorFrame[ran],
        0,
        new IAnimationListener() {

          @Override
          public void onAnimationFinished(AnimatedSprite arg0) {
            mDoorAnimatedSprite.setCurrentTileIndex(0);
            isDoor = true;
            handDefault();
          }

          @Override
          public void onAnimationFrameChanged(AnimatedSprite arg0, int arg1, int arg2) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onAnimationLoopFinished(AnimatedSprite arg0, int arg1, int arg2) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onAnimationStarted(AnimatedSprite arg0, int arg1) {
            // TODO Auto-generated method stub

          }
        });
  }
示例#23
0
  private void jumpMario(final AnimatedSprite face) {
    final Body faceBody = (Body) face.getUserData();

    // float bufX = mario.getX();
    // float bufY = mario.getY();
    // mario.setVisible(false);
    // mario = marioJump;
    // mario.setPosition(bufX, bufY);
    // mario.setVisible(true);

    final Vector2 velocity =
        Vector2Pool.obtain(this.mGravityX * -1, (float) (this.mGravityY * -0.7));
    faceBody.setLinearVelocity(velocity);
    Vector2Pool.recycle(velocity);
  }
 public void newEvent(float pX, float pY, int pSlot) {
   mCubicChooseSpite[TYPE].setVisible(false);
   SLOT = pSlot;
   CUBIC_SLOT[SLOT] = true;
   checkArrow();
   this.setPosition(0, 100);
   ACTION = ACTION_DEFAULT;
   mCubicStartAniSprite.setVisible(true);
   mScrollLeftSprite.clearEntityModifiers();
   mScrollLeftSprite.registerEntityModifier(
       new LoopEntityModifier(
           new SequenceEntityModifier(
               new AlphaModifier(0.5f, 0.2f, 1.0f), new AlphaModifier(0.5f, 1.0f, 0.2f))));
   mScrollLeftSprite.setVisible(true);
   this.setVisible(true);
   final Body body = (Body) CubicEntity.this.getUserData();
   Vector2 vector2 =
       Vector2Pool.obtain(
           pX / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT,
           pY / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
   body.setTransform(vector2, 0);
   Vector2Pool.recycle(vector2);
 }
示例#25
0
 private void handAction(int pAction) {
   setVisibleHandDefault(false);
   switch (pAction) {
     case 2: // Door Human
       mHandActionAniSprite.setCurrentTileIndex(3);
       mHandActionAniSprite.setVisible(true);
       break;
     case 1: // Door ani
     case 0:
       mHandActionAniSprite.setCurrentTileIndex(4);
       mHandActionAniSprite.setVisible(true);
       break;
     case 3:
       mHandActionAniSprite.setCurrentTileIndex(5);
       mHandActionAniSprite.setVisible(true);
       break;
   }
 }
示例#26
0
  @Override
  public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
    this.mGravityX = pAccelerometerData.getX();
    this.mGravityY = pAccelerometerData.getY();

    if (pAccelerometerData.getX() > 0) {
      marioMoveRight = true;
      marioMoveLeft = false;
      marioStand = false;
    } else if (pAccelerometerData.getX() == 0) {
      marioMoveLeft = false;
      marioMoveRight = false;
      marioStand = true;
    } else if (pAccelerometerData.getX() < 0) {
      marioStand = false;
      marioMoveLeft = true;
      marioMoveRight = false;
    }

    float bufX = mario.getX();
    float bufY = mario.getY();

    if (marioMoveLeft && mario != marioLeft) {
      mario.setVisible(false);
      mario = marioLeft;
    } else if (marioMoveRight && mario != marioRight) {
      mario.setVisible(false);
      mario = marioRight;
    } else if (marioStand) {
      mario.setVisible(false);
    }
    mario.setPosition(bufX, bufY);
    mario.setVisible(true);

    final Vector2 gravity = Vector2Pool.obtain(this.mGravityX * 5, this.mGravityY);
    this.mPhysicsWorld.setGravity(gravity);
    Vector2Pool.recycle(gravity);
  }
 @Override
 protected void onManagedUpdate(float pSecondsElapsed) {
   move();
   super.onManagedUpdate(pSecondsElapsed);
 }
示例#28
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

          }
        });
  }
示例#29
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) {}
        });
  }
示例#30
0
  @Override
  protected void onManagedUpdate(float pSecondsElapsed) {
    super.onManagedUpdate(pSecondsElapsed);

    if (!juegoCorriendo) {
      return;
    }

    // Acumular tiempo
    tiempoEnemigos += pSecondsElapsed;
    if (tiempoEnemigos > LIMITE_TIEMPO) {
      // Se cumplió el tiempo
      tiempoEnemigos = 0;
      if (LIMITE_TIEMPO > 0.5f) {
        LIMITE_TIEMPO -= 0.15f;
      }
      Sprite spriteEnemigo =
          cargarSprite(
              ControlJuego.ANCHO_CAMARA + regionEnemigo.getWidth(),
              (float) (Math.random() * ControlJuego.ALTO_CAMARA - regionEnemigo.getHeight())
                  + regionEnemigo.getHeight(),
              regionEnemigo);
      Enemigo nuevoEnemigo = new Enemigo(spriteEnemigo);
      listaEnemigos.add(nuevoEnemigo);
      attachChild(nuevoEnemigo.getSprite());
      Log.i("Tamaño", "Datos: " + listaEnemigos.size());
    }
    // Actualizar cada uno de los listaEnemigos y ver si alguno ya salió de la pantalla
    for (int i = listaEnemigos.size() - 1; i >= 0; i--) {
      Enemigo enemigo = listaEnemigos.get(i);

      enemigo.mover(-10, 0);

      if (enemigo.getSprite().getX() < -enemigo.getSprite().getWidth()) {
        detachChild(enemigo.getSprite());
        listaEnemigos.remove(enemigo);
      }

      // Revisa si choca el personaje con el enemigo
      if (spritePersonaje.collidesWith(enemigo.getSprite())) {
        detachChild(enemigo.getSprite());
        listaEnemigos.remove(enemigo);
        energia -= 10;
        Log.i("ENERGIA", "Energia: " + energia);
        if (energia <= 0) {
          juegoCorriendo = false;
          // Agrega pantalla de fin
          Sprite spriteFin =
              new Sprite(
                  ControlJuego.ANCHO_CAMARA / 2,
                  ControlJuego.ALTO_CAMARA / 2,
                  regionFin,
                  actividadJuego.getVertexBufferObjectManager()) {
                @Override
                public boolean onAreaTouched(
                    TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
                  if (pSceneTouchEvent.isActionUp()) {
                    onBackKeyPressed();
                  }
                  return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
                }
              };
          registerTouchArea(spriteFin);
          attachChild(spriteFin);
        }
      }
    }
  }