Created
March 28, 2014 20:04
-
-
Save jodem/9841845 to your computer and use it in GitHub Desktop.
Space corsair level sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fr.testudo.spacecorsair.game.levels.builders; | |
| import fr.testudo.spacecorsair.R; | |
| import fr.testudo.spacecorsair.business.Element; | |
| import fr.testudo.spacecorsair.business.ennemis.*; | |
| import fr.testudo.spacecorsair.business.factory.GamePools; | |
| import fr.testudo.spacecorsair.business.player.PlayerShip; | |
| import fr.testudo.spacecorsair.business.world.Portal; | |
| import fr.testudo.spacecorsair.display.Background; | |
| import fr.testudo.spacecorsair.engine.ObjectRegistry; | |
| import fr.testudo.spacecorsair.engine.Vector2; | |
| import fr.testudo.spacecorsair.game.levels.Level; | |
| import fr.testudo.spacecorsair.game.levels.LevelAnimator; | |
| import fr.testudo.spacecorsair.game.levels.LevelId; | |
| import fr.testudo.spacecorsair.game.levels.LevelNames; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class TheHiveLevelBuilder { | |
| public static final int LEVEL_MIN = 14; | |
| public static final int LEVEL_MAX = 16; | |
| public static final Vector2 GATE_TO_DELTA_NODE_POS = new Vector2(10000, 3000); | |
| public static final Vector2 GATE_TO_LEFT_POS = new Vector2(-40000, -4000); | |
| static Portal DELTA_NODE_PORTAL; | |
| static Portal LEFT_PORTAL; | |
| public static Level getTheHive() { | |
| List<Element> levelObjects = new ArrayList<Element>(); | |
| addPortals(levelObjects); | |
| addEnemies(levelObjects); | |
| addAsteroids(levelObjects); | |
| //todo: ajouter un trésor ou pas ? | |
| //addTreasure(levelObjects); | |
| levelObjects.add(PlayerShip.instance()); | |
| Level theHive = new Level(LevelId.THE_HIVE, levelObjects, theHiveLevelAnimator); | |
| theHive.musicResourceId = R.raw.loop_electro1; | |
| theHive.backGroundImage = Background.BackImage.Nebuleuse; | |
| return theHive; | |
| } | |
| private static void addAsteroids(List<Element> levelObjects) { | |
| // packs | |
| LevelBuilderHelper.addAsteroidPacks(levelObjects, 50, -15000, -500, 30000, 9000, 7, 25, 800); | |
| } | |
| private static final LevelAnimator theHiveLevelAnimator = new LevelAnimator() { | |
| @Override | |
| public void onEveryTenSec() { | |
| if (Math.random() < 0.2f) { | |
| //un risque sur 5 de se prendre une hive dans la tronche | |
| if (!ObjectRegistry.INSTANCE.game.currentLevel.isThereMoreAttackingPlayerEnemiesThan(0)) { | |
| ObjectRegistry.INSTANCE.game.currentLevel.getRandomPlayerLocationCirclePoint(temp, 3800, 0); | |
| int blatteLevel = getBlatteLevel(); | |
| Ennemis newBlatte = EnnemisFactory.newAlienBlatte(blatteLevel - 1, blatteLevel).initPosition(temp); | |
| if (Math.random() < 0.1) { | |
| newBlatte.setElite(); | |
| } | |
| newBlatte.initChasePlayer(); | |
| ObjectRegistry.INSTANCE.queueElementToBeAddToLevel(newBlatte); | |
| ObjectRegistry.INSTANCE.game.currentLevel.requestPlayerGotoLastPosOfElements(); | |
| } | |
| } | |
| } | |
| }; | |
| private static int getBlatteLevel() { | |
| int blatteLevel = 13; | |
| if (ObjectRegistry.INSTANCE.game.playerInfo.level > 15) { | |
| blatteLevel = ObjectRegistry.INSTANCE.game.playerInfo.level - 1; | |
| } | |
| return blatteLevel; | |
| } | |
| static Vector2 temp = new Vector2(); | |
| public static void addEnemies(List<Element> levelObjects) { | |
| int blatteLevel = getBlatteLevel(); | |
| //2 qui se baladent | |
| for (int i = 0; i < 2; i++) { | |
| temp.set((float) (-33000 + Math.random() * 40000), (float) (-9000 + Math.random() * 18000)); | |
| Ennemis newBlatte = EnnemisFactory.newAlienBlatte(blatteLevel - 1, blatteLevel).initPosition(temp); | |
| if (Math.random() < 0.1) { | |
| newBlatte.setElite(); | |
| } | |
| newBlatte.setActivitySequence(generateAlienBlatteSequence(temp)); | |
| levelObjects.add(newBlatte); | |
| } | |
| } | |
| public static EnnemisActivitySequence generateAlienBlatteSequence(Vector2 initialPos) { | |
| return new EnnemisActivitySequence() | |
| .addActivity(new EnnemisActivity().initGotoRandom(initialPos.x, -12000, 4000)) | |
| .addActivity(new EnnemisActivity().initGotoRandom(initialPos.x, 12000, 4000)); | |
| } | |
| public static void addPortals(List<Element> levelObjects) { | |
| Portal deltaNodePortal = GamePools.newPortal().init(LevelNames.GATE_TO_DELTA_NODE); | |
| deltaNodePortal.jumpLevelName = LevelNames.DELTA_NODE; | |
| deltaNodePortal.jumpPortalName = LevelNames.GATE_TO_THE_HIVE; | |
| deltaNodePortal.position.setSameAs(GATE_TO_DELTA_NODE_POS); | |
| deltaNodePortal.initialPlayerSpeed.set(-Portal.EJECTION_SPEED, 0f); | |
| deltaNodePortal.initialPlayerSpin = 0f; | |
| DELTA_NODE_PORTAL = deltaNodePortal; | |
| levelObjects.add(deltaNodePortal); | |
| Portal leftPortal = GamePools.newPortal().init(LevelNames.COMING_SOON_PORTAL); | |
| leftPortal.jumpLevelName = LevelNames.THE_HIVE; | |
| leftPortal.jumpPortalName = LevelNames.COMING_SOON_PORTAL; | |
| leftPortal.position.setSameAs(GATE_TO_LEFT_POS); | |
| leftPortal.canBeUsed = false; | |
| leftPortal.initialPlayerSpeed.set(0f, Portal.EJECTION_SPEED); | |
| leftPortal.initialPlayerSpin = 0f; | |
| LEFT_PORTAL = leftPortal; | |
| levelObjects.add(leftPortal); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment