Exemplo n.º 1
0
  @Override
  protected Scene onCreateScene() { // #3
    this.scene = new Scene();
    this.scene.setBackground(new Background(0.9804f, 0.6274f, 0.8784f));
    // Probamos la celda

    FontFactory.setAssetBasePath("fuentes/");
    final ITexture fontTexture =
        new BitmapTextureAtlas(
            getTextureManager(), 256, 256, TextureOptions.BILINEAR); // textura para la fuente
    Font myFont;
    myFont =
        FontFactory.createFromAsset(
            getFontManager(), fontTexture, getAssets(), "fuente.ttf", 40, true, Color.WHITE);
    myFont.load();
    Celda unaCelda =
        new Celda(
            camera.getWidth() / 2,
            camera.getHeight() / 2,
            celdaTextureRegion,
            getVertexBufferObjectManager(),
            myFont);
    unaCelda.addToScene(scene);

    // scene.attachChild(rectangulo);
    return this.scene;
  }
  @Override
  protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
    if (super.mScene != null) {
      final Camera secondCamera = this.getSecondCamera();

      final int surfaceWidth = this.mSurfaceWidth;
      final int surfaceWidthHalf = surfaceWidth >> 1;

      final int surfaceHeight = this.mSurfaceHeight;

      pGLState.enableScissorTest();

      /* First Screen. With first camera, on the left half of the screens width. */
      {
        GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
        GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

        super.mScene.onDraw(pGLState, pFirstCamera);
        pFirstCamera.onDrawHUD(pGLState);
      }

      /* Second Screen. With second camera, on the right half of the screens width. */
      {
        GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
        GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

        super.mScene.onDraw(pGLState, secondCamera);
        secondCamera.onDrawHUD(pGLState);
      }

      pGLState.disableScissorTest();
    }
  }
  public ResultScene(Camera mCamera) {
    super(mCamera);
    activity = BaseActivity.getSharedInstance();
    setBackgroundEnabled(false);
    GameScene scene = (GameScene) activity.mCurrentScene;
    float accureay = 1 - (float) scene.missCount / scene.bulletCount;
    if (Float.isNaN(accureay)) accureay = 0;
    accureay *= 100;
    Text result =
        new Text(
            0,
            0,
            activity.mFont,
            activity.getString(R.string.accuracy) + ": " + String.format("%.2f", accureay) + "%",
            BaseActivity.getSharedInstance().getVertexBufferObjectManager());

    final int x = (int) (mCamera.getWidth() / 2 - result.getWidth() / 2);
    final int y = (int) (mCamera.getHeight() / 2 - result.getHeight() / 2);

    done = false;
    result.setPosition(x, mCamera.getHeight() + result.getHeight());
    MoveYModifier mod =
        new MoveYModifier(5, result.getY(), y) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            done = true;
          }
        };
    attachChild(result);
    result.registerEntityModifier(mod);
    setOnSceneTouchListener(this);
  }
Exemplo n.º 4
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);
  }
  @Override
  protected void convertSurfaceToSceneTouchEvent(
      final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
    final int surfaceWidthHalf = this.mSurfaceWidth >> 1;

    if (pCamera == this.getFirstCamera()) {
      pCamera.convertSurfaceToSceneTouchEvent(
          pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
    } else {
      pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
      pCamera.convertSurfaceToSceneTouchEvent(
          pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
    }
  }
Exemplo n.º 6
0
  public BackgroundLayer() {
    super();

    final Camera camera = ResourceManager.getInstance().camera;
    final float width = camera.getWidth();
    final float height = camera.getHeight();

    final float moonX = 2 * width / 3;
    final float moonY = height / 2;

    final GameObject moon =
        new GameObject(moonX, moonY, ResourceManager.getInstance().mMoonTextureRegion);

    this.attachChild(moon);
  }
Exemplo n.º 7
0
  public void loadMenuResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    ResourceManager.playBitmapTextureAtlas =
        new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    ResourceManager.optionsBitmapTextureAtlas =
        new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    ResourceManager.scoresBitmapTextureAtlas =
        new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    ResourceManager.instructionsTextureAtlas =
        new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    ResourceManager.exitBitmapTextureAtlas =
        new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);

    // load the button texture regions
    mMenuBgTextureAtlas =
        new BitmapTextureAtlas(
            activity.getTextureManager(),
            (int) camera.getWidth(),
            (int) camera.getHeight(),
            TextureOptions.DEFAULT);

    mBgTexture =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mMenuBgTextureAtlas, activity, "image.jpg", 0, 0);
    ResourceManager.newGameTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            ResourceManager.playBitmapTextureAtlas, activity, "new_game.PNG", 0, 0);
    ResourceManager.optionsTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            ResourceManager.optionsBitmapTextureAtlas, activity, "settings1.png", 0, 0);
    ResourceManager.quitTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            ResourceManager.exitBitmapTextureAtlas, activity, "exit.PNG", 0, 50);
    ResourceManager.scoresTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            ResourceManager.scoresBitmapTextureAtlas, activity, "menu_reset.png", 0, 0);
    ResourceManager.instructionsTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            ResourceManager.instructionsTextureAtlas, activity, "instructions.PNG", 0, 0);

    ResourceManager.optionsBitmapTextureAtlas.load();
    ResourceManager.playBitmapTextureAtlas.load();
    ResourceManager.scoresBitmapTextureAtlas.load();
    ResourceManager.instructionsTextureAtlas.load();
    ResourceManager.exitBitmapTextureAtlas.load();
    ResourceManager.mMenuBgTextureAtlas.load();
  }
