Пример #1
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;
  }
Пример #2
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);
  }