Exemplo n.º 1
0
  private void loadGameGraphics() {

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/game/");
    gameTextureAtlas =
        new BuildableBitmapTextureAtlas(
            activity.getTextureManager(),
            1024,
            1024,
            TextureOptions.REPEATING_NEAREST_PREMULTIPLYALPHA);
    rockTop_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Red_Rock_Top.png");
    rockMid_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Red_Rock_Middle.png");
    rockOre_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Ore_Rock.png");
    player_region =
        BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
            gameTextureAtlas, activity, "player.png", 1, 1);
    dpad_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Dpad_Notpressed.png");
    try {
      this.gameTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));
      this.gameTextureAtlas.load();
    } catch (final TextureAtlasBuilderException e) {
      Debug.e(e);
    }
  }
Exemplo n.º 2
0
  @Override
  public void loadScene() {

    menuTextureAtlas =
        new BuildableBitmapTextureAtlas(
            activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    menu_background_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "menu_background.png");
    play_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "play.png");
    options_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "options.png");

    try {
      this.menuTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));

    } catch (TextureAtlasBuilderException e) {
      Debug.e(e);
    }
    this.menuTextureAtlas.load();
  }
Exemplo n.º 3
0
  @Override
  public void onDestroy() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onDestroy"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    super.onDestroy();

    this.mEngine.onDestroy();

    try {
      this.onDestroyResources();
    } catch (final Throwable pThrowable) {
      Debug.e(
          this.getClass().getSimpleName()
              + ".onDestroyResources failed."
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')",
          pThrowable);
    }

    this.onGameDestroyed();

    this.mEngine = null;
  }
 @Override
 protected void onReadTransmissionData(final DataInputStream pDataInputStream) throws IOException {
   ObjectInputStream reader = new ObjectInputStream(pDataInputStream);
   try {
     this.mServerList = (HashMap<String, GameServer>) reader.readObject();
   } catch (ClassNotFoundException e) {
     Debug.e(e);
   }
 }
 public Sound createSound(String soundFileName) {
   Sound sound = null;
   try {
     sound = SoundFactory.createSoundFromAsset(engine.getSoundManager(), context, soundFileName);
   } catch (final IOException e) {
     Debug.e(e);
   }
   return sound;
 }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
 public void writeScore(Context ctx) {
   DataOutputStream out;
   try {
     out = new DataOutputStream(ctx.openFileOutput(FILENAME, Context.MODE_APPEND));
     out.writeInt(getScore());
     out.writeChar(' ');
     out.writeUTF(mName);
     out.flush();
     out.close();
   } catch (IOException e) {
     Debug.e(e);
   }
 }
  @Override
  public Bitmap onLoadBitmap(final Config pBitmapConfig) {
    final Bitmap bitmap =
        this.ensureLoadedBitmapIsMutable(
            this.mBitmapTextureAtlasSource.onLoadBitmap(pBitmapConfig));

    final Canvas canvas = new Canvas(bitmap);
    try {
      this.onDecorateBitmap(canvas);
    } catch (final Exception e) {
      Debug.e(e);
    }
    return bitmap;
  }
Exemplo n.º 9
0
  @Override
  protected void onCreateResources() {
    try {
      final TMXLoader tmxLoader =
          new TMXLoader(
              getAssets(),
              getTextureManager(),
              TextureOptions.NEAREST,
              getVertexBufferObjectManager());
      this.tiledMap = tmxLoader.loadFromAsset("TileMap_new.tmx");

      // this.tiledMap.setIsometricDrawMethod(TMXConstants.DRAW_METHOD_ISOMETRIC_CULLING_PADDING);
    } catch (final TMXLoadException e) {
      Debug.e(e);
    }
  }
Exemplo n.º 10
0
 private void acquireWakeLock(final WakeLockOptions pWakeLockOptions) {
   if (pWakeLockOptions == WakeLockOptions.SCREEN_ON) {
     ActivityUtils.keepScreenOn(getActivity());
   } else {
     final PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
     this.mWakeLock =
         pm.newWakeLock(
             pWakeLockOptions.getFlag() | PowerManager.ON_AFTER_RELEASE, Constants.DEBUGTAG);
     try {
       this.mWakeLock.acquire();
     } catch (final SecurityException pSecurityException) {
       Debug.e(
           "You have to add\n\t<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>\nto your AndroidManifest.xml !",
           pSecurityException);
     }
   }
 }
