Exemple #1
0
 protected void DispatchDirectionEvent(DirectionEvent directionEvent, Vector3 position, Vector3 direction)
 {
     if (directionEvent != null)
     {
         directionEvent(position, direction);
     }
 }
        private void Initialize(Rectangle boundingBox, DirectionEvent directionEventHandler, bool isMirror)
        {
            int buttonWidth = boundingBox.Width / 2;
            int buttonHeight = boundingBox.Height / 2;

            clickableRegion = new Polygon(new Point[] { new Point(buttonWidth / 2, 0),
                                                        new Point(buttonWidth, buttonHeight / 2),
                                                        new Point(buttonWidth / 2, buttonHeight),
                                                        new Point(0, buttonHeight / 2)});

            buttons = new Button[(int) Entity.DirectionType.SIZE];
            textures = new Texture2D[(int) Entity.DirectionType.SIZE];
            boundingBoxes = new Rectangle[(int) Entity.DirectionType.SIZE];

            /* 0:North, 1:South, 2:East, 3:West */
            if (isMirror) {
                textures[0] = MediaRepository.Textures["Mirror_NE"];
                textures[1] = MediaRepository.Textures["Mirror_SW"];
                textures[2] = MediaRepository.Textures["Mirror_SE"];
                textures[3] = MediaRepository.Textures["Mirror_NW"];

                boundingBoxes[3] = new Rectangle(buttonWidth / 2, 0, buttonWidth, buttonHeight);
                boundingBoxes[1] = new Rectangle(0, buttonHeight / 2, buttonWidth, buttonHeight);
                boundingBoxes[0] = new Rectangle(buttonWidth, buttonHeight / 2, buttonWidth, buttonHeight);
                boundingBoxes[2] = new Rectangle(buttonWidth / 2, buttonHeight, buttonWidth, buttonHeight);
            } else {
                textures[0] = MediaRepository.Textures["Arrow_N"];
                textures[1] = MediaRepository.Textures["Arrow_S"];
                textures[2] = MediaRepository.Textures["Arrow_E"];
                textures[3] = MediaRepository.Textures["Arrow_W"];

                boundingBoxes[0] = new Rectangle(buttonWidth, 0, buttonWidth, buttonHeight);
                boundingBoxes[1] = new Rectangle(0, buttonHeight, buttonWidth, buttonHeight);
                boundingBoxes[2] = new Rectangle(buttonWidth, buttonHeight, buttonWidth, buttonHeight);
                boundingBoxes[3] = new Rectangle(0, 0, buttonWidth, buttonHeight);
            }

            for (int n = 0; n < (int) Entity.DirectionType.SIZE; n++) {
                buttons[n] = new Button(textures[n], boundingBoxes[n], Color.White);
                AddComponent(buttons[n]);
                buttons[n].AddActionListener(this);
                buttons[n].clickableRegionRel = new Polygon(clickableRegion);
            }

            this.directionEventHandler = directionEventHandler;

            base.Deactivate();
        }
 protected virtual void OnDirectionChanged(string dir)
 {
     DirectionEvent de = new DirectionEvent();
     de.Direction = dir;
     DirectionChanged?.Invoke(this, de);
 }
        static void KeyReader()
        {
            while (play)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKey k = Console.ReadKey(true).Key;
                    switch (k)
                    {
                    case ConsoleKey.Spacebar:
                    {
                        delay -= 25;
                        if (delay < 25)
                        {
                            delay = 25;
                        }
                        break;
                    }

                    case ConsoleKey.Enter:
                    {
                        delay += 25;
                        if (delay > 600)
                        {
                            delay = 600;
                        }
                        break;
                    }

                    case ConsoleKey.UpArrow:
                    {
                        DirectionEvent?.Invoke(direction.up);
                        break;
                    }

                    case ConsoleKey.LeftArrow:
                    {
                        DirectionEvent?.Invoke(direction.left);
                        break;
                    }

                    case ConsoleKey.DownArrow:
                    {
                        DirectionEvent?.Invoke(direction.down);
                        break;
                    }

                    case ConsoleKey.RightArrow:
                    {
                        DirectionEvent?.Invoke(direction.right);
                        break;
                    }

                    case ConsoleKey.Escape:
                    {
                        break;
                    }
                    }
                }
            }
        }
 public DirectionPanel(Rectangle boundingBox, DirectionEvent directionEventHandler)
     : base(MediaRepository.Textures["Blank"], boundingBox, Color.TransparentWhite)
 {
     Initialize(boundingBox, directionEventHandler, false);
 }