public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

    boton =
        new ButtonSprite(
            100,
            100,
            this.mBotonTextureRegion,
            this.getVertexBufferObjectManager(),
            new OnClickListener() {

              public void onClick(
                  ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
                boton.setPosition(boton.getX() + 20, boton.getY() + 20);
              }
            });

    scene.attachChild(boton);
    scene.registerTouchArea(boton);

    return scene;
  }
Esempio n. 2
0
  @Override
  protected Scene onCreateScene() {
    this.mScene = new Scene();
    this.xCoords = new float[COLUMNS];
    this.yCoords = new float[ROWS];
    float space =
        Math.min((float) CAMERA_HEIGHT / (float) ROWS, (float) CAMERA_WIDTH / (float) COLUMNS);
    float xCord = (CAMERA_WIDTH - space * (COLUMNS - 1)) / 2f;
    float yCord = (CAMERA_HEIGHT - space * (ROWS - 1)) / 2f;
    this.maps = new GomokuTiledSprite[COLUMNS - 1][ROWS - 1];
    VertexBufferObjectManager VBOManager = this.getVertexBufferObjectManager();
    Log.w("SPACE", "" + space);

    for (int i = 0; i < COLUMNS; i++) {
      xCoords[i] = xCord + i * space;
    }

    for (int i = 0; i < ROWS; i++) {
      yCoords[i] = yCord + i * space;
    }

    for (int i = 0; i < COLUMNS; i++) {
      Line line =
          new Line(xCoords[i], yCoords[0], xCoords[i], yCoords[ROWS - 1], STROKE_WIDTH, VBOManager);
      line.setColor(0f, 1f, 1f);
      mScene.attachChild(line);
    }

    for (int i = 0; i < ROWS; i++) {
      Line line =
          new Line(
              xCoords[0], yCoords[i], xCoords[COLUMNS - 1], yCoords[i], STROKE_WIDTH, VBOManager);
      line.setColor(0f, 1f, 1f);
      mScene.attachChild(line);
    }

    mScene.setTouchAreaBindingOnActionDownEnabled(true);
    mScene.setTouchAreaBindingOnActionMoveEnabled(false);

    for (int i = 0; i < COLUMNS - 1; i++) {
      for (int j = 0; j < ROWS - 1; j++) {
        this.maps[i][j] =
            new GomokuTiledSprite(
                xCoords[i] + space / 2f,
                yCoords[j] + space / 2f,
                blankRegion,
                xRegion,
                oRegion,
                winRegion,
                VBOManager,
                this);
        mScene.registerTouchArea(maps[i][j]);
        mScene.attachChild(maps[i][j]);
        maps[i][j].setCoordinates(i, j);
      }
    }

    return mScene;
  }
  public LevelViewButtonSelector attachButtonsToScene(Scene pScene, boolean pTouchEn) {
    for (LevelViewButton btn : getButtons()) {
      pScene.attachChild(btn);

      if (pTouchEn == true) {
        pScene.registerTouchArea(btn);
      }
    }

    return this;
  }
  @Override
  protected Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());
    // TODO Auto-generated method stub
    scene = new Scene();
    try {
      final TMXLoader tmxLoader =
          new TMXLoader(
              this.getAssets(),
              this.mEngine.getTextureManager(),
              TextureOptions.BILINEAR_PREMULTIPLYALPHA,
              this.getVertexBufferObjectManager(),
              new ITMXTilePropertiesListener() {
                @Override
                public void onTMXTileWithPropertiesCreated(
                    final TMXTiledMap pTMXTiledMap,
                    final TMXLayer pTMXLayer,
                    final TMXTile pTMXTile,
                    final TMXProperties<TMXTileProperty> pTMXTileProperties) {}
              });
      this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/map_pro.tmx");

    } catch (final TMXLoadException e) {
      Debug.e(e);
    }
    final TMXLayer tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);

    scene.attachChild(tmxLayer);

    /* Make the camera not exceed the bounds of the TMXEntity. */
    this.mBoundChaseCamera.setBounds(0, 0, tmxLayer.getHeight(), tmxLayer.getWidth());
    this.mBoundChaseCamera.setBoundsEnabled(true);

    final float centerX = (MyCamera.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final float centerY = (MyCamera.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
    face =
        new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager());

    scene.attachChild(face);

    // Add playerSprite to screen
    initplayerSprite(scene, this.mPlayerTextureRegion);

    // Scene UpdateHandler

    scene.setTouchAreaBindingOnActionDownEnabled(true);
    scene.setOnAreaTouchListener(pOnAreaTouchListener);
    scene.registerUpdateHandler(pUpdateHandler);
    scene.registerTouchArea(tmxLayer);
    scene.setOnSceneTouchListener(pOnSceneTouchListener);
    return scene;
  }
  public LevelViewButtonSelector attachButtonsToScene(
      Scene pScene, boolean pTouchEn, IEntityModifier pEntityModifier) {
    for (LevelViewButton btn : getButtons()) {
      pScene.attachChild(btn);

      if (pTouchEn == true) {
        pScene.registerTouchArea(btn);
      }
      btn.registerEntityModifier(pEntityModifier);
    }

    return this;
  }
