@Override
  public EngineOptions onCreateEngineOptions() {
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    final EngineOptions engineOptions =
        new EngineOptions(
            true,
            ScreenOrientation.LANDSCAPE_SENSOR,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
            this.mCamera);
    engineOptions.getTouchOptions().setNeedsMultiTouch(true);

    if (MultiTouch.isSupported(this)) {
      if (MultiTouch.isSupportedDistinct(this)) {
        Toast.makeText(
                this,
                "MultiTouch detected --> Both controls will work properly!",
                Toast.LENGTH_SHORT)
            .show();
      } else {
        this.mPlaceOnScreenControlsAtDifferentVerticalLocations = true;
        Toast.makeText(
                this,
                "MultiTouch detected, but your device has problems distinguishing between fingers.\n\nControls are placed at different vertical locations.",
                Toast.LENGTH_LONG)
            .show();
      }
    } else {
      Toast.makeText(
              this,
              "Sorry your device does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)\n\nControls are placed at different vertical locations.",
              Toast.LENGTH_LONG)
          .show();
    }

    return engineOptions;
  }
Beispiel #2
0
  /**
   * Defines the options of the engine, such as the type of camera and screen orientation
   *
   * @return
   */
  @Override
  public EngineOptions onCreateEngineOptions() {
    smoothCamera =
        new SmoothCamera(
            0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, maxVelocityX, maxVelocityY, maxZoomFactorChange);
    smoothCamera.setBounds(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    smoothCamera.setBoundsEnabled(true);
    IResolutionPolicy resolutionPolicy = new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT);
    EngineOptions engineOptions =
        new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, resolutionPolicy, smoothCamera);
    engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    engineOptions.getTouchOptions().setNeedsMultiTouch(true);

    // Check for MultiTouch support
    if (!MultiTouch.isSupported(this)) {
      Toast.makeText(
              this, getResources().getString(R.string.multitouch_support), Toast.LENGTH_SHORT)
          .show();
      finish();
    }
    return engineOptions;
  }
