예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MyNode"/> class.
        /// </summary>
        /// <param name="rand">The rand.</param>
        /// <param name="circleTex">The circle tex.</param>
        /// <param name="screenSize">Size of the screen.</param>
        /// <param name="gardener">The gardener.</param>
        public MyNode(Random rand, Texture2D circleTex, Point screenSize, Gardener gardener)
            : base(rand, circleTex, screenSize)
        {
            this.NodeSizeMax = 70;

            this.gardener = gardener;

            var accentColor = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
            this.color = GetXnaColour(accentColor);

            // set the controllable node to take touch events
            Touch.FrameReported += this.TouchFrameReported;

            this.DisableVirtualMovement = true;

            var pingTag = new PingTag { AccentColour = accentColor };
            this.Tag = pingTag.Serialize();
        }
예제 #2
0
 private void Ping()
 {
     var selfNode = this.nodes.FirstOrDefault(n => n.NodeType == TypeOfNode.Self);
     selfNode.CreateRipple();
     var tag = new PingTag { AccentColour = selfNode.AccentColour, Ping = true };
     gardener.UpdateSelfNodePosition(selfNode.X, selfNode.Y, tag.Serialize());
     gardener.ClearSelfPing();
 }
예제 #3
0
        /// <summary>
        /// Handles the FrameReported event of the Touch control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.TouchFrameEventArgs"/> instance containing the event data.</param>
        private void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint tp = e.GetPrimaryTouchPoint(null);
            switch (tp.Action)
            {
                case TouchAction.Down:
                    // when the user touches the screen find out if they hit the node, if so start dragging
                    if (Vector2.DistanceSquared(new Vector2((float)tp.Position.X, (float)tp.Position.Y), this.Position) < Global.TouchPointSize * Global.TouchPointSize)
                    {
                        this.isBeingDragged = true;
                        heldAt = new Vector2((float)tp.Position.X, (float)tp.Position.Y);
                    }

                    break;

                case TouchAction.Move:
                    // if dragging move the node to the touch position
                    if (this.isBeingDragged)
                    {
                        var x = tp.Position.X;
                        var y = tp.Position.Y;

                        this.Position = new Vector2((float)x, (float)y);

                        var accentColour = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
                        var tag = new PingTag { AccentColour = accentColour, Ping = false };
                        this.gardener.UpdateSelfNodePosition(x, y, tag.Serialize());
                    }

                    break;

                case TouchAction.Up:
                    // release finger and stop dragging
                    this.isBeingDragged = false;
                    if (heldAt == new Vector2((float)tp.Position.X, (float)tp.Position.Y))
                    {
                        Debug.WriteLine("Ping");
                        var accentColour = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
                        CreateRipple(GetXnaColour(accentColour));
                        var tag = new PingTag { AccentColour = accentColour, Ping = true };
                        gardener.UpdateSelfNodePosition(tp.Position.X, tp.Position.Y, tag.Serialize());
                        gardener.ClearSelfPing();
                    }
                    break;
                default:
                    break;
            }
        }