private void Start()
 {
     RightKey.DeActivateKey();
     UpKey.DeActivateKey();
     DownKey.DeActivateKey();
     LeftKey.DeActivateKey();
     RKey.DeActivateKey();
     GameManager.AddInfection(this);
 }
 private void EndGame()
 {
     gameCodes.Clear();
     gameStarted = false;
     RightKey.DeActivateKey();
     UpKey.DeActivateKey();
     DownKey.DeActivateKey();
     LeftKey.DeActivateKey();
     RKey.DeActivateKey();
 }
    public void OnTriggerExit2D(Collider2D collision)
    {
        Player p = collision.gameObject.GetComponent <Player>();

        if (p == null)
        {
            return;
        }
        entered = false;
        Debug.Log("Exited range of infection :(");
        Player.EnableCure(false);
        Player.UnSubscribePlayerKeyPressEvent(OnPlayerKeyPress);
        RightKey.DeActivateKey();
        UpKey.DeActivateKey();
        DownKey.DeActivateKey();
        LeftKey.DeActivateKey();
        RKey.DeActivateKey();
        if (gameStarted)
        {
            gameStarted = false;
        }
    }
Beispiel #4
0
        private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (is_Start)
            {
                System.Windows.Controls.Button temp = Keys.FindName(e.Key.ToString()) as System.Windows.Controls.Button;
                if (temp != null)
                {
                    if (e.Key.ToString() == "System")
                    {
                        temp = Keys.FindName("Alt") as System.Windows.Controls.Button;
                    }

                    if (temp.Content.ToString().Length == 1 || temp.Content.ToString() == "Space")
                    {
                        if (temp.Content.ToString() != "Space")
                        {
                            my_chars = temp.Content.ToString();
                        }
                        else
                        {
                            my_chars = " ";
                        }



                        FormattedText formattedText = new FormattedText(my_chars, CultureInfo.CurrentCulture,
                                                                        System.Windows.FlowDirection.LeftToRight,
                                                                        new Typeface(this._Scroll_Prow_Str.FontFamily, this._Scroll_Prow_Str.FontStyle, this._Scroll_Prow_Str.FontWeight,
                                                                                     this._Scroll_Prow_Str.FontStretch), this._Scroll_Prow_Str.FontSize, System.Windows.Media.Brushes.Black, new NumberSubstitution(), TextFormattingMode.Display);


                        len = new Size(formattedText.Width, formattedText.Height);

                        DownKey?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        my_chars = "";
                        is_Fail  = false;
                    }



                    if (is_Fail == false)
                    {
                        for (int i = 0; i < startBrush.Count; i++)
                        {
                            if (startBrush[i].temp.Content == temp.Content)
                            {
                                return;
                            }
                        }
                        mycolor tempM = new mycolor();
                        Spehil_Key(e);
                        tempM.temp       = temp;
                        tempM.startBrush = temp.Background;
                        startBrush.Add(tempM);

                        temp.Background = System.Windows.Media.Brushes.IndianRed;
                    }
                    else
                    {
                        fails += 1;
                        System.Windows.MessageBox.Show(string.Format("The character you entered({0}) is incorrect.", my_chars));
                    }
                }
            }
        }
    private IEnumerator MiniGameEnumeration()
    {
        currentCheck = KeyCode.None;
        float currentCooldown = GameProperties.GetCheckTime();

        while (gameStarted)
        {
            //get new check
            if (currentCheck == KeyCode.None)
            {
                currentCheck = gameCodes.Dequeue();
            }

            switch (currentCheck)
            {
            case KeyCode.UpArrow:
                RightKey.DeActivateKey();
                UpKey.ActivateKey();
                DownKey.DeActivateKey();
                LeftKey.DeActivateKey();
                RKey.DeActivateKey();
                break;

            case KeyCode.RightArrow:
                RightKey.ActivateKey();
                UpKey.DeActivateKey();
                DownKey.DeActivateKey();
                LeftKey.DeActivateKey();
                RKey.DeActivateKey();
                break;

            case KeyCode.DownArrow:
                RightKey.DeActivateKey();
                UpKey.DeActivateKey();
                DownKey.ActivateKey();
                LeftKey.DeActivateKey();
                RKey.DeActivateKey();
                break;

            case KeyCode.LeftArrow:
                RightKey.DeActivateKey();
                UpKey.DeActivateKey();
                DownKey.DeActivateKey();
                LeftKey.ActivateKey();
                RKey.DeActivateKey();
                break;
            }

            //start timer
            currentCooldown = GameProperties.GetCheckTime();

            while (currentFramePressed != currentCheck)
            {
                yield return(new WaitForEndOfFrame());

                currentCooldown -= Time.fixedDeltaTime;
                if (currentCooldown < 0)
                {
                    Debug.Log("FAIL");
                    EndGame();
                    yield break;
                }
            }

            currentCheck = KeyCode.None;
            //check if any left
            if (gameCodes.Count == 0)
            {
                Debug.Log("WIN");
                GameManager.RemoveInfection(this);
                transform.parent.GetComponent <SpriteRenderer>().enabled = false;
                Destroy(gameObject);
                yield break;
            }
        }
    }
Beispiel #6
0
 public bool ButtonPressed()
 {
     return(UpKey.Down() || DownKey.Down() || LeftKey.Down() || RightKey.Down());
 }
Beispiel #7
0
        public override void Update(GameTime gt)
        {
            if (AutoSwitchInputs) //Switch the inputs
            {
                if (Input != MovementInput.Analog && AnalogStickMoved())
                {
                    Input = MovementInput.Analog;
                    EntityGame.Log.Write("Input switched to Analog", this, Alert.Info);
                }
                else if (Input != MovementInput.Buttons && ButtonPressed())
                {
                    Input = MovementInput.Buttons;
                    EntityGame.Log.Write("Input switched to Buttons", this, Alert.Info);
                }
            }



            switch (Input)
            {
            case MovementInput.Analog:
                if (!HasFocus && (AnalogStickMoved() || SelectKey.Down()))
                {
                    GetFocus(this);
                }
                if (HasFocus)
                {
                    //TODO: Use normalized positition for this.
                    Position = new Vector2(Position.X + AnalogStick.Position.X * MovementSpeed.X,
                                           Position.Y - AnalogStick.Position.Y * MovementSpeed.Y);

                    //Move it with the camera.
                    //Position += EntityGame.Camera.Delta;

                    //Keep it from leaving the bounds of the window.
                    if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                    }
                    else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;
                    }

                    if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                    }
                    else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                }
                break;

            case MovementInput.Buttons:
                if (!HasFocus && ButtonPressed() || SelectKey.Down())
                {
                    GetFocus(this);
                }
                if (HasFocus)
                {
                    Position = new Vector2(
                        Position.X + ((LeftKey.Down()) ? -MovementSpeed.X : 0) + ((RightKey.Down()) ? MovementSpeed.X : 0),
                        Position.Y + ((UpKey.Down()) ? -MovementSpeed.Y : 0) + ((DownKey.Down()) ? MovementSpeed.Y : 0)
                        );

                    //Move it with the camera.
                    Position += EntityGame.ActiveCamera.Delta;

                    //Keep it from leaving the bounds of the window.
                    if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                    }
                    else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;
                    }

                    if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                    }
                    else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                }
                break;
            }
            base.Update(gt);
        }