Beispiel #1
0
        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)
            //    {
            //
            //    }
            // }
        }
Beispiel #2
0
        public void Die()
        {
            lock (lock_die) {
                if (Died)
                {
                    return;
                }
                this.act = Activities.DEAD;
            }

            OnUpdate -= e_update;
            if (AnimationsEnabled)
            {
                window.DrawHead -= draw_event;
            }

            if (Tick < 60 + Map.StartRoundTime)
            {
                MVP.Add(MVPTypes.EARLY_KILL, DisplayKey);
            }

            lock (ActiveLock) {
                ActiveKeys.Remove(this.KeyCode);
                if (KingOfTheHill)
                {
                    InactiveKeys.Add(this.KeyCode);
                }
                else
                {
                    InactiveKeys.Insert(0, this.KeyCode);
                }
            }
            key.Die();
            tail.Die();
            z            = 0;
            DashHideText = false;

            if (isBounty)
            {
                new Animation(pos, 30, HeadR - 1, HeadR - 5, 5, 0, Color.Red, Color.Red, AnimationTypes.CUBED);
            }

            isBounty       = false;
            isDoubleBounty = false;

            if (AnimationsEnabled && ActiveKeys.Count <= 12 && !(Map is BotArena))
            {
                _ = new Animation(pos, 80, 0, W, HeadR, (float)PHI * HeadR, Color.FromArgb(150, this.color), 0);
            }
            if (AnimationsEnabled)
            {
                _ = new Animation(pos, 12, 0, 0, HeadR, HeadR, this.color, 32, AnimationTypes.CUBED);
            }
            else
            {
                window.writeln(DisplayKey + " died: " + Points + " pts");
            }



            if (KingOfTheHill)
            {
                IKey.UpdateAll();
                new Thread(() => {
                    int tick = Tick;
                    SpinWait.SpinUntil(() => Tick >= tick + 120 || Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning);
                    if (Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning)
                    {
                        return;
                    }
                    new Coin(IPoint.Center + 3 * IVector.Random(), "3", this.color);

                    SpinWait.SpinUntil(() => Tick >= tick + 180 || Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning);
                    if (Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning)
                    {
                        return;
                    }
                    new Coin(IPoint.Center + 3 * IVector.Random(), "2", this.color);

                    SpinWait.SpinUntil(() => Tick >= tick + 240 || Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning);
                    if (Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning)
                    {
                        return;
                    }
                    new Coin(IPoint.Center + 3 * IVector.Random(), "1", this.color);

                    SpinWait.SpinUntil(() => Tick >= tick + 300 || Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning);
                    if (Map.phase != Phases.NONE || state == States.NEWGAME || !ApplicationRunning)
                    {
                        return;
                    }
                    lock (updatinglocker) {
                        this.clear();
                        this.Revive();
                        this.act = Activities.DEFAULT;
                        lock (ActiveLock) {
                            ActiveKeys.Add(KeyCode);
                            InactiveKeys.Remove(KeyCode);
                        }
                        this.INVINCIBLE = true;
                    }
                    SpinWait.SpinUntil(() => (Tick >= tick + 360 && !is_about_to_die()) || !ApplicationRunning);
                    this.INVINCIBLE = false;

                    SpinWait.SpinUntil(() => (Tick >= tick + 372 || Died) || !ApplicationRunning);
                    if (Tick <= tick + 372 && Died)
                    {
                        MVP.Flash("Spawnkill!");
                    }
                }).Start();
            }
            else
            {
                Map.Sort();
                IKey.UpdateAll();
                if (ActiveKeys.Count == 1 && Map.phase != Phases.ENDROUND)
                {
                    new Thread(Map.EndRound).Start();
                }
            }

            if (OnDie != null)
            {
                Parallel.Invoke(OnDie);
            }
        }