Exemplo n.º 8
0
 @Override
 public void onDraw(GLState pGLState, Camera pCamera) {
   super.onDraw(pGLState, pCamera);
   mBackgroundPages.get(mCurrentIndex).onDraw(pGLState, pCamera, mOffset);
   mBackgroundPages
       .get((mCurrentIndex + 1) % mBackgroundPages.size())
       .onDraw(pGLState, pCamera, mOffset - pCamera.getWidth());
 }
Exemplo n.º 9
0
  @Override
  protected void draw(final GLState pGLState, final Camera pCamera) {
    final int tileColumns = this.mTileColumns;
    final int tileRows = this.mTileRows;
    final int tileWidth = this.mTMXTiledMap.getTileWidth();
    final int tileHeight = this.mTMXTiledMap.getTileHeight();

    final float scaledTileWidth = tileWidth * this.mScaleX;
    final float scaledTileHeight = tileHeight * this.mScaleY;

    final float[] cullingVertices = this.mCullingVertices;
    RectangularShapeCollisionChecker.fillVertices(
        0, 0, this.mWidth, this.mHeight, this.getLocalToSceneTransformation(), cullingVertices);

    final float layerMinX = cullingVertices[SpriteBatch.VERTEX_INDEX_X];
    final float layerMinY = cullingVertices[SpriteBatch.VERTEX_INDEX_Y];

    final float cameraMinX = pCamera.getXMin();
    final float cameraMinY = pCamera.getYMin();
    final float cameraWidth = pCamera.getWidth();
    final float cameraHeight = pCamera.getHeight();

    /* Determine the area that is visible in the camera. */
    final float firstColumnRaw = (cameraMinX - layerMinX) / scaledTileWidth;
    final int firstColumn =
        MathUtils.bringToBounds(0, tileColumns - 1, (int) Math.floor(firstColumnRaw));
    final int lastColumn =
        MathUtils.bringToBounds(
            0, tileColumns - 1, (int) Math.ceil(firstColumnRaw + cameraWidth / scaledTileWidth));

    final float firstRowRaw = (cameraMinY - layerMinY) / scaledTileHeight;
    final int firstRow = MathUtils.bringToBounds(0, tileRows - 1, (int) Math.floor(firstRowRaw));
    final int lastRow =
        MathUtils.bringToBounds(
            0, tileRows - 1, (int) Math.floor(firstRowRaw + cameraHeight / scaledTileHeight));

    for (int row = firstRow; row <= lastRow; row++) {
      for (int column = firstColumn; column <= lastColumn; column++) {
        this.mSpriteBatchVertexBufferObject.draw(
            GLES20.GL_TRIANGLE_STRIP,
            this.getSpriteBatchIndex(column, row) * SpriteBatch.VERTICES_PER_SPRITE,
            SpriteBatch.VERTICES_PER_SPRITE);
      }
    }
  }
 public static void prepare(
     Engine e, MainActivity ma, Camera c, VertexBufferObjectManager vertexBufferObjectManager) {
   getInstance().engine = e;
   getInstance().activity = ma;
   getInstance().camera = c;
   getInstance().vbom = vertexBufferObjectManager;
   getInstance().resizeFactor = c.getWidth() / getInstance().cameraWidthRef;
   getInstance().setVibrator();
 }
