public Level(main main) { // should only be called by EditorLevel players = new List <Player>() { new Player(main.getSettings().getControlMode()) }; platforms = new List <Platform>() { new Platform(new Point(1000, 1000), 200), new Platform(new Point(1000, 800), 200) }; foreach (Player p in players) { p.setLevel(this); } Sentry s = new Sentry(Sentry.Type.PUSH, 6); s.setPlatform(platforms.ElementAt(1)); s.setLevel(this); sentries = new List <Sentry>() { s }; this.animations = new List <Animation>(); this.background = Render.initialBackground(); this.camera = new Camera(Camera.FollowMode.STEADY); this.main = main; }
public new void keyHandler(KeyEventArgs e, bool down) { // Key status if (e.KeyCode == controls[4]) { is4Down = down; } else if (e.KeyCode == controls[5]) { is5Down = down; } else if (e.KeyCode == Keys.Up) { arrowDown[UP] = down; } else if (e.KeyCode == Keys.Down) { arrowDown[DOWN] = down; } else if (e.KeyCode == Keys.Left) { arrowDown[LEFT] = down; } else if (e.KeyCode == Keys.Right) { arrowDown[RIGHT] = down; } // TODO if (!down) { // Test if (e.KeyCode == Keys.T) { main.playEditorLevel(); } else if (e.KeyCode == Keys.R) { main.resetEditor(); } else if (e.KeyCode == Keys.F) { main.setMode(Mode.MENU); main.setMenuFrame("editor-level-finish"); } switch (selectionMode) { case SelectionMode.CAN_ADD: if (e.KeyCode == controls[4]) { platforms.Add(new Platform( mover.getLocation(), 200)); } break; case SelectionMode.REG_PLATFORM: Platform p = (Platform)selected; if (e.KeyCode == Keys.Back) { // Delete platform platforms.Remove(p); for (int i = 0; i < sentries.Count; i++) { Sentry sentry = sentries.ElementAt(i); if (sentry.getPlatform() == p) { sentries.Remove(sentry); i--; } } selected = null; selectionMode = SelectionMode.NONE; } else if (e.KeyCode == Keys.X) { // Add sentry Sentry sentry = new Sentry(Sentry.Type.RANDOM, 6, Sentry.Type.RANDOM); sentries.Add(sentry); sentry.setPlatform(p); } break; case SelectionMode.SENTRY: Sentry s = (Sentry)selected; if (e.KeyCode == controls[4]) { // Next type - cycles through the enum s.nextType(); } else if (e.KeyCode == controls[5]) { // Next secondary s.nextSecondary(); } else if (e.KeyCode == Keys.Left) { s.setDirection(-1); } else if (e.KeyCode == Keys.Right) { s.setDirection(1); } else if (e.KeyCode == Keys.Up && s.getSpeed() < 14) { s.changeSpeed(2); } else if (e.KeyCode == Keys.Down && s.getSpeed() > 2) { s.changeSpeed(-2); } else if (e.KeyCode == Keys.Back) { sentries.Remove(s); selected = null; selectionMode = SelectionMode.NONE; } break; } } if (down) { if (e.KeyCode == controls[6]) { if (selectable != null) { selected = selectable; selectable = null; if (selected is Sentry) { selectionMode = SelectionMode.SENTRY; selectionContext = "SENTRY " + (sentries.IndexOf((Sentry)selected) + 1); } else if (selected is Platform) { Platform p = (Platform)selected; if (platforms.IndexOf(p) == 0) { selectionMode = SelectionMode.STARTING_PLATFORM; selectionContext = "STARTING PLATFORM"; } else { selectionMode = SelectionMode.REG_PLATFORM; selectionContext = "PLATFORM " + (platforms.IndexOf(p) + 1); } } } else if (selected != null) { selected = null; selectionMode = SelectionMode.NONE; } } } if (selected != null) { updateSelectionStats(); } mover.keyHandler(e, down); }
public void behave() { Player sees = null; List <Platform> platforms = level.getPlatforms(); if (sightDependent()) { // SIGHT-DEPENDENT sees = seesPlayer(); if (sees != null) { switch (type) { case Type.PUSH: sees.moveX(speed * direction); break; case Type.SHOVE: sees.moveX(4 * speed * direction); break; case Type.PULL: sees.moveX(-speed * direction); break; case Type.DROP: sees.moveY(21); break; case Type.GRAV_FLIP: sees.mulGAcceleration(-1); break; case Type.GRAV_DOUBLE: sees.mulGAcceleration(2); break; case Type.MOVE: platform.moveX(-(speed * direction)); break; case Type.DECAY: if (platform.getWidth() > 20) { platform.changeWidth(-speed); platform.moveX(direction * (-speed / 2)); } break; case Type.SPREAD: if (platform.getWidth() < 500) { platform.changeWidth(speed); } break; case Type.EXPAND: foreach (Platform p in level.getPlatforms()) { if (p != platform) { p.moveX(speed * Math.Sign( p.getLocation().X - platform.getLocation().X)); p.moveY((speed / 2) * Math.Sign( p.getLocation().Y - platform.getLocation().Y)); } } foreach (Sentry s in level.getSentries()) { if (s != this) { s.fix(); } } break; case Type.FLEE: int i = 0; while (i == 0 || platforms.ElementAt(i) == platform) { Random rnd = new Random(Guid.NewGuid().GetHashCode()); i = rnd.Next(1, platforms.Count); } setPlatform(platforms.ElementAt(i)); break; case Type.GOD: int seesY = sees.getLocation().Y; List <Player> players = level.getPlayers(); List <Sentry> sentries = level.getSentries(); List <Animation> animations = level.getAnimations(); foreach (Player p in players) { p.setY(-1 * p.getLocation().Y); p.setSY(-1 * p.getSaveLocation().Y); p.mulGAcceleration(-1); } foreach (Platform p in platforms) { p.setY(-1 * p.getLocation().Y); } foreach (Sentry s in sentries) { s.location.Y *= -1; s.location.Y -= 40; } foreach (Animation a in animations) { a.setY(-1 * a.getLocation().Y); } int o = seesY - sees.getLocation().Y; foreach (Player p in players) { p.moveY(o); p.moveSY(o); } foreach (Platform p in platforms) { p.moveY(o); } foreach (Sentry s in sentries) { s.location.Y += o; } foreach (Animation a in animations) { a.moveY(o); } break; default: // TODO break; } } } else { // TODO: NON- SIGHT-DEPENDENT List <Player> players = level.getPlayers(); switch (type) { case Type.GRAV_INC: foreach (Player player in players) { player.changeGAcceleration(-3); } break; case Type.GRAV_RED: foreach (Player player in players) { player.changeGAcceleration(3); } break; case Type.HORZ_MAGNET: foreach (Player player in players) { player.moveX(speed * Math.Sign(location.X - player.getLocation().X)); } break; case Type.SPAWN: count++; count %= 100; // UPDATE CHILDREN for (int i = 0; i < children.Count; i++) { if (!children.ElementAt(i).isAlive()) { children.RemoveAt(i); i--; } } // SPAWN LOGIC if (count == 0 && children.Count < 5) { Random sp = new Random(Guid.NewGuid().GetHashCode()); int childSpeed = sp.Next(1, 8) * 2; Sentry child = new Sentry(secondary, childSpeed); children.Add(child); level.addSentry(child); int i = 0; while (i == 0 || platforms.ElementAt(i) == platform) { Random rnd = new Random(Guid.NewGuid().GetHashCode()); i = rnd.Next(1, platforms.Count); } child.setPlatform(platforms.ElementAt(i)); } break; case Type.NECROMANCER: count++; count %= 100; // REANIMATION LOGIC if (count == 0) { for (int i = 0; i < level.getSentries().Count; i++) { Sentry s = level.getSentries().ElementAt(i); if (!s.alive && s != this) { s.alive = true; children.Add(s); break; } } } break; case Type.RANDOM: // RESOLVE to another type while (type == Type.RANDOM) { Random random = new Random(Guid.NewGuid().GetHashCode()); type = (Type)random.Next(0, NUM_TYPES); } if (type == Type.SPAWN || type == Type.NECROMANCER) { children = new List <Sentry>(); count = 0; secondary = Type.RANDOM; } break; default: // TODO break; } } }