Beispiel #3
0
  // ***********************************************************
  // CONSTRUCTOR
  // ***********************************************************
  public GameScene(MapType type) {
    instance = this;

    gameMap = new GameMap(type);

    // Zoom-Camera configuration
    this.setOnAreaTouchTraversalFrontToBack();
    this.mScrollDetector = new SurfaceScrollDetector(this);

    activity = TowerDefenseActivity.getSharedInstance();
    resourceManager = ResourceManager.getInstance();

    if (MultiTouch.isSupported(activity)) {
      this.mPinchZoomDetector = new PinchZoomDetector(this);
    } else {
      this.mPinchZoomDetector = null;
    }

    this.setOnSceneTouchListener(this);
    this.setOnSceneTouchListenerBindingOnActionDownEnabled(true);

    fingerOnSceneCount = 0;
    zooming = false;

    String map = "";

    if (type == MapType.DESERT) map = "tmx/new_desert_path.tmx";
    else if (type == MapType.GRASS) map = "tmx/grass_path.tmx";
    else if (type == MapType.TUNDRA) map = "tmx/tundra_path.tmx";

    try {
      final TMXLoader tmxLoader =
          new TMXLoader(
              activity.getAssets(),
              activity.getEngine().getTextureManager(),
              TextureOptions.BILINEAR_PREMULTIPLYALPHA,
              activity.getVertexBufferObjectManager(),
              new ITMXTilePropertiesListener() {
                @Override
                public void onTMXTileWithPropertiesCreated(
                    final TMXTiledMap pTMXTiledMap,
                    final TMXLayer pTMXLayer,
                    final TMXTile pTMXTile,
                    final TMXProperties<TMXTileProperty> pTMXTileProperties) {}
              });
      this.mTMXTiledMap = tmxLoader.loadFromAsset(map);
    } catch (final TMXLoadException e) {
      Debug.e(e);
    }

    gameMap.setMap(mTMXTiledMap);

    tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);
    tmxLayer.setIgnoreUpdate(true);
    this.attachChild(tmxLayer);

    mCamera = activity.getCamera();
    this.mCamera.setBounds(
        0, (mCamera.getHeight() - tmxLayer.getHeight()), tmxLayer.getWidth(), tmxLayer.getHeight());
    this.mCamera.setBoundsEnabled(true);

    float camera_width = activity.getCamera().getWidth();
    float camera_height = activity.getCamera().getHeight();
    if (camera_width / tmxLayer.getHeight() >= camera_height / tmxLayer.getWidth())
      maxZoom = camera_width / (tmxLayer.getHeight() * 2);
    else maxZoom = camera_height / (tmxLayer.getWidth() * 2);

    // 2-dimensional array of tiles
    TMXTile[][] tiles = tmxLayer.getTMXTiles();

    startTile = null;
    endTile = null;
    outer:
    for (int i = 0; i < tiles.length; i++) {
      for (int j = 0; j < tiles[0].length; j++) {

        int[] start = gameMap.getStartTile();
        int[] end = gameMap.getEndTile();

        if (i == start[0] && j == start[1]) {
          startTile = tiles[i][j];
        } else if (i == end[0] && j == end[1]) {
          endTile = tiles[i][j];
          break outer;
        }
      }
    }

    money = 60;
    lives = 20;

    // Initializes the HUD
    panel = new BottomPanel(mCamera, gameMap);
    this.attachChild(panel);

    TowerTile.initializeMap();

    TowerTile turretTile = new TowerTile(resourceManager.getTurretTowerRegion());
    panel.placeTowerAccess(turretTile, 1);

    TowerTile iceTile = new TowerTile(resourceManager.getIceTowerRegion());
    panel.placeTowerAccess(iceTile, 2);

    TowerTile dartTile = new TowerTile(resourceManager.getDartTowerRegion());
    panel.placeTowerAccess(dartTile, 3);

    TowerTile spikeTile = new TowerTile(resourceManager.getSpikeTowerRegion());
    panel.placeTowerAccess(spikeTile, 4);

    TowerTile flameTile = new TowerTile(resourceManager.getFlameTowerRegion());
    panel.placeTowerAccess(flameTile, 5);

    startButton =
        new AnimatedSprite(
            0.0f,
            0.0f,
            resourceManager.getStartButtonRegion(),
            activity.getVertexBufferObjectManager()) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

            if (readyToPressAgain) {
              startCurrentWave();

              readyToPressAgain = false;
              this.registerUpdateHandler(
                  new TimerHandler(
                      1.0f,
                      new ITimerCallback() {

                        @Override
                        public void onTimePassed(TimerHandler pTimerHandler) {
                          readyToPressAgain = true;
                          unregisterUpdateHandler(pTimerHandler);
                        }
                      }));
            }

            panel.detachTowerTextDescription();

            return true;
          }
        };

    startButton.setScale(0.473372781f);
    panel.placeStartButton(startButton);

    // Getting texture regions for submenu items
    SubMenuManager.getDeleteRegion(resourceManager.getDeleteOptionRegion());
    SubMenuManager.getUpgradeRegion(resourceManager.getUpgradeOptionRegion());
    SubMenuManager.getReticalRegion(resourceManager.getTowerSightRegion());

    // Initializing tower array
    towers = new ArrayList<ITower>();

    downCoords = new Vector2();

    blockedTileList = new ArrayList<TMXTile>();

    aStarHelper = new AStarPathHelper(mTMXTiledMap, endTile);
    waveGenerator = new WaveHelper();
    waveCount = 0;
    deadEnemies = 0;

    waveFinished = true;
    initializedNewWave = false;

    // Sets up paths/move modifiers of enemies in the first wave
    initializeNextWave();

    FlameTower.initialize(resourceManager.getFlameParticleRegion());

    Log.i(
        "Info",
        "Dead Enemies: "
            + deadEnemies
            + " Finished Enemies: "
            + aStarHelper.getNumberOfEnemiesFinished()
            + " Current Wave Length: "
            + currentWave.getEnemies().size());

    speedFactor = 0.5f;
    readyToPressAgain = true;

    // collisionDetect = new TimerHandler((float)0.0125/speedFactor, true, new ITimerCallback() {

    collisionDetect =
        new TimerHandler(
            0.025f,
            true,
            new ITimerCallback() {

              @Override
              public void onTimePassed(TimerHandler pTimerHandler) {
                collisionDetect();
              }
            });

    enemyQueues =
        new TimerHandler(
            0.3f,
            true,
            new ITimerCallback() {
              @Override
              public void onTimePassed(TimerHandler pTimerHandler) {
                addEnemiesToTowerQueues();
              }
            });

    disableBackButton = false;
  }