public void Touch(ContactData contact, int playerId)
 {
   if (playerId == turret.PlayerId)
   {
     turret.Active = true;
   }
 }
    public void Touch(ContactData contact, int playerId)
    {
      upgrade.Apply();

      // Hide the menu.
      App.Instance.Model.Players[playerId].ShowMenu(false);
      App.Instance.Model.Players[playerId].CanUpgrade = false;
    }
 public void Press(ContactData contact, int playerId)
 {
   if (playerId == turret.PlayerId)
   {
     contact.ContactUpdated += new EventHandler(Update);
     turret.Active = false;
   }
 }
 public void Release(ContactData contact, int playerId)
 {
   // Did the user change their mind? If not, do a regular Touch.
   if (upgrade.InRegion(contact.Contact))
   {
     Touch(contact, playerId);
   }
 }
 public void Release(ContactData contact, int playerId)
 {
   if (playerId == turret.PlayerId)
   {
     contact.ContactUpdated -= new EventHandler(Update);
     turret.Active = true;
   }
 }
    public void Touch(ContactData contact, int playerId)
    {
      MainGun p = App.Instance.Model.Players[playerId];

      // Upgrade ready?
      if (p.CanUpgrade && !p.UpgradeMenuShowing)
      {
        // Make upgrade menu appear.
        p.ShowMenu(true);
      }
      else if (p.UpgradeMenuShowing)
      {
        p.ShowMenu(false);
      }
    }
    public void Release(ContactData contact, int playerId)
    {
      MainGun p = App.Instance.Model.Players[playerId];

      // Upgrade ready?
      if (p.CanUpgrade && p.UpgradeMenuShowing)
      {
        // If contact is currently over one of the menu items, fire that
        // item's Touch.
        foreach (ITouchable option in App.Instance.Controller.Touchables)
        {
          if (option is Upgrade && ((Upgrade) option).UpgradeTarget == p && option.InRegion(contact.Contact))
          {
            option.Controller.Touch(contact, playerId);
            break;
          }
        }

        // Hide the menu.
        p.ShowMenu(false);
      }
    }
 protected void OnContactAdded(object sender, ContactData e)
 {
   if (e.Contact.IsTagRecognized)
   {
     AddPlayer(e);
   }
   else if (e.Contact.IsFingerRecognized)
   {
     foreach (ITouchable t in Touchables)
     {
       if (t.InRegion(e.Contact))
       {
         pendingPressed.Add(new TouchableContactPair(t, e));
       }
     }
   }
 }
    public void ProcessContacts(GameTime gameTime, ReadOnlyContactCollection contacts)
    {
      TimeSpan now = gameTime.TotalRealTime;

      // First process tags that are leaving.
      Queue<ContactData> q = leavingTags;
      ContactData current;
      leavingTags = new Queue<ContactData>();
      while (q.Count > 0)
      {
        current = q.Dequeue();
        if (current.LastSeen + new TimeSpan(0, 0, 0, 1) < now)
        {
          if (ContactRemoved != null) ContactRemoved(this, current);
        }
        else
        {
          Contact returned = FindReturned(contacts, current);
          if (returned != null)
          {
            current.Update(returned, now);
            activeContacts.Add(current);
          }
          else
          {
            leavingTags.Enqueue(current);
          }
        }
      }

      // Now get current contacts.
      foreach (Contact c in contacts)
      {
        bool found = false;
        // Search the collection of active contacts to see if we already know about this one.
        foreach (ContactData d in activeContacts)
        {
          if (c.Id == d.Contact.Id)
          {
            d.Update(c, now);
            found = true;
            break;
          }
        }

        // Not found? It's a new contact, add it and notify event handlers.
        if (!found)
        {
          ContactData d = new ContactData(c, now);
          activeContacts.Add(d);
          if (ContactAdded != null) ContactAdded(this, d);
        }
      }
      // Now check to see if there are any that need removing - these will have an outdated LastSeen.
      int length = activeContacts.Count;
      for (int i = 0; i < length; i++)
      {
        ContactData d = activeContacts[i];
        if (!d.LastSeen.Equals(now))
        {
          activeContacts.RemoveAt(i);
          i--;
          length--;
          if (d.Contact.IsTagRecognized)
          {
            leavingTags.Enqueue(d);
          }
          else
          {
            if (ContactRemoved != null) ContactRemoved(this, d);
          }
        }
      }

      // Finally, check to see if anything in pendingPressed can be moved to pressed.
      length = pendingPressed.Count;
      for (int i = 0; i < length; i++)
      {
        TouchableContactPair p = pendingPressed[i];
        if ((p.Contact.LastSeen - p.Contact.TimeAdded).TotalMilliseconds > 100 &&
          p.Touchable.InRegion(p.Contact.Contact))
        {
          pressed.Add(p);
          pendingPressed.RemoveAt(i);
          i--;
          length--;
          int player = WhichPlayer(p.Contact);
          if (player != -1)
          {
            p.Touchable.Controller.Press(p.Contact, player);
          }
        }
      }
    }
    private Contact FindReturned(ReadOnlyContactCollection contacts, ContactData gone)
    {
      foreach (Contact c in contacts)
      {
        // Not a tag, or is already associated with a player.
        if (!c.IsTagRecognized || GetPlayerIdByContact(c) != -1)
        {
          continue;
        }

        for (int i = 0; i < 4; i++)
        {
          if (playerTags[i] == gone.Contact.Id)
          {
            if (Vector2.Distance(new Vector2(c.CenterX, c.CenterY), gone.LastLocation) < 50)
            {
              playerTags[i] = c.Id;
              return c;
            }
            return null;
          }
        }
      }
      return null;
    }
    /// <summary>
    /// Of the active players, this method decides who was responsible for the given contact.
    /// </summary>
    /// <param name="c">The contact to check. Type should be tag or finger.</param>
    /// <returns>The playerid of the most likely responsible active player. -1 if no such player exists.</returns>
    private int WhichPlayer(ContactData c)
    {
      MainGun[] players = App.Instance.Model.Players;
      int[] sortedPlayers = null;
      int octant = (int) (4 * c.InitialOrientation / Math.PI);

      switch (octant)
      {
        case 0: // WNW
          sortedPlayers = new int[] { 3, 0, 2, 1 };
          break;
        case 1: // NNW
          sortedPlayers = new int[] { 0, 3, 1, 2 };
          break;
        case 2: // NNE
          sortedPlayers = new int[] { 0, 1, 3, 2 };
          break;
        case 3: // ENE
          sortedPlayers = new int[] { 1, 0, 2, 3 };
          break;
        case 4: // ESE
          sortedPlayers = new int[] { 1, 2, 0, 3 };
          break;
        case 5: // SSE
          sortedPlayers = new int[] { 2, 1, 3, 0 };
          break;
        case 6: // SSW
          sortedPlayers = new int[] { 2, 3, 1, 0 };
          break;
        case 7: // WSW
          sortedPlayers = new int[] { 3, 2, 0, 1 };
          break;
      }

      for (int i = 0; i < 4; i++)
      {
        if (players[sortedPlayers[i]].IsActive)
        {
          return sortedPlayers[i];
        }
      }

      return -1;
    }
 public TouchableContactPair(ITouchable touchable, ContactData contact)
 {
   this.touchable = touchable;
   this.contact = contact;
 }
 private void RemovePlayer(ContactData e)
 {
   for (int i = 0; i < 4; i++)
   {
     if (playerTags[i] == e.Contact.Id)
     {
       App.Instance.Model.PlayerLeave(i);
       playerTags[i] = 0;
       e.ContactUpdated -= new EventHandler(OnTagUpdated);
       break;
     }
   }
 }
    private void AddPlayer(ContactData e)
    {
      BaseModel model = App.Instance.Model;

      if (model.NumberOfPlayers < 4)
      {
        int newPlayer = WhichPlayer(new Vector2(e.Contact.CenterX, e.Contact.CenterY), false);
        model.PlayerJoin(newPlayer);
        playerTags[newPlayer] = e.Contact.Id;
        e.ContactUpdated += new EventHandler(OnTagUpdated);
      }
    }