Exemplo n.º 11
0
  private void createExplosion(
      final float posX, final float posY, final Color color, final int rec, final float size) {
    int mNumPart = 25;
    int mTimePart = 2;

    CircleParticleEmitter particleEmitter = new CircleParticleEmitter(posX, posY, size);
    IEntityFactory recFact1 =
        new IEntityFactory() {
          @Override
          public Rectangle create(float pX, float pY) {
            Rectangle rect =
                new Rectangle(posX, posY, rec, rec, activity.getVertexBufferObjectManager());
            rect.setColor(color);
            return rect;
          }
        };

    final ParticleSystem particleSystem =
        new ParticleSystem(recFact1, particleEmitter, 200, 700, mNumPart);
    particleSystem.addParticleInitializer(
        new VelocityParticleInitializer(
            -mCamera.getHeight() / 12,
            mCamera.getHeight() / 12,
            -mCamera.getHeight() / 12,
            mCamera.getHeight() / 12));
    particleSystem.addParticleModifier(new AlphaParticleModifier(0, mTimePart * 0.8f, 1, 0));
    particleSystem.addParticleModifier(new RotationParticleModifier(0, mTimePart, 50, 480));

    particleSystem.setZIndex(10);

    attachChild(particleSystem);

    registerUpdateHandler(
        new TimerHandler(
            mTimePart,
            new ITimerCallback() {
              @Override
              public void onTimePassed(final TimerHandler pTimerHandler) {
                particleSystem.detachSelf();
                sortChildren();
                unregisterUpdateHandler(pTimerHandler);
              }
            }));
  }
Exemplo n.º 12
0
  public void addShield() {
    detachChild(activity.shieldSpriteP);

    activity.shieldSpriteP =
        new Sprite(0, 0, activity.shieldRegion, activity.getVertexBufferObjectManager());
    activity.shieldSpriteP.setSize(
        activity.mCamera.getWidth() / 15.4f, activity.mCamera.getWidth() / 15.4f);
    activity.shieldSpriteP.setZIndex(1);

    Random rand = new Random();
    int rangex = (int) (mCamera.getWidth() - 100 - activity.shieldSpriteP.getWidth());
    int rangey = (int) (mCamera.getHeight() - 100 - activity.shieldSpriteP.getHeight());
    int x = rand.nextInt(rangex);
    int y = rand.nextInt(rangey);

    activity.shieldSpriteP.setPosition(x + 50, y + 50);

    attachChild(activity.shieldSpriteP);
    shieldHit = false;
  }
Exemplo n.º 13
0
  @Override
  public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
    startMenuScene = new Scene();
    gameInstanceScene = new Scene();
    endGameScene = new Scene();
    currentScenario = new StartMenuScenario(this, startMenuScene, prepareLoadGameInstanceCallback);
    hud = new HUD();
    camera.setHUD(hud);

    pOnCreateSceneCallback.onCreateSceneFinished(startMenuScene);
  }
Exemplo n.º 14
0
  public Player(
      float pX, float pY, VertexBufferObjectManager vbo, Camera camera, PhysicsWorld physicsWorld) {
    super(
        pX,
        pY,
        com.tesc.sos2014.managers.ResourcesManager.getInstance().player_region.deepCopy(),
        vbo);
    createPhysics(camera, physicsWorld);
    camera.setChaseEntity(this);

    // jetfire();
  }
