Android Open Source - ssniper-andengine Survivor Scene






From Project

Back to project page ssniper-andengine.

License

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.

Java Source Code

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);
                    }
                }
            }
        );
    }
}




Java Source Code List

com.cladophora.ssniper.BaseActivity.java
com.cladophora.ssniper.DeviceUtil.java
com.cladophora.ssniper.EnemyPool.java
com.cladophora.ssniper.GameEffects.java
com.cladophora.ssniper.GameEvents.java
com.cladophora.ssniper.GameLoopUpdateHandler.java
com.cladophora.ssniper.GameUtil.java
com.cladophora.ssniper.HUDManager.java
com.cladophora.ssniper.HoverListener.java
com.cladophora.ssniper.ItemPool.java
com.cladophora.ssniper.LevelLoader.java
com.cladophora.ssniper.PlantPool.java
com.cladophora.ssniper.SPenHoverView.java
com.cladophora.ssniper.ScopeEngine.java
com.cladophora.ssniper.SoundManager.java
com.cladophora.ssniper.SpriteManager.java
com.cladophora.ssniper.andengine.IRandomTimerCallBack.java
com.cladophora.ssniper.andengine.RandomTimerHandler.java
com.cladophora.ssniper.entity.EnemyLayer.java
com.cladophora.ssniper.entity.Enemy.java
com.cladophora.ssniper.entity.ItemLayer.java
com.cladophora.ssniper.entity.Item.java
com.cladophora.ssniper.entity.PlantLayer.java
com.cladophora.ssniper.entity.Plant.java
com.cladophora.ssniper.entity.Reticle.java
com.cladophora.ssniper.entity.Rifle.java
com.cladophora.ssniper.entity.SPen.java
com.cladophora.ssniper.scene.GameScene.java
com.cladophora.ssniper.scene.InstructionScene.java
com.cladophora.ssniper.scene.IntroScene.java
com.cladophora.ssniper.scene.MainMenuScene.java
com.cladophora.ssniper.scene.PauseScene.java
com.cladophora.ssniper.scene.ResultScene.java
com.cladophora.ssniper.scene.ShopScene.java
com.cladophora.ssniper.scene.SplashScene.java
com.cladophora.ssniper.scene.SurvivorIntroScene.java
com.cladophora.ssniper.scene.SurvivorScene.java
com.cladophora.ssniper.scene.TutorialScene.java
com.cladophora.ssniper.scene.WeaponInfoScene.java