Exemplo n.º 1
0
  private void createPhysics(final Camera camera, PhysicsWorld physicsWorld) {
    body =
        PhysicsFactory.createBoxBody(
            physicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));

    body.setUserData("player");
    body.setFixedRotation(true);

    physicsWorld.registerPhysicsConnector(
        new PhysicsConnector(this, body, true, false) {
          @Override
          public void onUpdate(float pSecondsElapsed) {
            super.onUpdate(pSecondsElapsed);
            camera.onUpdate(0.1f);

            if (getY() <= 0) {
              onDie();
            }

            if (canRun) {
              body.setLinearVelocity(new Vector2(5, body.getLinearVelocity().y));
            }
          }
        });
  }
Exemplo n.º 2
0
 private void createGround() {
   this.ground = new Rectangle(400, GROUND_LEVEL, GROUND_WIDTH, GROUND_THICKNESS, this.vbom);
   this.ground.setColor(LevelElement.COLOR_DEFAULT);
   this.groundBody =
       PhysicsFactory.createBoxBody(
           this.physicWorld,
           this.ground,
           BodyDef.BodyType.StaticBody,
           PhysicsFactory.createFixtureDef(0, 0, 0));
   this.groundBody.setUserData("ground");
   this.attachChild(this.ground);
 }
Exemplo n.º 3
0
  private void createPlayer() {
    this.player =
        new Player(
            PLAYER_X,
            GROUND_LEVEL + GROUND_THICKNESS / 2 + 32,
            this.resourcesManager.player,
            this.vbom,
            this.physicWorld) {
          @Override
          protected void onUpdateColor() {
            super.onUpdateColor();
            if (BaseGameScene.this.playerTrail != null) {
              BaseGameScene.this.playerTrail.setColor(this.getColor());
            }
          }
        };
    this.player.getBody().setUserData("player");
    this.player.registerPlayerListener(new BaseGamePlayerListener());

    this.attachChild(this.player);
    this.playerTrail =
        new Trail(
            36,
            0,
            0,
            64,
            -340,
            -300,
            -2,
            2,
            25,
            30,
            50,
            Trail.ColorMode.NORMAL,
            this.resourcesManager.trail,
            this.vbom);
    this.playerTrail.bind(this.player);
    this.attachChild(this.playerTrail);
    this.playerTrail.hide();
    this.playerTrail.setZIndex(this.player.getZIndex() - 1);
    this.sortChildren();

    Body retention =
        PhysicsFactory.createBoxBody(
            this.physicWorld,
            PLAYER_X - this.player.getWidth() / 2,
            250,
            1,
            400,
            BodyDef.BodyType.StaticBody,
            PhysicsFactory.createFixtureDef(0, 0, 0));
    retention.setUserData("retention");
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
  @Override
  public Scene onCreateScene() {
    // Set FPSlogger and physics World
    this.mEngine.registerUpdateHandler(new FPSLogger());
    this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

    // Create new Scene
    this.mScene = new Scene();
    mScene.setBackground(new Background(0, 0, 0));

    // Initialize the physical boundary
    final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
    final Rectangle ground =
        new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
    final Rectangle roof = new Rectangle(0, 0, CAMERA_WIDTH, 2, vertexBufferObjectManager);
    final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
    final Rectangle right =
        new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);

    // Create the physical body of boundary
    final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

    // Add the bodies to the scene
    this.mScene.attachChild(ground);
    this.mScene.attachChild(roof);
    this.mScene.attachChild(left);
    this.mScene.attachChild(right);
    addMario(50, 50);

    //
    this.mScene.registerUpdateHandler(this.mPhysicsWorld);
    this.mScene.setOnSceneTouchListener(this);

    return mScene;
  }