Exemplo n.º 15
0
        @Override
        public void onUpdate(float pSecondsElapsed) {
          synchronized (this) {
            Iterator<Sprite> targets = enemies.iterator();
            Sprite _target;
            Sprite _bonus;
            Sprite _shield;

            while (targets.hasNext()) {
              _target = targets.next();
              _bonus = activity.bonusSprite;
              _shield = activity.shieldSpriteP;

              if (_target.getY() >= _target.getWidth() + mCamera.getHeight()) {
                removeSprite(_target, targets);
                addTarget();
                break;
              }

              if (isColliding(
                  activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                  activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                  _target.getX() + activity.enemySprite.getWidth() / 2,
                  _target.getY() + activity.enemySprite.getHeight() / 2,
                  (int) activity.enemySprite.getHeight() / 2)) {
                enemyCollide(_target, targets);
                break;
              }
              if (!bonusHit)
                if (isColliding(
                    activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                    activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                    _bonus.getX() + activity.bonusSprite.getWidth() / 2,
                    _bonus.getY() + activity.bonusSprite.getHeight() / 2,
                    (int) activity.bonusSprite.getHeight() / 2)) {
                  bonusCollide();
                }
              if (!shieldHit)
                if (isColliding(
                    activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                    activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                    _shield.getX() + activity.shieldSpriteP.getWidth() / 2,
                    _shield.getY() + activity.shieldSpriteP.getHeight() / 2,
                    (int) activity.shieldSpriteP.getHeight() / 2)) {
                  shieldCollide();
                }
            }
            enemies.addAll(enemiesToBeAdded);
            enemiesToBeAdded.clear();
            sortChildren();
          }
        }
Exemplo n.º 16
0
  public void addBonus() {
    if (activity.bonusSprite.hasParent()) {
      detachChild(activity.bonusSprite);
    }

    activity.bonusSprite =
        new Sprite(0, 0, activity.bonusRegion, activity.getVertexBufferObjectManager());
    activity.bonusSprite.setSize(
        activity.mCamera.getWidth() / 15.4f, activity.mCamera.getWidth() / 15.4f);
    activity.bonusSprite.setZIndex(1);

    Random rand = new Random();
    int rangex = (int) (mCamera.getWidth() - 100 - activity.bonusSprite.getWidth());
    int rangey = (int) (mCamera.getHeight() - 100 - activity.bonusSprite.getHeight());
    int x = rand.nextInt(rangex);
    int y = rand.nextInt(rangey);

    activity.bonusSprite.setPosition(x + 50, y + 50);

    attachChild(activity.bonusSprite);
    bonusHit = false;
  }
  private void setAssetBasePath() {
    int cameraWidth;
    setSvgAssetBasePath("svg/");

    cameraWidth = (int) camera.getWidth();
    switch (cameraWidth) {
      case 480:
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx480/");
        break;
      case 720:
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx720/");
        break;
      case 1080:
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx1080/");
        break;
      default:
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx720/");
        Log.v("assetPathErro", "SomethingWrong~");
        break;
    }
  }
Exemplo n.º 18
0
    public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue) {
      pGLState.pushModelViewGLMatrix();
      {
        final float cameraWidth = pCamera.getWidth();
        final float entityWidthScaled = this.mEntity.getWidth() * this.mEntity.getScaleX();
        float baseOffset = (pParallaxValue * this.mParallaxFactor) % entityWidthScaled;

        while (baseOffset > 0) {
          baseOffset -= entityWidthScaled;
        }
        pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);

        float currentMaxX = baseOffset;

        do {
          this.mEntity.onDraw(pGLState, pCamera);
          pGLState.translateModelViewGLMatrixf(entityWidthScaled, 0, 0);
          currentMaxX += entityWidthScaled;
        } while (currentMaxX < cameraWidth);
      }
      pGLState.popModelViewGLMatrix();
    }
Exemplo n.º 19
0
 public Player(
     float pX, float pY, VertexBufferObjectManager vbo, Camera camera, PhysicsWorld physicsWorld) {
   super(pX, pY, ResourcesManager.getInstance().player_region, vbo);
   createPhysics(camera, physicsWorld);
   camera.setChaseEntity(this);
 }