Beispiel #15
0
        public void ProcessContacts(GameTime gameTime, ReadOnlyContactCollection contacts)
        {
            TimeSpan now = gameTime.TotalRealTime;

            // First process tags that are leaving.
            Queue <ContactData> q = leavingTags;
            ContactData         current;

            leavingTags = new Queue <ContactData>();
            while (q.Count > 0)
            {
                current = q.Dequeue();
                if (current.LastSeen + new TimeSpan(0, 0, 0, 1) < now)
                {
                    if (ContactRemoved != null)
                    {
                        ContactRemoved(this, current);
                    }
                }
                else
                {
                    Contact returned = FindReturned(contacts, current);
                    if (returned != null)
                    {
                        current.Update(returned, now);
                        activeContacts.Add(current);
                    }
                    else
                    {
                        leavingTags.Enqueue(current);
                    }
                }
            }

            // Now get current contacts.
            foreach (Contact c in contacts)
            {
                bool found = false;
                // Search the collection of active contacts to see if we already know about this one.
                foreach (ContactData d in activeContacts)
                {
                    if (c.Id == d.Contact.Id)
                    {
                        d.Update(c, now);
                        found = true;
                        break;
                    }
                }

                // Not found? It's a new contact, add it and notify event handlers.
                if (!found)
                {
                    ContactData d = new ContactData(c, now);
                    activeContacts.Add(d);
                    if (ContactAdded != null)
                    {
                        ContactAdded(this, d);
                    }
                }
            }
            // Now check to see if there are any that need removing - these will have an outdated LastSeen.
            int length = activeContacts.Count;

            for (int i = 0; i < length; i++)
            {
                ContactData d = activeContacts[i];
                if (!d.LastSeen.Equals(now))
                {
                    activeContacts.RemoveAt(i);
                    i--;
                    length--;
                    if (d.Contact.IsTagRecognized)
                    {
                        leavingTags.Enqueue(d);
                    }
                    else
                    {
                        if (ContactRemoved != null)
                        {
                            ContactRemoved(this, d);
                        }
                    }
                }
            }

            // Finally, check to see if anything in pendingPressed can be moved to pressed.
            length = pendingPressed.Count;
            for (int i = 0; i < length; i++)
            {
                TouchableContactPair p = pendingPressed[i];
                if ((p.Contact.LastSeen - p.Contact.TimeAdded).TotalMilliseconds > 100 &&
                    p.Touchable.InRegion(p.Contact.Contact))
                {
                    pressed.Add(p);
                    pendingPressed.RemoveAt(i);
                    i--;
                    length--;
                    int player = WhichPlayer(p.Contact);
                    if (player != -1)
                    {
                        p.Touchable.Controller.Press(p.Contact, player);
                    }
                }
            }
        }