Esempio n. 6
0
  public void enable() {
    enabled = true;

    this.detachChild(fgText);
    this.detachChild(fgRect);
    this.detachChild(bgRect);

    fgRect.setColor(FGRECT_COLOR);

    mScene.registerTouchArea(bgRect);

    this.attachChild(bgRect);
    this.attachChild(fgRect);
    this.attachChild(fgText);
  }
Esempio n. 7
0
  public void addGimmicsButton(
      Scene mScene,
      String[] sound,
      int[] image,
      TexturePackTextureRegionLibrary pTexturePackTextureRegionLibrary) {

    ITextureRegion[] ttrGimmic = new ITextureRegion[3];
    sprGimmic = new Sprite[3];
    final Sound[] sndGimmic = new Sound[3];
    int[] start = {244, 436, 612};

    for (int i = 0; i < sprGimmic.length; i++) {
      // load sound
      sndGimmic[i] = loadSoundResourceFromSD(sound[i]);

      ttrGimmic[i] = pTexturePackTextureRegionLibrary.get(image[i]);
      final int tmp = i;
      sprGimmic[i] =
          new Sprite(start[i], 496, ttrGimmic[i], this.getVertexBufferObjectManager()) {

            @Override
            public boolean onAreaTouched(
                final TouchEvent pSceneTouchEvent,
                final float pTouchAreaLocalX,
                final float pTouchAreaLocalY) {
              if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
                if (isTouchGimmic[tmp]) {
                  if (tmp == 2) {
                    combineGimmic3WithAction();
                  } else {
                    sndGimmic[tmp].play();
                  }
                  sprGimmic[tmp].registerEntityModifier(
                      new SequenceEntityModifier(
                          new ScaleModifier(0.35f, 1, 1.3f), new ScaleModifier(0.35f, 1.3f, 1f)));
                }
                return true;
              }
              return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
            }
          };
      mScene.registerTouchArea(sprGimmic[i]);
      mScene.attachChild(sprGimmic[i]);
    }

    mScene.setTouchAreaBindingOnActionDownEnabled(true);
    mScene.setTouchAreaBindingOnActionMoveEnabled(true);
  }
  @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();
  }
Esempio n. 9
0
  /**
   * Create the level tiles with a customized ITextureRegion representation as well as a customized
   * Font.
   *
   * @param pTextureRegion The ITextureRegion to supply each of the level tiles.
   * @param star The Font to be displayed by Text written on the tiles, specifying tile level number
   *     for example.
   */
  public void createTiles(
      final LinkedList<ITextureRegion> pTextureRegion, final ITiledTextureRegion star) {

    /* Temp coordinates for placing level tiles */
    float tempX = this.mInitialX + pTextureRegion.get(0).getWidth() * 0.5f;
    float tempY = this.mInitialY - pTextureRegion.get(0).getHeight() * 0.5f;

    /* Current level of the tile to be placed */
    int currentTileLevel = 1;

    /*
     * Loop through the Rows, adjusting tempY coordinate after each
     * iteration
     */
    for (int i = 0; i < ROWS; i++) {

      /*
       * Loop through the column positions, placing a LevelTile in each
       * column
       */
      for (int o = 0; o < COLUMNS; o++) {

        final boolean locked;

        /* Determine whether the current tile is locked or not */
        if (currentTileLevel <= mMaxLevel) {
          locked = false;
        } else {
          locked = true;
        }

        /* Create a level tile */
        LevelTile levelTile =
            new LevelTile(
                tempX,
                tempY,
                locked,
                currentTileLevel,
                pTextureRegion.get(currentTileLevel - 1),
                star);

        /*
         * Attach the level tile's text based on the locked and
         * currentTileLevel variables pass to its constructor
         */

        levelTile.attachStar();

        /* Register & Attach the levelTile object to the LevelSelector */
        mScene.registerTouchArea(levelTile);
        this.attachChild(levelTile);

        /* Increment the tempX coordinate to the next column */
        tempX = tempX + TILE_DIMENSION + TILE_PADDING;

        /* Increment the level tile count */
        currentTileLevel++;
      }

      /* Reposition the tempX coordinate back to the first row (far left) */
      tempX = mInitialX + TILE_DIMENSION * 0.5f;

      /* Reposition the tempY coordinate for the next row to apply tiles */
      tempY = tempY + TILE_DIMENSION + TILE_PADDING + 50;
    }
  }