Exemplo n.º 20
0
  public org.andengine.entity.scene.menu.MenuScene createScene() {
    float screenWidth = camera.getWidth();
    float screenHeight = camera.getHeight();
    menuScene = new org.andengine.entity.scene.menu.MenuScene(camera);

    // BACKGROUND SETUP
    map.loadMap(menuScene);
    // menuScene.attachChild(map.createScene(10));

    spawnCar(screenWidth, screenHeight);

    // BANNER/LOGO & banner animation
    final Sprite banner =
        new Sprite(
            (screenWidth - dodgecarsTR.getWidth()) / 2,
            (screenHeight / 7) / 2,
            dodgecarsTR,
            this.activity.getVertexBufferObjectManager());
    rotBan = false;
    scaBan = false;
    banner.registerEntityModifier(
        new ScaleModifier(scaleDuration, startScale, endScale) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            super.onModifierFinished(pItem);
            if (scaBan) {
              this.reset(scaleDuration, startScale, endScale, startScale, endScale);
              scaBan = !scaBan;
            } else {
              this.reset(scaleDuration, endScale, startScale, endScale, startScale);
              scaBan = !scaBan;
            }
          }
        });
    banner.registerEntityModifier(
        new RotationModifier(rotDuration, startRot, endRot) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            super.onModifierFinished(pItem);
            if (!rotBan) {
              this.reset(rotDuration, endRot, startRot);
              rotBan = !rotBan;
            } else {
              this.reset(rotDuration, startRot, endRot);
              rotBan = !rotBan;
            }
          }
        });

    // MENU ITEMS
    final IMenuItem buttonPlay =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(PLAY_BTN_ID, playTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    final IMenuItem buttonHighScore =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(
                HIGHSCORE_BTN_ID, highscoreTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    final IMenuItem buttonCredits =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(
                CREDITS_BTN_ID, creditsTR, this.activity.getVertexBufferObjectManager()),
            unSelected,
            onSelected);
    buttonPlay.setPosition((screenWidth - playTR.getWidth()) / 2, screenHeight / 7 * 3);
    buttonHighScore.setPosition((screenWidth - highscoreTR.getWidth()) / 2, screenHeight / 7 * 4);
    buttonCredits.setPosition((screenWidth - creditsTR.getWidth()) / 2, screenHeight / 7 * 5);

    // Sound and Music on/off buttons
    soundOnBtn =
        new Sprite(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            soundsOnTR,
            this.activity.getVertexBufferObjectManager());
    soundOffBtn =
        new Sprite(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            soundsOffTR,
            this.activity.getVertexBufferObjectManager());
    musicOnBtn =
        new Sprite(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            musicOnTR,
            this.activity.getVertexBufferObjectManager());
    musicOffBtn =
        new Sprite(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            musicOffTR,
            this.activity.getVertexBufferObjectManager());

    menuScene.attachChild(banner);
    menuScene.addMenuItem(buttonPlay);
    menuScene.addMenuItem(buttonHighScore);
    menuScene.addMenuItem(buttonCredits);

    if (sounds.playMusic) {
      menuScene.attachChild(musicOffBtn);
      menuScene.attachChild(musicOnBtn);
      musicOffBtn.setVisible(false);
      musicOnBtn.setVisible(true);
    } else {
      menuScene.attachChild(musicOnBtn);
      menuScene.attachChild(musicOffBtn);
      musicOnBtn.setVisible(false);
      musicOffBtn.setVisible(true);
    }

    if (sounds.playSounds) {
      menuScene.attachChild(soundOffBtn);
      menuScene.attachChild(soundOnBtn);
      soundOffBtn.setVisible(false);
      soundOnBtn.setVisible(true);
    } else {
      menuScene.attachChild(soundOnBtn);
      menuScene.attachChild(soundOffBtn);
      soundOnBtn.setVisible(false);
      soundOffBtn.setVisible(true);
    }

    final Rectangle soundRec =
        new Rectangle(
            camera.getWidth() - soundsOnTR.getWidth() * 2,
            0,
            GameManager.lengthOfTile,
            GameManager.lengthOfTile,
            this.activity.getVertexBufferObjectManager()) {
          public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y) {
            if (touchEvent.isActionDown()) {
              if (sounds.playSounds) {
                sounds.setSoundsEnable(false);
                soundOnBtn.setVisible(false);
                soundOffBtn.setVisible(true);
              } else {
                sounds.setSoundsEnable(true);
                soundOffBtn.setVisible(false);
                soundOnBtn.setVisible(true);
              }
            }
            return true;
          };
        };
    final Rectangle musicRec =
        new Rectangle(
            camera.getWidth() - musicOnTR.getWidth(),
            0,
            GameManager.lengthOfTile,
            GameManager.lengthOfTile,
            this.activity.getVertexBufferObjectManager()) {
          public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y) {
            if (touchEvent.isActionDown()) {
              if (sounds.playMusic) {
                sounds.setMusicEnable(false);
                sounds.pauseMusic();
                musicOnBtn.setVisible(false);
                musicOffBtn.setVisible(true);
              } else {
                sounds.setMusicEnable(true);
                sounds.playMusic();
                musicOffBtn.setVisible(false);
                musicOnBtn.setVisible(true);
              }
            }
            return true;
          };
        };
    soundRec.setAlpha(255);
    musicRec.setAlpha(255);
    menuScene.registerTouchArea(soundRec);
    menuScene.registerTouchArea(musicRec);
    menuScene.attachChild(soundRec);
    menuScene.attachChild(musicRec);

    menuScene.setOnMenuItemClickListener(
        new IOnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClicked(
              org.andengine.entity.scene.menu.MenuScene pMenuScene,
              IMenuItem pMenuItem,
              float pMenuItemLocalX,
              float pMenuItemLocalY) {

            switch (pMenuItem.getID()) {
              case PLAY_BTN_ID:
                sounds.playCarStart();
                sceneManager.createGameScene();
                sceneManager.setCurrentSence(AllScenes.GAME);
                break;
              case HIGHSCORE_BTN_ID:
                sounds.playBlop();
                sceneManager.createHighScoreScene();
                sceneManager.setCurrentSence(AllScenes.HIGHSCORE);
                break;
              case CREDITS_BTN_ID:
                sounds.playBlop();
                sceneManager.createCreditScene();
                sceneManager.setCurrentSence(AllScenes.CREDITS);
                break;
            }

            return false;
          }
        });

    return menuScene;
  }