Beispiel #16
0
 public TouchableContactPair(ITouchable touchable, ContactData contact)
 {
     this.touchable = touchable;
     this.contact   = contact;
 }
 public void Press(ContactData contact, int playerId)
 {
   Touch(contact, playerId);
 }
Beispiel #18
0
 public void Press(ContactData contact, int playerId)
 {
     Touch(contact, playerId);
 }
 protected void OnContactRemoved(object sender, ContactData e)
 {
   if (e.Contact.IsTagRecognized)
   {
     RemovePlayer(e);
   }
   else if (e.Contact.IsFingerRecognized)
   {
     foreach (TouchableContactPair p in pressed)
     {
       if (p.Contact == e)
       {
         int player = WhichPlayer(e);
         if (player != -1)
         {
           p.Touchable.Controller.Release(e, player);
         }
         return;
       }
     }
     int length = pendingPressed.Count;
     for (int i = 0; i < length; i++)
     {
       if (pendingPressed[i].Contact == e)
       {
         if (pendingPressed[i].Touchable.InRegion(e.Contact))
         {
           int player = WhichPlayer(e);
           if (player != -1)
           {
             pendingPressed[i].Touchable.Controller.Touch(e, player);
           }
         }
         pendingPressed.RemoveAt(i);
         return;
       }
     }
   }
 }
 public void Press(ContactData contact, int playerId)
 {
   // Do nothing - the user might change their mind.
 }