Exemplo n.º 6
0
  public Puck(
      final float pX,
      final float pY,
      final TextureRegion pTextureRegion,
      final VertexBufferObjectManager pVertexBufferObjectManager,
      PhysicsWorld physicsWorld) {
    super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
    fixtureDef.filter.categoryBits = NightHockeyActivity.CATEGORY_PUCK;
    fixtureDef.filter.maskBits = NightHockeyActivity.CATEGORY_WALL;
    body = PhysicsFactory.createCircleBody(physicsWorld, this, BodyType.DynamicBody, fixtureDef);

    body.setLinearDamping(0.3f);
    body.setAngularDamping(0.3f);
    body.setUserData(this);

    setAlpha(0.2f);

    physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, true));

    startPosition = new Vector2(body.getPosition());
  }
Exemplo n.º 7
0
/**
 * (c) 2010 Nicolas Gramlich (c) 2011 Zynga
 *
 * @author Nicolas Gramlich
 * @since 18:47:08 - 19.03.2010
 */
public class BLevel4 extends Scene implements IOnSceneTouchListener {
  // ===========================================================
  // Constants
  // ===========================================================

  private Scene mScene;

  static PhysicsWorld mPhysicsWorld;
  private int mFaceCount = 0;
  protected MenuScene menu;
  private Path path = new Path();
  World2Activity activity;
  static AnimatedSprite face;
  Body bod;
  Body lbod;
  Body rbod;
  Body Finish;
  PhysicsWorld bPhysicsWorld;
  Body body;
  Rectangle one;
  Rectangle two;
  Rectangle three;
  Rectangle four;
  Rectangle five;
  int score = 10000;
  FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
  FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);

  private int i = 0;
  int x;
  private boolean isDrawing = false;

  int linesDrawn = 0;

  Line bodyLine;
  Body lb;
  Line line;
  Text centerText;
  DelayModifier dMod;
  Rectangle[] rec = new Rectangle[250]; // Just in case, it's not THAT big of a deal.

  private FixtureDef pFixtureDef;

  // ===========================================================
  // Constructors
  // ===========================================================

  // ===========================================================
  // Getter & Setter
  // ===========================================================

  // ===========================================================
  // Methods for/from SuperClass/Interfaces
  // ===========================================================

  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

          }
        });
  }

  @Override
  public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    final VertexBufferObjectManager vertexBufferObjectManager =
        activity.getVertexBufferObjectManager();
    // FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(0.0f,
    //       0.0f, 0.0f);

    // centerText.detachSelf();

    if (linesDrawn <= 150) {
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
        isDrawing = true;
        i = 0;
      }
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
        isDrawing = false;
      }
      if (isDrawing = true) {
        rec[i] =
            new Rectangle(
                pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 1, 1, vertexBufferObjectManager);
        if (i != 0) {
          Line l =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          Line bodyLine =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          Body lb;
          Line line =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          lb = PhysicsFactory.createLineBody(mPhysicsWorld, bodyLine, wallFixtureDef);
          lb.setUserData("line");
          line.setLineWidth(5);
          bodyLine.setVisible(false);
          line.setColor(Color.WHITE);
          bodyLine.setColor(Color.WHITE);
          attachChild(bodyLine);
          attachChild(line);
          linesDrawn++;
          rectangle(linesDrawn);
        }
        linesDrawn++;
        i++;

        // final Text elapsedText = new Text(500, 360, activity.mFont, "Seconds elapsed:", "Seconds
        // elapsed: XXXXX".length(), activity.getVertexBufferObjectManager());
        // final Text fpsText = new Text(500, 400, activity.mFont, "FPS:", "FPS: XXXXX".length(),
        // activity.getVertexBufferObjectManager());

        // attachChild(elapsedText);
        // attachChild(fpsText);

        // final FPSCounter fpsCounter = new FPSCounter();

        //	registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() {
        //		@Override
        //		public void onTimePassed(final TimerHandler pTimerHandler) {
        //			elapsedText.setText("Globs Used: " + linesDrawn);
        // fpsText.setText("Globs Left: " + ( 150 - linesDrawn));
        //		}
        //	}));
        //  }

      }
    }
    return true;
  }

  private void rectangle(int b) {

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

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

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

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

    if (b > 150) five.detachSelf();
  }

  private void destroy(int t) {

    if (t == 0) {
      activity.menu = 5;
      W1LSMenu.bPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      String Score = String.valueOf(score);
      if (activity.isBeat(34).compareTo("true") != 0) {
        activity.setScore(34, Score);
        activity.unLockLevel(35, "true");
        activity.setScore(score);
        activity.saveHighScore();
        activity.loadHighScore();
      } else {
        int test = activity.getScore(31);
        if (score > test) {
          activity.setScore(31, Score);
          // activity.unLockLevel(2, "true");
          int newscore = (score - test);
          activity.setScore(newscore);
          activity.saveHighScore();
          activity.loadHighScore();
        }
      }

      MenuScene end = activity.scoreScene(5, score);
      setChildScene(end, false, true, true);
    } else if (t == 1) {
      activity.menu = 5;
      W1LSMenu.bPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      MenuScene end = activity.deadScene(5);
      setChildScene(end, false, true, true);
    } else if (t == 2) {
      W1LSMenu.bPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      activity.setCurrentScene(new BLevel4());
    }

    // mPhysicsWorld.dispose();
    // mPhysicsWorld.destroyBody(lbod);
    // mPhysicsWorld.destroyBody(rbod);
    // mPhysicsWorld.destroyBody(Finish);
    // mPhysicsWorld.destroyBody(bod);
    // mPhysicsWorld.reset();

    // mPhysicsWorld.clearForces();
    // mPhysicsWorld.clearPhysicsConnectors();
    //  mPhysicsWorld.dispose();
    //   mPhysicsWorld = null;

    //    mScene.clearChildScene();
    // mScene.reset();
    //

    // activity.setCurrentScene(null);

  }
}
Exemplo n.º 8
0
  @Override
  public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    final VertexBufferObjectManager vertexBufferObjectManager =
        activity.getVertexBufferObjectManager();
    // FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(0.0f,
    //       0.0f, 0.0f);

    // centerText.detachSelf();

    if (linesDrawn <= 150) {
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
        isDrawing = true;
        i = 0;
      }
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
        isDrawing = false;
      }
      if (isDrawing = true) {
        rec[i] =
            new Rectangle(
                pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 1, 1, vertexBufferObjectManager);
        if (i != 0) {
          Line l =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          Line bodyLine =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          Body lb;
          Line line =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          lb = PhysicsFactory.createLineBody(mPhysicsWorld, bodyLine, wallFixtureDef);
          lb.setUserData("line");
          line.setLineWidth(5);
          bodyLine.setVisible(false);
          line.setColor(Color.WHITE);
          bodyLine.setColor(Color.WHITE);
          attachChild(bodyLine);
          attachChild(line);
          linesDrawn++;
          rectangle(linesDrawn);
        }
        linesDrawn++;
        i++;

        // final Text elapsedText = new Text(500, 360, activity.mFont, "Seconds elapsed:", "Seconds
        // elapsed: XXXXX".length(), activity.getVertexBufferObjectManager());
        // final Text fpsText = new Text(500, 400, activity.mFont, "FPS:", "FPS: XXXXX".length(),
        // activity.getVertexBufferObjectManager());

        // attachChild(elapsedText);
        // attachChild(fpsText);

        // final FPSCounter fpsCounter = new FPSCounter();

        //	registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() {
        //		@Override
        //		public void onTimePassed(final TimerHandler pTimerHandler) {
        //			elapsedText.setText("Globs Used: " + linesDrawn);
        // fpsText.setText("Globs Left: " + ( 150 - linesDrawn));
        //		}
        //	}));
        //  }

      }
    }
    return true;
  }