Exemplo n.º 21
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

          }
        });
  }
Exemplo n.º 22
0
  public void loadGameResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    SoundFactory.setAssetBasePath("sfx/");
    MusicFactory.setAssetBasePath("sfx/");
    condomTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    chickenTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    tabletTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    waterTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    garlicTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 32, 32);
    pineappleTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    alcoholTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 32, 64);
    blueTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256);
    redTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256);
    razorTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256);
    winTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 512);
    lossTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 512);
    pauseTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    cigarreteTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);
    soyaTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 32, 16);
    bonusTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 64, 64);

    // create the texture regions of the different Sprites
    condomTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            condomTextureAtlas, activity, "condom2f.png", 0, 0);
    chickenTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            chickenTextureAtlas, activity, "chichen_final.png", 0, 0);
    tabletTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            tabletTextureAtlas, activity, "tab.png", 0, 0);
    garlicTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            garlicTextureAtlas, activity, "garlicf.png", 0, 0);
    pineappleTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            pineappleTextureAtlas, activity, "pinef.png", 0, 0);
    waterTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            waterTextureAtlas, activity, "water.png", 0, 0);
    alcoholTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            alcoholTextureAtlas, activity, "waragi.png", 0, 0);
    blueTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            blueTextureAtlas, activity, "blue3.png", 0, 0);
    redTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            redTextureAtlas, activity, "red2.png", 0, 0);
    razorTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            razorTextureAtlas, activity, "razor.png", 0, 0);
    winTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            winTextureAtlas, activity, "win.png", 0, 0);
    lossTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            lossTextureAtlas, activity, "loss.png", 0, 0);
    cigarreteTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            cigarreteTextureAtlas, activity, "cigaret5.png", 0, 0);
    soyaTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            soyaTextureAtlas, activity, "sayaf.png", 0, 0);
    bonusTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bonusTextureAtlas, activity, "health.png", 0, 0);
    pauseTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            pauseTextureAtlas, activity, "pause.png", 0, 0);

    mBackgroundTexture =
        new BitmapTextureAtlas(
            engine.getTextureManager(),
            (int) camera.getWidth(),
            (int) camera.getHeight(),
            TextureOptions.DEFAULT);
    mBgTexture =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            mBackgroundTexture, activity, "game_background.jpg", 0, 0);

    // scoreFontTexture = new BitmapTextureAtlas(engine.getTextureManager(),
    // 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    // FontFactory.setAssetBasePath("font/");
    // ResourceManager.mFont = FontFactory.createFromAsset(scoreFontTexture,
    // engine.getTextureManager(),
    // "Droid.ttf", FONT_SIZE, true, Color.BLACK);
    ResourceManager.mFont =
        FontFactory.create(
            engine.getFontManager(),
            engine.getTextureManager(),
            256,
            256,
            Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
            FONT_SIZE);

    // Load our "sound.mp3" file into a Sound object
    try {
      mGameTapSound =
          SoundFactory.createSoundFromAsset(engine.getSoundManager(), activity, "tap.mp3");
      badFoodSound =
          SoundFactory.createSoundFromAsset(engine.getSoundManager(), activity, "plast.mp3");
    } catch (IOException e) {
      e.printStackTrace();
    }
    // Load our "music.mp3" file into a music object
    try {
      gameMusic =
          MusicFactory.createMusicFromAsset(engine.getMusicManager(), activity, "welcome.mp3");
    } catch (IOException e) {
      e.printStackTrace();
    }

    ResourceManager.mFont.load();
    ResourceManager.mBackgroundTexture.load();
    condomTextureAtlas.load();
    chickenTextureAtlas.load();
    tabletTextureAtlas.load();
    pineappleTextureAtlas.load();
    waterTextureAtlas.load();
    alcoholTextureAtlas.load();
    garlicTextureAtlas.load();
    blueTextureAtlas.load();
    redTextureAtlas.load();
    razorTextureAtlas.load();
    winTextureAtlas.load();
    lossTextureAtlas.load();
    pauseTextureAtlas.load();
    cigarreteTextureAtlas.load();
    soyaTextureAtlas.load();
    bonusTextureAtlas.load();
  }
