Back to project page ssniper-andengine.
The source code is released under:
Apache License
If you think the Android project ssniper-andengine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cladophora.ssniper.scene; // w ww . j a v a 2 s .co m import com.cladophora.ssniper.BaseActivity; import com.cladophora.ssniper.HUDManager; import com.cladophora.ssniper.andengine.IRandomTimerCallBack; import com.cladophora.ssniper.andengine.RandomTimerHandler; import com.cladophora.ssniper.entity.EnemyLayer; import com.cladophora.ssniper.entity.Rifle; import org.andengine.entity.scene.CameraScene; import java.util.Timer; import java.util.TimerTask; /** * Created by jmar on 1/27/14. */ public class SurvivorScene extends CameraScene { public static SurvivorScene instance; private static RandomTimerHandler randomSpawnTimer; public static int maxSpawnSize; public static float minSpawnTime; public static float maxSpawnTime; public static boolean inSurvivorMode; public static Timer survivorModeTimer; public static long millisecondsToNextDifficulty; public static int maxEnemiesOnScreen; public static int minEnemiesOnScreen; public static int absoluteMaxEnemiesOnScreen = 32; public static float currentMinMovementSpeed = 0.03f; // max movement in terms of camera width public static float currentMaxMovementSpeed = 0.07f; // max movement in terms of camera width public static float absoluteMaxMovementSpeed = 0.20f; // max movement in terms of camera width public static float bossEnemyPct; public static float superBossEnemyPct; public static float megaBossEnemyPct; public SurvivorScene() { instance = this; inSurvivorMode = true; mCamera = BaseActivity.mCamera; resetTimer(); GameScene.inGame = true; setBackgroundEnabled(false); setInitialGameState(); setRandomSpawnTimer(); EnemyLayer.addEnemies(8); survivorModeTimer.schedule(new IncreaseDifficultyTask(), millisecondsToNextDifficulty); } public static void setInitialGameState() { maxSpawnSize = 3; minSpawnTime = 2.4f; maxSpawnTime = 8.0f; millisecondsToNextDifficulty = 16000; maxEnemiesOnScreen = 30; minEnemiesOnScreen = 8; bossEnemyPct = 0.05f; superBossEnemyPct = 0.01f; megaBossEnemyPct = 0.10f; GameScene.slowTimeBank = 0; GameScene.killBonus = 0; GameScene.headShotBonus = 0.5f; GameScene.initialAmmo = 50; GameScene.initialTime = 60f; final int initialHP = 10; GameScene.missionTime = GameScene.initialTime; GameScene.initialHeadshots = GameScene.totalHeadshots; GameScene.bonusTime = 0; GameScene.slowTime = 0; GameScene.initialCash = GameScene.cash; GameScene.slowTimeBank = GameScene.SLOW_TIME_BANK_MAX; if (Rifle.roundsLeft < GameScene.initialAmmo) { Rifle.getSharedInstance().setRoundsLeft(GameScene.initialAmmo); } GameScene.setHP(initialHP); Rifle.getSharedInstance().resetValues(); HUDManager.registerClockUpdateHandler(); HUDManager.updateHUDAmmoCount(); } public static void resetTimer() { if (survivorModeTimer != null) { survivorModeTimer.cancel(); survivorModeTimer.purge(); } survivorModeTimer = new Timer(); } public static void increaseDifficulty () { instance.unregisterUpdateHandler(randomSpawnTimer); if (minSpawnTime > 2.0f) { minSpawnTime -= 0.1f; } if (maxSpawnTime > 4.0f) { maxSpawnTime -= 0.2f; } if (maxSpawnSize < 6) { maxSpawnSize += 1; } if (currentMaxMovementSpeed + 0.01f < absoluteMaxMovementSpeed) { currentMaxMovementSpeed += 0.01f; } if (currentMinMovementSpeed + 0.01f < currentMaxMovementSpeed) { currentMinMovementSpeed += 0.01f; } if (maxEnemiesOnScreen + 5 < absoluteMaxEnemiesOnScreen) { maxEnemiesOnScreen += 5;} if (minEnemiesOnScreen + 1 < absoluteMaxEnemiesOnScreen) { minEnemiesOnScreen += 2;} if (bossEnemyPct < 0.60f) { bossEnemyPct += 0.02f; } if (superBossEnemyPct < 0.10f) { superBossEnemyPct += 0.005f; } if (megaBossEnemyPct < 0.30f) { megaBossEnemyPct += 0.01f; } getSharedInstance().setRandomSpawnTimer(); getSharedInstance().scheduleIncreasedDifficultyTask(); } public void scheduleIncreasedDifficultyTask() { survivorModeTimer.schedule(new IncreaseDifficultyTask(), millisecondsToNextDifficulty); } class IncreaseDifficultyTask extends TimerTask { public void run() { increaseDifficulty(); } } public static SurvivorScene getSharedInstance() { if (instance == null) { instance = new SurvivorScene(); } return instance; } public void setRandomSpawnTimer() { setRandomTimer(minSpawnTime, maxSpawnTime); instance.registerUpdateHandler(randomSpawnTimer); } public void setRandomTimer(final float minWait, final float maxWait) { randomSpawnTimer = new RandomTimerHandler(minWait, maxWait, true, new IRandomTimerCallBack() { @Override public void onTimePassed(final RandomTimerHandler pRandomTimerHandler) { final int size = EnemyLayer.getSharedInstance().enemies.size(); int numEnemiesToSpawn = BaseActivity.r.nextInt(maxSpawnSize); if (size < maxEnemiesOnScreen) { if (size < minEnemiesOnScreen) { numEnemiesToSpawn = minEnemiesOnScreen - size; } EnemyLayer.getSharedInstance().addEnemies(numEnemiesToSpawn); } } } ); } }