Esempio n. 10
0
  public ChromaButton(float x, float y, int fontSize, String text, boolean e, Scene s) {
    super(0, 0);

    mScene = s;
    fgText =
        new ChromaText(fontSize)
            .getText(text, x + (BGRECT_MARGIN_WIDTH), y + (BGRECT_MARGIN_HEIGHT), TEXT_LEFT);

    posX = x;
    posY = y;

    textHeight = fgText.getHeightScaled();
    textWidth = fgText.getWidthScaled();

    enabled = e;

    fgRect =
        new Rectangle(
            x + FGRECT_MARGIN_WIDTH,
            y + FGRECT_MARGIN_HEIGHT,
            textWidth + (FGRECT_MARGIN_WIDTH * 2),
            textHeight + (FGRECT_MARGIN_HEIGHT * 2),
            ChromaTools.mVBO) {};

    bgRect =
        new Rectangle(
            x,
            y,
            textWidth + (BGRECT_MARGIN_WIDTH * 2),
            textHeight + (BGRECT_MARGIN_HEIGHT * 2),
            ChromaTools.mVBO) {
          @Override
          public boolean onAreaTouched(
              final TouchEvent pSceneTouchEvent,
              final float pTouchAreaLocalX,
              final float pTouchAreaLocalY) {

            int action = pSceneTouchEvent.getAction();

            if (action == TouchEvent.ACTION_DOWN) {
              ColorModifier cm = new ColorModifier(1, FGRECT_COLOR_PRESSED, FGRECT_COLOR);
              fgRect.clearEntityModifiers();
              fgRect.registerEntityModifier(cm);
              onTouch();
            }

            return true;
          }
        };

    if (enabled) {
      fgRect.setColor(FGRECT_COLOR);
    } else {
      fgRect.setColor(FGRECT_COLOR_DISABLED);
    }

    bgRect.setColor(BGRECT_COLOR);

    this.attachChild(bgRect);
    this.attachChild(fgRect);
    this.attachChild(fgText);

    if (enabled) {
      mScene.registerTouchArea(bgRect);
    }
  }
Esempio n. 11
0
 public void rebuild() {
   if (enabled) mScene.registerTouchArea(bgRect);
 }
  @Override
  protected Scene onCreateScene() {
    // 1 - Create new scene
    final Scene scene = new Scene();
    Sprite backgroundSprite =
        new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
    scene.attachChild(backgroundSprite);

    // 2 - Add the towers
    mTower1 = new Sprite(192, 63, this.mTowerTextureRegion, getVertexBufferObjectManager());
    mTower2 = new Sprite(400, 63, this.mTowerTextureRegion, getVertexBufferObjectManager());
    mTower3 = new Sprite(604, 63, this.mTowerTextureRegion, getVertexBufferObjectManager());
    scene.attachChild(mTower1);
    scene.attachChild(mTower2);
    scene.attachChild(mTower3);

    // 3 - Create the rings
    Ring ring1 =
        new Ring(1, 139, 174, this.mRing1, getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false;
            this.setPosition(
                pSceneTouchEvent.getX() - this.getWidth() / 2,
                pSceneTouchEvent.getY() - this.getHeight() / 2);
            if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
              checkForCollisionsWithTowers(this);
            }
            return true;
          }
        };
    Ring ring2 =
        new Ring(2, 118, 212, this.mRing2, getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false;
            this.setPosition(
                pSceneTouchEvent.getX() - this.getWidth() / 2,
                pSceneTouchEvent.getY() - this.getHeight() / 2);
            if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
              checkForCollisionsWithTowers(this);
            }
            return true;
          }
        };
    Ring ring3 =
        new Ring(3, 97, 255, this.mRing3, getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false;
            this.setPosition(
                pSceneTouchEvent.getX() - this.getWidth() / 2,
                pSceneTouchEvent.getY() - this.getHeight() / 2);
            if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
              checkForCollisionsWithTowers(this);
            }
            return true;
          }
        };

    scene.attachChild(ring1);
    scene.attachChild(ring2);
    scene.attachChild(ring3);

    // 4 - Add all rings to stack one
    this.mStack1.add(ring3);
    this.mStack1.add(ring2);
    this.mStack1.add(ring1);
    // 5 - Initialize starting position for each ring
    ring1.setmStack(mStack1);
    ring2.setmStack(mStack1);
    ring3.setmStack(mStack1);
    ring1.setmTower(mTower1);
    ring2.setmTower(mTower1);
    ring3.setmTower(mTower1);
    // 6 - Add touch handlers
    scene.registerTouchArea(ring1);
    scene.registerTouchArea(ring2);
    scene.registerTouchArea(ring3);
    scene.setTouchAreaBindingOnActionDownEnabled(true);
    return scene;
  }