public void DrawPaint(object sender, PaintEventArgs e) { if (!drawing) { return; } Graphics g = e.Graphics; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.Low; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.ScaleTransform(scalar, scalar); try { Map?.Draw(g); DrawWhite?.Invoke(g); Blast.DrawAll(g); DrawTail?.Invoke(g); DrawBullet?.Invoke(g); DrawHead?.Invoke(g); DrawKeys?.Invoke(g); DrawAnimation?.Invoke(g); if (ActiveKeys.Contains(Leader)) { Map.DrawCrown(g); } MVP.Draw(g); } catch (Exception) { } }
private void window_keyup(object sender, KeyEventArgs e) { keydown.Remove(e.KeyCode); if (e.KeyCode == Keys.F7) { SlowMo = false; return; } else if (e.KeyCode == Keys.F8) { SpeedMo = false; return; } if (Ingame && ActiveKeys.Contains(e.KeyCode)) { HEADS[e.KeyCode].key.Release(); } }
private void window_keydown(object sender, KeyEventArgs e) { if (keydown.Contains(e.KeyCode) || e.KeyCode == Keys.NumLock || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.Menu) { return; } else { keydown.Add(e.KeyCode); } Keys ekey = e.KeyCode; if (e.KeyCode == Keys.Delete) { ekey = Keys.Decimal; } else if (e.KeyCode == Keys.Insert) { ekey = Keys.NumPad0; } else if (e.KeyCode == Keys.Clear) { ekey = Keys.NumPad5; } else if (e.KeyCode == Keys.F2) { ContrastMode = !ContrastMode; return; } else if (e.KeyCode == Keys.F3) { if (state == States.NEWGAME && Neat.All.Count < 24) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Bot files (*.bot)|*.bot|All files (*.*)|*.*"; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName)); Neat.remove(bytes, 8); Neat n = Neat.decompile(bytes); n.SetupGenZero(); n.AddKey(); IKey.UpdateAll(); Map.SetMaxPoints(); // Set color Program.HEADS[n.Key].color = n.color.GetValueOrDefault(Entities.Head.GenerateColor()); } } return; } else if (e.KeyCode == Keys.F1) { if (state != States.NEWGAME) { return; } if (ActiveKeys.Count > 0) { new AI(ActiveKeys[ActiveKeys.Count - 1]); MVP.Flash($"AI added to {HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey}"); HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey = "AI"; } return; } else if (e.KeyCode == Keys.F4 && !e.Alt) { if (state == States.NEWGAME) { if (Neat.All.Count > 0) { Neat toRemove = Neat.All.Last(); toRemove.Remove(); IKey.UpdateAll(); } Map.SetMaxPoints(); } return; } else if (e.KeyCode == Keys.F9 && e.Alt) { if (ActiveKeys.Count == 0 || InactiveKeys.Count == 0) { return; } HEADS[InactiveKeys[0]].Reward(0, ActiveKeys[0]); HEADS[ActiveKeys[0]].Die(); return; } else if (e.KeyCode == Keys.F10) { if (SyncUpdate) { SyncUpdate = false; UpdateThread.Stop(); NeuralThread.Stop(); StartAsyncUpdate(); } else { SyncUpdate = true; UpdateThread.Start(); NeuralThread.Start(); } return; } else if (e.KeyCode == Keys.F7) { SlowMo = true; return; } else if (e.KeyCode == Keys.F8) { SpeedMo = true; return; } else if (e.KeyCode == Keys.F11) { FullScreen = !FullScreen; if (FullScreen) { Width = Screen.PrimaryScreen.Bounds.Width; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; Cursor.Hide(); } else { Width = 1024; Height = 600; FormBorderStyle = FormBorderStyle.Sizable; WindowState = FormWindowState.Normal; Cursor.Show(); } return; } else if (e.KeyCode == Keys.F12) { if (!e.Alt) { if (map is BotArena) { List <byte> bytes = new List <byte>(); bytes.AddRange(((BotArena)map).GetGeneration()); foreach (Neat bot in ((BotArena)map).bots) { bytes.AddRange(Neat.compile(bot)); } SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Bot files (*.bot)|*.bot|All files (*.*)|*.*"; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(dialog.FileName, bytes.ToArray()); } } else if (ActiveKeys.Count == 0) { Cursor.Show(); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Bot files (*.bot)|*.bot|All files (*.*)|*.*"; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName)); BotArena arena = new BotArena(BotArena.Type.MAX_POINTS); arena.SetGeneration(bytes); map = arena; while (bytes.Count > 0) { arena.bots.Add(Neat.decompile(bytes)); } arena.AddBots(false); Map.StartGame(); Ingame = true; state = States.INGAME; } if (FullScreen) { Cursor.Hide(); } } } else if (state == States.NEWGAME && !TutorialActive) { if (ActiveKeys.Count != 1) { return; } TUTO = new Tutorial(Map); TutorialActive = true; Map.StartGame(); if (SyncUpdate) { NeuralThread.Start(); } } return; // trigger tutorial } else if (e.KeyCode == Keys.F6) { if (ActiveKeys.Count != 0) { return; } BotArena arena = new BotArena(7, BotArena.Type.MAX_POINTS); /// < - - - - - - - - - - - - - - - - map = arena; arena.AddBots(false); Map.StartGame(); Ingame = true; state = States.INGAME; return; // trigger bot arena } else if (e.KeyCode == Keys.F5) { if (state != States.NEWGAME) { return; } switch (Gamemode) { case Gamemodes.CLASSIC: MVP.SetText("Red chaos"); Gamemode = Gamemodes.CHAOS_RED; foreach (Head head in HEADS.Values) { head.NewColor(true); } break; case Gamemodes.CHAOS_RED: MVP.SetText("Rainbow chaos"); Gamemode = Gamemodes.CHAOS_RAINBOW; foreach (Head head in HEADS.Values) { head.NewColor(); } break; case Gamemodes.CHAOS_RAINBOW: MVP.SetText("King of the hill"); foreach (Head head in HEADS.Values) { head.NewColor(false); } Map.MaxOrbs = 7; Gamemode = Gamemodes.KING_OF_THE_HILL; break; case Gamemodes.KING_OF_THE_HILL: MVP.SetText("Hidden"); Map.MaxOrbs = 8; Gamemode = Gamemodes.HIDDEN; break; case Gamemodes.HIDDEN: MVP.SetText("Yeet Mode"); Gamemode = Gamemodes.YEET_MODE; Map.blastSpawn = BlastSpawn.RARE; break; case Gamemodes.YEET_MODE: MVP.SetText("Classic"); Map.MaxOrbs = 255; Gamemode = Gamemodes.CLASSIC; break; } UpdateColors?.Invoke(); return; } switch (state) { case States.NEWGAME: //add new player if (e.KeyCode == Keys.Enter && ActiveKeys.Count > 0) // (re)start game { if (e.Shift) { Map.ResumeGame(); } else { Map.StartGame(); } if (SyncUpdate) { NeuralThread.Start(); } Ingame = true; state = States.INGAME; } else if (e.KeyCode == Keys.Escape) // clear all keys { HashSet <Neat> NeatCopy = new HashSet <Neat>(Neat.All); foreach (Neat neat in NeatCopy) { neat.Remove(); } HashSet <Head> HeadCopy = new HashSet <Head>(HEADS.Values); foreach (Head head in HeadCopy) { head.Remove(); } Map.MaxPoints = 0; Leader = Keys.None; } else if (0 <= e.KeyValue && e.KeyValue < 256) //add key { lock (ActiveLock) { if (ActiveKeys.Contains(ekey)) { HEADS[ekey].Remove(); } else { if (HEADSOnPause.ContainsKey(ekey)) { HEADS.Add(ekey, new Head(HEADSOnPause[ekey])); } else { HEADS.Add(ekey, new Head(ekey)); } ActiveKeys.Add(ekey); Map.SetMaxPoints(); } } IKey.UpdateAll(); } break; case States.INGAME: if (e.KeyCode == Keys.Escape) //pause game { ApplicationPause(); } else if (ActiveKeys.Contains(ekey)) //default action { HEADS[ekey].Action(); } break; case States.PAUSED: if (e.KeyCode == Keys.Escape) // unpause { state = States.INGAME; Ingame = true; if (SyncUpdate) { UpdateThread.Start(); NeuralThread.Start(); } else { StartAsyncUpdate(); } VisualThread.Start(); //ForcePaused = false; } else if (e.KeyCode == Keys.Enter) // let players join { HEADSOnPause.Clear(); foreach (KeyValuePair <Keys, Head> player in HEADS) { HEADSOnPause.Add(player.Key, player.Value); } Map.EndGame(); Map.Clear(); Map.phase = Phases.NONE; state = States.NEWGAME; MVP.Show("Prepare!"); lock (ActiveLock) foreach (Keys key in ActiveKeys) { HEADS[key].v = IVector.Up; } Ingame = false; VisualThread.Start(); if (SyncUpdate) { UpdateThread.Start(); } else { StartAsyncUpdate(); } } break; } }
private static void CheckKeyState(KeyboardState previousState, KeyboardState currentState) { for (int i = 0; i < currentState.GetPressedKeys().Length; i++) { KeyToCheck = currentState.GetPressedKeys()[i]; if (previousState.IsKeyUp(KeyToCheck) && currentState.IsKeyDown(KeyToCheck)) { // pressedKeys.Add(KeyToCheck); // pressedKeysStates.Add(KeyState.Clicked); ActiveKeys.Add(new KeyboardButtonState(KeyToCheck)); } else if (previousState.IsKeyDown(KeyToCheck) && currentState.IsKeyDown(KeyToCheck)) { // pressedKeysStates[pressedKeys.IndexOf(KeyToCheck)] = KeyState.Held; foreach (KeyboardButtonState key in ActiveKeys) { if (key.Button == KeyToCheck) { key.ButtonState = KeyboardButtonState.KeyState.Held; } } } } for (int i = 0; i < previousState.GetPressedKeys().Length; i++) { KeyToCheck = previousState.GetPressedKeys()[i]; if (previousState.IsKeyDown(KeyToCheck) && currentState.IsKeyUp(KeyToCheck)) { // pressedKeysStates[pressedKeys.IndexOf(KeyToCheck)] = KeyState.Released; foreach (KeyboardButtonState key in ActiveKeys) { if (key.Button == KeyToCheck) { key.ButtonState = KeyboardButtonState.KeyState.Released; } } } } for (int i = 0; i < ActiveKeys.Count; i++) { if (previousState.IsKeyUp(ActiveKeys[i].Button) && currentState.IsKeyUp(ActiveKeys[i].Button)) { ActiveKeys[i].Button = Keys.None; ActiveKeys[i].ButtonState = KeyboardButtonState.KeyState.None; } } // while (ActiveKeys.Contains(Keys.None)) // { // pressedKeysStates.RemoveAt(pressedKeys.IndexOf(Keys.None)); // pressedKeys.RemoveAt(pressedKeys.IndexOf(Keys.None)); // } while (ActiveKeys.Contains(new KeyboardButtonState(Keys.None))) { ActiveKeys.Remove(new KeyboardButtonState(Keys.None)); } // for (int i = 0; i < ActiveKeys.Count; i++) // { // if (ActiveKeys[i].Button == Keys.None) // { // // } // } }