Exemplo n.º 9
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.º 10
0
/**
 * (c) 2010 Nicolas Gramlich (c) 2011 Zynga
 *
 * @author Nicolas Gramlich
 * @since 18:47:08 - 19.03.2010
 */
public class Level21 extends Scene implements IOnSceneTouchListener {
  // ===========================================================
  // Constants
  // ===========================================================

  /* The categories. */
  public static final short CATEGORYBIT_WALL = 1;
  public static final short CATEGORYBIT_BOX = 2;
  public static final short CATEGORYBIT_CIRCLE = 4;

  Body body;
  Body Enemy;
  Sprite enemy;
  Sprite enemy2;
  Sprite enemy3;
  int score = 15000;
  /* And what should collide with what. */
  public static final short MASKBITS_WALL = CATEGORYBIT_WALL + CATEGORYBIT_BOX + CATEGORYBIT_CIRCLE;
  public static final short MASKBITS_BOX =
      CATEGORYBIT_WALL + CATEGORYBIT_BOX; // Missing: CATEGORYBIT_CIRCLE
  public static final short MASKBITS_CIRCLE = CATEGORYBIT_WALL; // Missing: CATEGORYBIT_BOX

  public static final FixtureDef WALL_FIXTURE_DEF =
      PhysicsFactory.createFixtureDef(
          0, 0.5f, 0.5f, false, CATEGORYBIT_WALL, MASKBITS_WALL, (short) 0);
  public static final FixtureDef BOX_FIXTURE_DEF =
      PhysicsFactory.createFixtureDef(
          0, 0.5f, 0.5f, false, CATEGORYBIT_BOX, MASKBITS_BOX, (short) 0);
  public static final FixtureDef CIRCLE_FIXTURE_DEF =
      PhysicsFactory.createFixtureDef(
          10, 0.2f, 0.5f, false, CATEGORYBIT_CIRCLE, MASKBITS_CIRCLE, (short) 0);
  public static final FixtureDef FACE_FIXTURE_DEF =
      PhysicsFactory.createFixtureDef(
          1, 0.5f, 0.5f, false, CATEGORYBIT_WALL, MASKBITS_WALL, (short) 0);