Exemplo n.º 11
0
 @Override
 public synchronized void onGameCreated() {
   this.mGameCreated = true;
   if (this.mOnReloadResourcesScheduled) {
     this.mOnReloadResourcesScheduled = false;
     try {
       this.onReloadResources();
     } catch (final Throwable pThrowable) {
       Debug.e(
           this.getClass().getSimpleName()
               + ".onReloadResources failed."
               + " @(Thread: '"
               + Thread.currentThread().getName()
               + "')",
           pThrowable);
     }
   }
   loadKaraokeComplete();
 }
  @Override
  public void load(Context context, Engine engine) {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/main-menu/");

    BuildableBitmapTextureAtlas bitmapTextureAtlas =
        new BuildableBitmapTextureAtlas(
            engine.getTextureManager(),
            1024,
            1024,
            BitmapTextureFormat.RGBA_8888,
            TextureOptions.BILINEAR);

    backgroundTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "background.png");
    titleTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "title.png");
    easyUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "easy_unlock.png");
    normalUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "normal_unlock.png");
    hardUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "hard_unlock.png");
    normalLockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "normal_lock.png");
    hardLockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "hard_lock.png");

    try {
      bitmapTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));
      bitmapTextureAtlas.load();
    } catch (TextureAtlasBuilderException e) {
      Debug.e(e);
    }
  }
  @Override
  public Bitmap onLoadBitmap(final Config pBitmapConfig) {
    final Picture picture = this.mPicture;
    if (picture == null) {
      Debug.e("Failed loading Bitmap in " + this.getClass().getSimpleName() + ".");
      return null;
    }

    final Bitmap bitmap =
        Bitmap.createBitmap(this.mTextureWidth, this.mTextureHeight, pBitmapConfig);
    final Canvas canvas = new Canvas(bitmap);

    final float scaleX = (float) this.mTextureWidth / this.mPicture.getWidth();
    final float scaleY = (float) this.mTextureHeight / this.mPicture.getHeight();
    canvas.scale(scaleX, scaleY, 0, 0);

    picture.draw(canvas);

    return bitmap;
  }