Exemplo n.º 23
0
  @Override
  protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
    if (this.mClippingEnabled) {
      /* Enable scissor test, while remembering previous state. */
      final boolean wasScissorTestEnabled = pGLState.enableScissorTest();

      final int surfaceHeight = pCamera.getSurfaceHeight();

      /* In order to apply clipping, we need to determine the the axis aligned bounds in OpenGL coordinates. */

      /* Determine clipping coordinates of each corner in surface coordinates. */
      final float[] lowerLeftSurfaceCoordinates =
          pCamera.getSurfaceCoordinatesFromSceneCoordinates(
              this.convertLocalCoordinatesToSceneCoordinates(0, 0));
      final int lowerLeftX =
          (int) Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
      final int lowerLeftY =
          surfaceHeight - (int) Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

      final float[] upperLeftSurfaceCoordinates =
          pCamera.getSurfaceCoordinatesFromSceneCoordinates(
              this.convertLocalCoordinatesToSceneCoordinates(0, this.mHeight));
      final int upperLeftX =
          (int) Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
      final int upperLeftY =
          surfaceHeight - (int) Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

      final float[] upperRightSurfaceCoordinates =
          pCamera.getSurfaceCoordinatesFromSceneCoordinates(
              this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, this.mHeight));
      final int upperRightX =
          (int) Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
      final int upperRightY =
          surfaceHeight - (int) Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

      final float[] lowerRightSurfaceCoordinates =
          pCamera.getSurfaceCoordinatesFromSceneCoordinates(
              this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, 0));
      final int lowerRightX =
          (int) Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
      final int lowerRightY =
          surfaceHeight - (int) Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

      /* Determine minimum and maximum x clipping coordinates. */
      final int minClippingX = MathUtils.min(lowerLeftX, upperLeftX, upperRightX, lowerRightX);
      final int maxClippingX = MathUtils.max(lowerLeftX, upperLeftX, upperRightX, lowerRightX);

      /* Determine minimum and maximum y clipping coordinates. */
      final int minClippingY = MathUtils.min(lowerLeftY, upperLeftY, upperRightY, lowerRightY);
      final int maxClippingY = MathUtils.max(lowerLeftY, upperLeftY, upperRightY, lowerRightY);

      /* Determine clipping width and height. */
      final int clippingWidth = maxClippingX - minClippingX;
      final int clippingHeight = maxClippingY - minClippingY;

      /* Finally apply the clipping. */
      pGLState.glPushScissor(minClippingX, minClippingY, clippingWidth, clippingHeight);

      /* Draw children, etc... */
      super.onManagedDraw(pGLState, pCamera);

      /* Revert scissor test to previous state. */
      pGLState.glPopScissor();
      pGLState.setScissorTestEnabled(wasScissorTestEnabled);
    } else {
      super.onManagedDraw(pGLState, pCamera);
    }
  }