  private Scene mScene;

  static PhysicsWorld mPhysicsWorld;
  private int mFaceCount = 0;

  private Path path = new Path();
  World1Activity activity;
  static AnimatedSprite face;
  Body bod;
  Body lbod;
  Body rbod;
  Body Finish;
  PhysicsWorld bPhysicsWorld;
  Body Enemy2;
  Body Enemy3;

  Rectangle one;
  Rectangle two;
  Rectangle three;
  Rectangle four;
  Rectangle five;

  int dead = 0;
  private int i = 0;
  int x = 0;
  int l = 0;
  private boolean isDrawing = false;

  int linesDrawn = 0;

  Line bodyLine;
  Body lb;
  Line line;
  Text centerText;
  DelayModifier dMod;
  Rectangle[] rec = new Rectangle[250]; // Just in case, it's not THAT big of a deal.

  // ===========================================================
  // Constructors
  // ===========================================================

  // ===========================================================
  // Getter & Setter
  // ===========================================================

  // ===========================================================
  // Methods for/from SuperClass/Interfaces
  // ===========================================================

  public Level21() {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          }
        });

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

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

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

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

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

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

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

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

    final int blue = activity.faceSelected(1);

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

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

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

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

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

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

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

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

    */

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

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

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

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

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

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

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

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

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

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

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

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

              registerEntityModifier(dMod);
            }

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

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

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

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

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

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

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

          @Override
          public void postSolve(Contact contact, ContactImpulse impulse) {}
        });
  }

  @Override
  public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    final VertexBufferObjectManager vertexBufferObjectManager =
        activity.getVertexBufferObjectManager();
    FixtureDef objectFixtureDef =
        PhysicsFactory.createFixtureDef(
            0.0f, 0.5f, 0.5f, false, CATEGORYBIT_CIRCLE, MASKBITS_CIRCLE, (short) 0);

    // centerText.detachSelf();

    if (linesDrawn <= 151) {
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
        isDrawing = true;
        i = 0;
      }
      if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
        isDrawing = false;
      }
      if (isDrawing = true) {
        rec[i] =
            new Rectangle(
                pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 1, 1, vertexBufferObjectManager);
        if (i != 0) {
          Line l =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          bodyLine =
              new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          // Body lb;
          line = new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null);
          lb = PhysicsFactory.createLineBody(mPhysicsWorld, bodyLine, objectFixtureDef);
          lb.setUserData("line");
          bodyLine.setVisible(false);
          line.setColor(Color.WHITE);
          bodyLine.setColor(255, 0, 0);
          line.setLineWidth(5);
          attachChild(bodyLine);
          attachChild(line);
          linesDrawn++;
          rectangle(linesDrawn);
        }
        linesDrawn++;
        i++;

        // final Text elapsedText = new Text(500, 360, activity.mFont, "Seconds elapsed:", "Seconds
        // elapsed: XXXXX".length(), activity.getVertexBufferObjectManager());
        // final Text fpsText = new Text(500, 400, activity.mFont, "FPS:", "FPS: XXXXX".length(),
        // activity.getVertexBufferObjectManager());

        // attachChild(elapsedText);
        // attachChild(fpsText);

        // final FPSCounter fpsCounter = new FPSCounter();

        //	registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() {
        //		@Override
        //		public void onTimePassed(final TimerHandler pTimerHandler) {
        //			elapsedText.setText("Globs Used: " + linesDrawn);
        // fpsText.setText("Globs Left: " + ( 150 - linesDrawn));
        //		}
        //	}));
        //  }

      }
    }
    return true;
  }

  private void rectangle(int b) {

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

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

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

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

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

    if (b > 150) five.setVisible(false);
  }

  private void destroy(int t) {

    if (t == 0) {
      activity.menu = 22;
      activity.grav = 0;
      Level1.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      String Score = String.valueOf(score);
      if (activity.isBeat(21).compareTo("true") != 0) {
        activity.setScore(21, Score);
        activity.unLockLevel(22, "true");
        activity.setScore(score);
        activity.saveHighScore();
        activity.loadHighScore();
      } else {
        int test = activity.getScore(21);
        if (score > test) {
          activity.setScore(21, Score);
          // activity.unLockLevel(2, "true");
          int newscore = (score - test);
          activity.setScore(newscore);
          activity.saveHighScore();
          activity.loadHighScore();
        }
      }

      MenuScene end = activity.scoreScene(22, score);
      setChildScene(end, false, true, true);

    } else if (t == 1) {
      activity.menu = 22;
      activity.grav = 0;
      Level1.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      MenuScene end = activity.deadScene(22);
      setChildScene(end, false, true, true);
    } else if (t == 2) {
      Level1.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
      activity.grav = 0;
      activity.setCurrentScene(new Level21());
    }

    // mPhysicsWorld.dispose();
    // mPhysicsWorld.destroyBody(lbod);
    // mPhysicsWorld.destroyBody(rbod);
    // mPhysicsWorld.destroyBody(Finish);
    // mPhysicsWorld.destroyBody(bod);
    // mPhysicsWorld.reset();

    // mPhysicsWorld.clearForces();
    // mPhysicsWorld.clearPhysicsConnectors();
    //  mPhysicsWorld.dispose();
    //   mPhysicsWorld = null;

    //    mScene.clearChildScene();
    // mScene.reset();
    //

    // activity.setCurrentScene(null);

  }
}
Exemplo n.º 11
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) {}
        });
  }
