Esempio n. 1
0
 void p2_Move(object source, Glib.XNA.SpriteMoveEventArgs e)
 {
     if (!e.Cancel)
     {
         p2gun.Position -= e.OldPosition - e.NewPosition;
         p2gun2.Position -= e.OldPosition - e.NewPosition;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Draw the specified Sprite to this SpriteBatch.
 /// </summary>
 /// <param name="sb">The SpriteBatch to draw to.</param>
 /// <param name="sprToDraw">The sprite to draw.</param>
 public static void Draw(this SpriteBatch sb, Glib.XNA.SpriteLib.Sprite sprToDraw)
 {
     if (sprToDraw.Visible)
     {
         sb.Draw(sprToDraw.Texture, sprToDraw.Position, sprToDraw.DrawRegion, sprToDraw.Color, sprToDraw.Rotation.Radians, sprToDraw.Origin, sprToDraw.Scale, sprToDraw.Effect, 0f);
     }
 }
Esempio n. 3
0
        void NetworkData_DataReceived(object sender, Glib.XNA.NetworkLib.NetworkInformationReceivedEventArgs e)
        {
            if (!Visible)
            {
                return;
            }

            string[] propNameComponents = e.Data.Name.Split('.');

            if (propNameComponents[0].Equals("NewBullet", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Bullet Handling

                if (propNameComponents[1].Equals("PosSpeed", StringComparison.InvariantCultureIgnoreCase))
                {
                    Vector4 bulletData = (Vector4)e.Data.Data;
                    BaseAllyShip parent = null;
                    try
                    {
                        parent = StateManager.EnemyShips[e.Data.Sender];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        parent = StateManager.AllyShips[e.Data.Sender];
                    }
                    Bullet newBullet = StateManager.BulletPool.GetBullet();
                    newBullet.InitializePooledBullet(new Vector2(bulletData.X, bulletData.Y), parent);
                    newBullet.SpriteBatch = World;
                    newBullet.Speed = new Vector2(bulletData.Z, bulletData.W);
                    newBullet.MaximumDistance = new Vector2(4000f);
                    _bulletsInProgress[e.Data.Sender.Id] = newBullet;
                }
                else if (propNameComponents[1].Equals("FinalData", StringComparison.InvariantCultureIgnoreCase))
                {
                    Vector4 addlData = (Vector4)e.Data.Data;
                    Bullet newBullet = _bulletsInProgress[e.Data.Sender.Id];
                    newBullet.Rotation = SpriteRotation.FromRadians(addlData.Y);
                    newBullet.Damage = addlData.X.ToInt();

                    //Debug.WriteLine("Bullet received from {0}: X: {1}, Y: {2}", newBullet.ParentShip.Controller.Gamertag, newBullet.X, newBullet.Y);
                    (newBullet.ParentShip.PlayerType == PlayerType.Ally || newBullet.ParentShip.PlayerType == PlayerType.MyShip ? StateManager.AllyBullets : StateManager.EnemyBullets).Legit.Add(newBullet);
                    _bulletsInProgress.Remove(e.Data.Sender.Id);
                }
                #endregion
            }

            if (propNameComponents[0].Equals("MPShip", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Ship Handling
                if (propNameComponents[1].Equals("CurrentShipState", StringComparison.InvariantCultureIgnoreCase))
                {
                    Vector4 shipData = (Vector4)e.Data.Data;
                    foreach (Ship s in StateManager.EnemyShips)
                    {
                        BaseAllyShip sh = s as BaseAllyShip;
                        if (sh != null && sh.Controller != null && sh.Controller.Id == e.Data.Sender.Id)
                        {
                            Debug.WriteLine("Received ship data from {0}: [{1}, {2}], health {3}", e.Data.Sender.Gamertag, shipData.X, shipData.Y, shipData.W);
                            sh.WorldCoords = new Vector2(shipData.X, shipData.Y);
                            sh.Rotation = SpriteRotation.FromRadians(shipData.Z);
                            sh.CurrentHealth = shipData.W.ToInt();
                            break;
                        }
                    }
                    foreach (Ship s in StateManager.AllyShips)
                    {
                        BaseAllyShip sh = s as BaseAllyShip;
                        if (sh != null && sh.Controller != null && sh.Controller.Id == e.Data.Sender.Id)
                        {
                            Debug.WriteLine("Received ship data from {0}: [{1}, {2}], health {3}", e.Data.Sender.Gamertag, shipData.X, shipData.Y, shipData.W);
                            sh.WorldCoords = new Vector2(shipData.X, shipData.Y);
                            sh.Rotation = SpriteRotation.FromRadians(shipData.Z);
                            sh.CurrentHealth = shipData.W.ToInt();
                            break;
                        }
                    }
                }
                #endregion
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Create a new SpriteClickEventArgs, specifying a position and sprite.
 /// </summary>
 /// <param name="x">The X position of the click.</param>
 /// <param name="y">The Y position of the click.</param>
 /// <param name="spr">The sprite that was clicked on.</param>
 /// <param name="manager">Whether or not this event is being called by a SpriteManager.</param>
 public SpriteClickEventArgs(Glib.XNA.SpriteLib.Sprite spr, int x, int y, bool manager)
 {
     this.Sprite = spr;
     this.X = x;
     this.CalledByManager = manager;
     this.Y = y;
 }
        void Component_NetworkInformationReceived(object sender, Glib.XNA.NetworkLib.NetworkInformationReceivedEventArgs e)
        {
            string[] propComponents = e.Data.Name.Split('.');

            if (!propComponents[0].Equals("MPShip", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            ships.Clear();

            StateManager.SelectedShip = StateManager.NetworkData.SelectedNetworkShip.Type;
            StateManager.SelectedTier = StateManager.NetworkData.SelectedNetworkShip.Tier;
            StateManager.InitializeSingleplayerGameScreen(SelectedShips[StateManager.NetworkData.CurrentSession.LocalGamers[0].Id].Type, SelectedShips[StateManager.NetworkData.CurrentSession.LocalGamers[0].Id].Tier, false);

            int gamersReceived = 0;

            NetworkGamer infosender;
            //netGamer.ReceiveData(StateManager.NetworkData.DataReader, out infosender);

            MultiplayerTeam? mpTeam = null;
            if (StateManager.NetworkData.SessionMode == MultiplayerSessionType.TDM || StateManager.NetworkData.SessionMode == MultiplayerSessionType.Coop)
            {
                mpTeam = (MultiplayerTeam)Enum.Parse(typeof(MultiplayerTeam), StateManager.NetworkData.DataReader.ReadInt32().ToString(), true);
            }

            Vector4 ship = StateManager.NetworkData.DataReader.ReadVector4();

            NetworkPlayerID targetPlayer = new NetworkPlayerID(Guid.NewGuid());
            if (StateManager.NetworkData.DataReader.ReadBoolean())
            {
                targetPlayer = new NetworkPlayerID(StateManager.NetworkData.DataReader.ReadByte());
            }

            ships.Add(targetPlayer, new KeyValuePair<MultiplayerTeam?, Vector4>(mpTeam, ship));
            gamersReceived++;
        }