Exemplo n.º 24
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) {}
        });
  }
  private void loadFonts() {
    FontFactory.setAssetBasePath("fonts/");

    final ITexture tFontTextureDefault =
        new BitmapTextureAtlas(
            activity.getTextureManager(),
            (int) applyResizeFactor(camera.getWidth()),
            (int) applyResizeFactor(512f),
            TextureOptions.BILINEAR);

    final ITexture tFontTextureButton =
        new BitmapTextureAtlas(
            activity.getTextureManager(),
            (int) applyResizeFactor(camera.getWidth()),
            (int) applyResizeFactor(512f),
            TextureOptions.BILINEAR);

    final ITexture tFontTexturePoint =
        new BitmapTextureAtlas(
            activity.getTextureManager(),
            (int) applyResizeFactor(camera.getWidth()),
            (int) applyResizeFactor(512f),
            TextureOptions.BILINEAR);

    this.fontDefault =
        FontFactory.createFromAsset(
            activity.getFontManager(),
            tFontTextureDefault,
            activity.getAssets(),
            "UbuntuB.ttf",
            FONT_SIZE_DEFAULT,
            true,
            AppColor.getInstance().WHITE.getABGRPackedInt());
    this.fontDefault.load();

    this.fontButton =
        FontFactory.createFromAsset(
            activity.getFontManager(),
            tFontTextureButton,
            activity.getAssets(),
            "UbuntuB.ttf",
            FONT_SIZE_BUTTON,
            true,
            AppColor.getInstance().WHITE.getABGRPackedInt());
    this.fontButton.load();

    this.fontPoint =
        FontFactory.createFromAsset(
            activity.getFontManager(),
            tFontTexturePoint,
            activity.getAssets(),
            "UbuntuB.ttf",
            FONT_SIZE_DEFAULT,
            true,
            AppColor.getInstance().BALL.getABGRPackedInt());
    this.fontPoint.load();

    this.fontRoundMenu =
        FontFactory.createFromAsset(
            activity.getFontManager(),
            tFontTexturePoint,
            activity.getAssets(),
            "UbuntuB.ttf",
            FONT_SIZE_ROUNDMENU,
            true,
            AppColor.getInstance().BALL.getABGRPackedInt());
    this.fontRoundMenu.load();
  }
Exemplo n.º 26
0
  public org.andengine.entity.scene.menu.MenuScene createScene() {
    scene = new org.andengine.entity.scene.menu.MenuScene(camera);
    map.loadMap(scene);

    int padding = 50;

    final Sprite credits =
        new Sprite(
            (camera.getWidth() - creditsTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2,
            creditsTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite gameby =
        new Sprite(
            (camera.getWidth() - gamebyTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2 + creditsTR.getHeight() + padding * 2,
            gamebyTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite robin =
        new Sprite(
            (camera.getWidth() - robinTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + padding * 3,
            robinTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite musicby =
        new Sprite(
            (camera.getWidth() - musicbyTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + robinTR.getHeight()
                + padding * 5,
            musicbyTR,
            this.activity.getVertexBufferObjectManager());
    final Sprite alex =
        new Sprite(
            (camera.getWidth() - alexTR.getWidth()) / 2,
            GameManager.lengthOfTile * 2
                + creditsTR.getHeight()
                + gamebyTR.getHeight()
                + robinTR.getHeight()
                + musicbyTR.getHeight()
                + padding * 6,
            alexTR,
            this.activity.getVertexBufferObjectManager());

    scene.attachChild(gameby);
    scene.attachChild(alex);
    scene.attachChild(musicby);
    scene.attachChild(robin);

    final IMenuItem buttonHome =
        new ScaleMenuItemDecorator(
            new SpriteMenuItem(HOME_BTN_ID, homeTR, this.activity.getVertexBufferObjectManager()),
            1,
            1);
    buttonHome.setPosition(
        camera.getWidth() / 2 - homeTR.getWidth() / 2, camera.getHeight() - homeTR.getHeight() * 2);
    scene.addMenuItem(buttonHome);

    scene.setOnMenuItemClickListener(
        new IOnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClicked(
              org.andengine.entity.scene.menu.MenuScene pMenuScene,
              IMenuItem pMenuItem,
              float pMenuItemLocalX,
              float pMenuItemLocalY) {

            switch (pMenuItem.getID()) {
              case HOME_BTN_ID:
                sounds.playBlop();
                sceneManager.createMenuScene();
                sceneManager.setCurrentSence(AllScenes.MENU);
                break;
            }

            return false;
          }
        });

    scene.attachChild(credits);
    return scene;
  }
Exemplo n.º 27
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;
      }
    }
  }