public class AntiGravityActivity extends BaseGameActivity
    implements IAccelerationListener, IOnSceneTouchListener {

  // ====================================================
  // CONSTANTS
  // ====================================================
  public static int cameraWidth = 800;
  public static int cameraHeight = 480;

  // ====================================================
  // VARIABLES
  // ====================================================
  public Scene mScene;
  public FixedStepPhysicsWorld mPhysicsWorld;
  public Body groundWallBody;
  public Body roofWallBody;
  public Body leftWallBody;
  public Body rightWallBody;

  Body gravityBody;
  Body antigravityBody;
  final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(2f, 0.5f, 0.9f);

  @Override
  public Engine onCreateEngine(final EngineOptions pEngineOptions) {
    return new FixedStepEngine(pEngineOptions, 60);
  }

  // ====================================================
  // CREATE ENGINE OPTIONS
  // ====================================================
  @Override
  public EngineOptions onCreateEngineOptions() {
    EngineOptions engineOptions =
        new EngineOptions(
            true,
            ScreenOrientation.LANDSCAPE_SENSOR,
            new FillResolutionPolicy(),
            new Camera(0, 0, cameraWidth, cameraHeight));
    engineOptions.getRenderOptions().setDithering(true);
    engineOptions.getRenderOptions().getConfigChooserOptions().setRequestedMultiSampling(true);
    engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    return engineOptions;
  }

  // ====================================================
  // CREATE RESOURCES
  // ====================================================
  @Override
  public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) {
    // Setup the ResourceManager.
    pOnCreateResourcesCallback.onCreateResourcesFinished();
  }

  // ====================================================
  // CREATE SCENE
  // ====================================================
  @Override
  public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) {
    mScene = new Scene();
    mScene.setBackground(new Background(0.9f, 0.9f, 0.9f));
    pOnCreateSceneCallback.onCreateSceneFinished(mScene);
  }

  // ====================================================
  // POPULATE SCENE
  // ====================================================

  @Override
  public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) {

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

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

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

    mScene.setOnSceneTouchListener(this);
    pOnPopulateSceneCallback.onPopulateSceneFinished();
  }

  @Override
  public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
    return true;
  }

  @Override
  public void onAccelerationAccuracyChanged(AccelerationData pAccelerationData) {}

  @Override
  public void onAccelerationChanged(AccelerationData pAccelerationData) {
    final Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY());
    this.mPhysicsWorld.setGravity(gravity);
    Vector2Pool.recycle(gravity);
  }

  @Override
  public void onResumeGame() {
    super.onResumeGame();
    this.enableAccelerationSensor(this);
  }

  @Override
  public void onPauseGame() {
    super.onPauseGame();
    this.disableAccelerationSensor();
  }
}
  @Override
  public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) {

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

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

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

    mScene.setOnSceneTouchListener(this);
    pOnPopulateSceneCallback.onPopulateSceneFinished();
  }
