private void updateSelectionStats() { if (selected is Sentry) { Sentry s = (Sentry)selected; selectionStats = new string[] { "TYPE: " + Sentry.read(s.getType()), "SPEED: " + s.getSpeed(), "DIRECTION: " + s.interpretDirection(), "SECONDARY TYPE: " + Sentry.read(s.getSecondary()) }; } else if (selected is Platform) { Platform p = (Platform)selected; selectionStats = new string[] { "WIDTH: " + p.getWidth() }; } }
private void hovering() { Point l = mover.getLocation(); bool found = false; HasLocation hovered = null; // Player check if (Math.Abs(l.X - players.ElementAt(0).getLocation().X) <= 10 && Math.Abs(l.Y - players.ElementAt(0).getLocation().Y) <= 10) { found = true; hovered = players.ElementAt(0); } // Platform check for (int i = 0; i < platforms.Count && !found; i++) { Point p = platforms.ElementAt(i).getLocation(); int w = platforms.ElementAt(i).getWidth() / 2; if (Math.Abs(l.X - p.X) < w && Math.Abs(l.Y - p.Y) <= 10) { hovered = platforms.ElementAt(i); found = true; break; } } if (!found) { foreach (Sentry s in sentries) { if (Math.Abs(l.X - s.getLocation().X) <= 10 && Math.Abs(l.Y - s.getLocation().Y) <= 10) { hovered = s; found = true; break; } } } if (found) { if (hovered is Player) { crossHairColor = Color.FromArgb(255, 0, 0); updateSelectionContext( "<Player spawn is linked to starting platform>", new string[0]); } else { crossHairColor = Color.FromArgb(0, 255, 0); selectable = hovered; if (hovered is Sentry) { Sentry s = (Sentry)hovered; updateSelectionContext( "<" + controls[6] + "> to select - SENTRY " + (sentries.IndexOf(s) + 1), new string[] { "TYPE: " + Sentry.read(s.getType()), "SPEED: " + s.getSpeed(), "DIRECTION: " + s.interpretDirection(), "SECONDARY TYPE: " + Sentry.read(s.getSecondary()) }); } if (hovered is Platform) { Platform p = (Platform)hovered; int pIndex = platforms.IndexOf(p); switch (pIndex) { case 0: updateSelectionContext( "<" + controls[6] + "> to select - STARTING PLATFORM", new string[] { "WIDTH: " + p.getWidth() }); break; default: updateSelectionContext( "<" + controls[6] + "> to select - PLATFORM " + (pIndex + 1), new string[] { "WIDTH: " + p.getWidth() }); break; } } } } else { selectable = null; updateSelectionContext(" ", new string[0]); crossHairColor = Color.FromArgb(155, 155, 155); } }
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); }