Exemplo n.º 14
0
 private void loadMenuGraphics() {
   BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/menu/");
   menuTextureAtlas =
       new BuildableBitmapTextureAtlas(
           activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
   menu_background_region =
       BitmapTextureAtlasTextureRegionFactory.createFromAsset(
           menuTextureAtlas, activity, "menu_background.png");
   play_region =
       BitmapTextureAtlasTextureRegionFactory.createFromAsset(
           menuTextureAtlas, activity, "play.png");
   options_region =
       BitmapTextureAtlasTextureRegionFactory.createFromAsset(
           menuTextureAtlas, activity, "options.png");
   try {
     this.menuTextureAtlas.build(
         new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
     this.menuTextureAtlas.load();
   } catch (final TextureAtlasBuilderException e) {
     Debug.e(e);
   }
 }
  @Override
  protected void onCreateResources() {
    // TODO Auto-generated method stub
    try {
      // 1 - Set up bitmap textures
      ITexture backgroundTexture =
          new BitmapTexture(
              this.getTextureManager(),
              new IInputStreamOpener() {
                public InputStream open() throws IOException {
                  return getAssets().open("gfx/background.png");
                }
              });
      ITexture towerTexture =
          new BitmapTexture(
              this.getTextureManager(),
              new IInputStreamOpener() {
                public InputStream open() throws IOException {
                  return getAssets().open("gfx/tower.png");
                }
              });
      ITexture ring1 =
          new BitmapTexture(
              this.getTextureManager(),
              new IInputStreamOpener() {
                public InputStream open() throws IOException {
                  return getAssets().open("gfx/ring1.png");
                }
              });
      ITexture ring2 =
          new BitmapTexture(
              this.getTextureManager(),
              new IInputStreamOpener() {
                public InputStream open() throws IOException {
                  return getAssets().open("gfx/ring2.png");
                }
              });
      ITexture ring3 =
          new BitmapTexture(
              this.getTextureManager(),
              new IInputStreamOpener() {
                public InputStream open() throws IOException {
                  return getAssets().open("gfx/ring3.png");
                }
              });
      // 2 - Load bitmap textures into VRAM
      backgroundTexture.load();
      towerTexture.load();
      ring1.load();
      ring2.load();
      ring3.load();

      // 3 - Set up texture regions
      this.mBackgroundTextureRegion = TextureRegionFactory.extractFromTexture(backgroundTexture);
      this.mTowerTextureRegion = TextureRegionFactory.extractFromTexture(towerTexture);
      this.mRing1 = TextureRegionFactory.extractFromTexture(ring1);
      this.mRing2 = TextureRegionFactory.extractFromTexture(ring2);
      this.mRing3 = TextureRegionFactory.extractFromTexture(ring3);

      // 4 - Create the stacks
      this.mStack1 = new Stack();
      this.mStack2 = new Stack();
      this.mStack3 = new Stack();
    } catch (IOException e) {
      Debug.e(e.getStackTrace().toString());
    }
  }
Exemplo n.º 16
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;
  }
Exemplo n.º 17
0
  protected synchronized void onCreateGame() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onCreateGame"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    final OnPopulateSceneCallback onPopulateSceneCallback =
        new OnPopulateSceneCallback() {
          @Override
          public void onPopulateSceneFinished() {
            try {
              if (BuildConfig.DEBUG) {
                Debug.d(
                    BaseGameFragment.this.getClass().getSimpleName()
                        + ".onGameCreated"
                        + " @(Thread: '"
                        + Thread.currentThread().getName()
                        + "')");
              }

              BaseGameFragment.this.onGameCreated();
            } catch (final Throwable pThrowable) {
              Debug.e(
                  BaseGameFragment.this.getClass().getSimpleName()
                      + ".onGameCreated failed."
                      + " @(Thread: '"
                      + Thread.currentThread().getName()
                      + "')",
                  pThrowable);
            }

            BaseGameFragment.this.callGameResumedOnUIThread();
          }
        };

    final OnCreateSceneCallback onCreateSceneCallback =
        new OnCreateSceneCallback() {
          @Override
          public void onCreateSceneFinished(final Scene pScene) {
            BaseGameFragment.this.mEngine.setScene(pScene);

            try {
              if (BuildConfig.DEBUG) {
                Debug.d(
                    BaseGameFragment.this.getClass().getSimpleName()
                        + ".onPopulateScene"
                        + " @(Thread: '"
                        + Thread.currentThread().getName()
                        + "')");
              }

              BaseGameFragment.this.onPopulateScene(pScene, onPopulateSceneCallback);
            } catch (final Throwable pThrowable) {
              Debug.e(
                  BaseGameFragment.this.getClass().getSimpleName()
                      + ".onPopulateScene failed."
                      + " @(Thread: '"
                      + Thread.currentThread().getName()
                      + "')",
                  pThrowable);
            }
          }
        };

    final OnCreateResourcesCallback onCreateResourcesCallback =
        new OnCreateResourcesCallback() {
          @Override
          public void onCreateResourcesFinished() {
            try {
              if (BuildConfig.DEBUG) {
                Debug.d(
                    BaseGameFragment.this.getClass().getSimpleName()
                        + ".onCreateScene"
                        + " @(Thread: '"
                        + Thread.currentThread().getName()
                        + "')");
              }

              BaseGameFragment.this.onCreateScene(onCreateSceneCallback);
            } catch (final Throwable pThrowable) {
              Debug.e(
                  BaseGameFragment.this.getClass().getSimpleName()
                      + ".onCreateScene failed."
                      + " @(Thread: '"
                      + Thread.currentThread().getName()
                      + "')",
                  pThrowable);
            }
          }
        };

    try {
      if (BuildConfig.DEBUG) {
        Debug.d(
            this.getClass().getSimpleName()
                + ".onCreateResources"
                + " @(Thread: '"
                + Thread.currentThread().getName()
                + "')");
      }

      this.onCreateResources(onCreateResourcesCallback);
    } catch (final Throwable pThrowable) {
      Debug.e(
          this.getClass().getSimpleName()
              + ".onCreateGame failed."
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')",
          pThrowable);
    }
  }