Exemplo n.º 14
0
class Puck extends Sprite implements Drawable {
  final FixtureDef fixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
  protected final Body body;
  protected boolean isHockeyplayer = false;
  private Vector2 startPosition;

  protected boolean isActive = false; /* if current body is set to move */

  public Puck(
      final float pX,
      final float pY,
      final TextureRegion pTextureRegion,
      final VertexBufferObjectManager pVertexBufferObjectManager,
      PhysicsWorld physicsWorld) {
    super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
    fixtureDef.filter.categoryBits = NightHockeyActivity.CATEGORY_PUCK;
    fixtureDef.filter.maskBits = NightHockeyActivity.CATEGORY_WALL;
    body = PhysicsFactory.createCircleBody(physicsWorld, this, BodyType.DynamicBody, fixtureDef);

    body.setLinearDamping(0.3f);
    body.setAngularDamping(0.3f);
    body.setUserData(this);

    setAlpha(0.2f);

    physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, true));

    startPosition = new Vector2(body.getPosition());
  }

  public void resetPosition() {
    body.setLinearVelocity(0, 0);
    body.setTransform(startPosition, 0);
  }

  public short getID() {
    return puckID;
  }

  @Override
  public int getXposition() {
    return (int) getX();
  }

  @Override
  public int getYposition() {
    return (int) getY();
  }

  @Override
  public int getWidthOfSpite() {
    return (int) getWidth();
  }

  @Override
  public int getHeightOfSprite() {
    return (int) getHeight();
  }

  @Override
  public void setActive(boolean active) {
    isActive = active;
  }

  @Override
  public boolean isActive() {
    return isActive;
  }

  @Override
  public Body getBody() {
    return body;
  }

  @Override
  public short getTeam() {
    return 0;
  }
}
Exemplo n.º 15
0
  private void createPhysics(final Camera camera, PhysicsWorld physicsWorld) {
    body =
        PhysicsFactory.createBoxBody(
            physicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));
    as =
        new AnimatedSprite(
            mHeight,
            mHeight,
            ResourcesManager.getInstance().player_region.deepCopy(),
            MainGameEngineActivity.getSharedInstance()
                .getSharedInstance()
                .getVertexBufferObjectManager());

    body.setUserData(as);
    body.setFixedRotation(true);

    physicsWorld.registerPhysicsConnector(
        new PhysicsConnector(this, body, true, false) {
          @Override
          public void onUpdate(float pSecondsElapsed) {
            super.onUpdate(pSecondsElapsed);
            camera.onUpdate(0.1f);

            if (jetfireCalled == false) {
              jetfire();
              jetfireCalled = true;
              jumpTimer = fuelLevel;
            }
            if (getY() <= 0) {
              onDie();
            }

            if (jumping) {

              jumpTimer--;

              if (jumpTimer >= 1) {

                GameScene scene =
                    (GameScene) MainGameEngineActivity.getSharedInstance().mCurrentScene;

                scene.fuelText.setText(("Fuel: " + jumpTimer));
                if (jumpTimer > fuelLevel / 2) {
                  scene.fuelText.setColor(Color.rgb(0, 255, 0));
                } else if (jumpTimer > fuelLevel / 3 && jumpTimer < fuelLevel / 2) {
                  scene.fuelText.setColor(Color.rgb(255, 255, 0));
                } else {
                  scene.fuelText.setColor(Color.rgb(255, 0, 0));
                }

                body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 4));
                pe.setCenter(getX(), getY());

              } else if (jumpTimer <= 0) {
                GameScene scene =
                    (GameScene) MainGameEngineActivity.getSharedInstance().mCurrentScene;

                scene.fuelText.setText(("Fuel:Charging"));
                jumpRecharge--;
                pe.setCenter(-1000, -1000);
              }
              if (jumpRecharge <= 0 && jumpTimer <= 0) {
                pe.setCenter(-1000, -1000);
                jumpRecharge = 75;
                jumpTimer = fuelLevel;
              }
            }

            if (right) {
              body.setLinearVelocity(new Vector2(5, body.getLinearVelocity().y));
            }
            if (left) {
              body.setLinearVelocity(new Vector2(-5, body.getLinearVelocity().y));
            }

            if (stop) {
              body.setLinearVelocity(new Vector2(0, body.getLinearVelocity().y));
            }
          }
        });
  }
Exemplo n.º 16
0
  /**
   * The constructor for the background class is where the background is created. It takes
   * parameters from the BaseLevel class, which are received from the JSON file for each level.. It
   * loads the textures in first. Then, a check is done to see what kind of level I am dealing with,
   * and if it is bonus, I set the walls, as the level uses the accelerometer. Otherwise I add the
   * background and it sets the parallax background.
   *
   * @param base_class
   * @param image -image passsed through from the JSON parser to be part of the background
   * @param sizeY - Y size of the image
   * @param sizeX - X size of the image
   * @param posX - X pos of the image
   * @param posY - Y pos of the image
   * @param pX - Parrallax
   * @param pY - Parralax
   */
  public Background(
      base_class my_base_class,
      String image,
      int sizeX,
      int sizeY,
      int posX,
      int posY,
      String pX,
      String pY) {
    base = my_base_class;

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

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

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

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

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

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

    BaseLevel.ParallaxBackground.attachParallaxEntity(
        new Parallax2dEntity(
            parallaxX,
            parallaxY,
            new Sprite(posX, posY, backgroundTextureRegion, base.getVertexBufferObjectManager()),
            false,
            false));
  }