예제 #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
  @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;
  }
예제 #3
0
  @Override
  public void onPopulateScene(final Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback)
      throws Exception {
    this.initDimension();
    this.initAction();
    this.initMatrix();
    this.initHeader();
    this.initPlate();
    this.initScore();
    this.initBulles();

    pScene.setTouchAreaBindingOnActionDownEnabled(true);

    super.onPopulateScene(pScene, pOnPopulateSceneCallback);
  }
예제 #4
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
  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;
  }