コード例 #1
0
ファイル: ShipObj.cs プロジェクト: Aryn/Mobile-Fortress
        public ShipObj(MobileFortressClient game,Vector3 position, Quaternion orientation, ShipData data)
            : base(game,position,orientation,2)
        {
            Data = data;
            Data.ComposeHitbox();
            Data.Hitbox.Position = position;
            Sector.Redria.Space.Add(Data.Hitbox);
            this.Entity = Data.Hitbox;

            //Thrusters = new SingleEntityLinearMotor(Entity, Position);
            //ControlSurfaces = new SingleEntityAngularMotor(Entity);
            //ControlSurfaces.Settings.Mode = MotorMode.Servomechanism;
            //ControlSurfaces.Settings.Servo.MaxCorrectiveVelocity = 2;

            //Thrusters.Settings.Mode = MotorMode.VelocityMotor;
            //Thrusters.Settings.VelocityMotor.Softness = 0.002f;

            //Sector.Redria.Space.Add(Thrusters);
            //Sector.Redria.Space.Add(ControlSurfaces);
            Entity.IsAffectedByGravity = false;

            engineNoise = Resources.Sounds.Engine.CreateInstance();
            engineNoise.Apply3D(Camera.Audio, Audio);
            engineNoise.IsLooped = true;
            engineNoise.Play();
            Entity.CollisionInformation.Tag = this;
        }
コード例 #2
0
ファイル: MessageWriter.cs プロジェクト: Aryn/Mobile-Fortress
        public static void ShipDataOutputMessage(ShipData src)
        {
            var msg = Network.Client.CreateMessage();
            var Nose = src.NoseID;
            var Core = src.CoreID;
            var Engine = src.EngineID;
            int i = 0;
            var Weapons = new int[src.Weapons.Values.Count];
            var FireGroups = new byte[src.Weapons.Values.Count];
            if(src.Nose.WeaponSlots != null)
                foreach (Vector3 offset in src.Nose.WeaponSlots)
                {
                    if (src.Weapons[offset] != null)
                    {
                        Weapons[i] = src.Weapons[offset].Index;
                        FireGroups[i++] = src.Weapons[offset].fireGroup;
                    }
                }
            if (src.Core.WeaponSlots != null)
                foreach (Vector3 offset in src.Core.WeaponSlots)
                {
                    if (src.Weapons[offset] != null)
                    {
                        Weapons[i] = src.Weapons[offset].Index;
                        FireGroups[i++] = src.Weapons[offset].fireGroup;
                    }
                }
            if (src.Engine.WeaponSlots != null)
                foreach (Vector3 offset in src.Engine.WeaponSlots)
                {
                    if (src.Weapons[offset] != null)
                    {
                        Weapons[i] = src.Weapons[offset].Index;
                        FireGroups[i++] = src.Weapons[offset].fireGroup;
                    }
                }
            msg.Write((byte)NetMsgType.ShipDataOutput);
            msg.Write(Nose);
            msg.Write(Core);
            msg.Write(Engine);

            var NC = src.NoseColor;
            msg.Write(NC.R); msg.Write(NC.G); msg.Write(NC.B);
            var CC = src.CoreColor;
            msg.Write(CC.R); msg.Write(CC.G); msg.Write(CC.B);
            var TC = src.TailColor;
            msg.Write(TC.R); msg.Write(TC.G); msg.Write(TC.B);
            var WC = src.WeaponColor;
            msg.Write(WC.R); msg.Write(WC.G); msg.Write(WC.B);

            msg.Write(Weapons.Length);
            for (i = 0; i < Weapons.Length; i++)
            {
                msg.Write(Weapons[i]);
                msg.Write(FireGroups[i]);
            }
            Network.Client.SendMessage(msg, Lidgren.Network.NetDeliveryMethod.ReliableOrdered);
        }
コード例 #3
0
ファイル: DataManager.cs プロジェクト: Aryn/Mobile-Fortress
        public override void HandleData(NetIncomingMessage msg)
        {
            NetEntityType Type;
            ushort ID;
            Vector3 Position;
            Vector3 Velocity;
            Quaternion Orientation;
            NetMsgType datatype = (NetMsgType)msg.ReadByte();
            switch (datatype)
            {
                case NetMsgType.Chat:
                    Console.WriteLine(msg.ReadString());
                    break;
                case NetMsgType.CreateOnClient:
                    #region CreateOnClient
                    Type = (NetEntityType)msg.ReadByte();
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    ushort Resource;
                    long OwnerID;

                    //DEBUG
                    if (Type == NetEntityType.Ship)
                    {
                        int[] shipWeapons = null;
                        var shipNose = msg.ReadInt32();
                        var shipCore = msg.ReadInt32();
                        var shipTail = msg.ReadInt32();
                        int weaponLength = msg.ReadInt32();
                        if (weaponLength > 0)
                        {
                            shipWeapons = new int[weaponLength];
                            for (int i = 0; i < weaponLength; i++)
                                shipWeapons[i] = msg.ReadInt32();
                        }
                        Resource = 0;
                        OwnerID = msg.ReadInt64();
                        var shipData = new ShipData(shipNose, shipCore, shipTail);
                        WeaponsFromData(shipData, shipWeapons);
                        var ship = new ShipObj(MobileFortressClient.Game, Position, Orientation, shipData);
                        ship.ID = ID;
                        if (OwnerID == Network.Client.UniqueIdentifier)
                        {
                            Network.JoinedGame = true;
                            Camera.Setup(MobileFortressClient.Game, ship, new Vector3(0, 2f, 6f));
                            var HUD = new ShipHUD();
                            if (shipWeapons != null)
                            {
                                for (int i = 0; i < shipWeapons.Length; i++)
                                {
                                    HUD.MakeAmmoIndicator(shipWeapons[i]);
                                }
                            }
                            MenuManager.Menu = HUD;
                        }
                    }
                    else
                    {
                        Resource = msg.ReadUInt16();
                        if (Type == NetEntityType.Building)
                        {
                            new Building(Position, Resource);
                        }
                        else if (Type == NetEntityType.Missile)
                        {
                            var obj = new Rocket(MobileFortressClient.Game, Resource, Position, Orientation);
                            obj.ID = ID;
                        }
                        else
                        {
                            var obj = new PhysicsObj(MobileFortressClient.Game, Position, Orientation, Resource);
                            obj.ID = ID;
                        }
                    }
                    #endregion
                    break;
                case NetMsgType.MapLoading:
                    #region MapLoading
                    if (msg.ReadByte() == 0)
                    {
                        var Seed = msg.ReadInt32();
                        var Power = msg.ReadInt32();
                        var Roughness = msg.ReadFloat();
                        Sector.Redria.Terrain.Terrain = new Heightmap(Seed, Power, Roughness);
                    }
                    else
                    {
                        var terrain = Sector.Redria.Terrain.Terrain;
                        int alterations = msg.ReadInt32();
                        Console.WriteLine(alterations + " Recieved Alterations.");
                        for (int i = 0; i < alterations; i++)
                        {
                            Rectangle flattenedArea = new Rectangle(msg.ReadInt32(),
                                msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32());
                            terrain.FlattenArea(flattenedArea);

                        }
                        terrain.Graphics.ResetVertexBuffer();

                    }
                    #endregion
                    break;
                case NetMsgType.EntityUpdate:
                    #region EntityUpdate
                    Type = (NetEntityType)msg.ReadByte();
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Velocity = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    if (Type == NetEntityType.Ship)
                    {
                        var ship = Sector.Redria.Ships.Retrieve(ID);
                        if (ship == null)
                        {
                            Console.WriteLine("No such ship ID: " + ID);
                            break;
                        }
                        ship.UpdateFromNet(Position, Orientation, Velocity);
                    }
                    else if (Type == NetEntityType.Missile)
                    {
                        var missile = Sector.Redria.Objects.Retrieve(ID);
                        if (missile == null) break;
                        missile.UpdateFromNet(Position, Orientation, Velocity);
                    }
                    #endregion
                    break;
                case NetMsgType.Bullet:
                    #region Bullet
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Velocity = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    var Projectile = ProjectileData.ProjectileTable[ID];
                    var ping = Network.Client.ServerConnection.AverageRoundtripTime;
                    Projectile.Create(Position + Velocity * (ping / 2), Orientation, Velocity);
                    var Audio = new AudioEmitter();
                    Audio.Position = Position / Resources.AudioPositionQuotient;
                    Audio.Forward = Vector3.Transform(Vector3.Forward, Orientation);
                    Audio.Up = Vector3.Up;
                    Audio.Velocity = Velocity;

                    var sound = Resources.Sounds.WeaponSounds[ID].CreateInstance();
                    sound.Apply3D(Camera.Audio, Audio);
                    sound.Play();
                    #endregion
                    break;
                case NetMsgType.ShipExplode:
                    #region ShipExplode
                    ID = msg.ReadUInt16();
                    var deadship = Sector.Redria.Ships.Retrieve(ID);
                    deadship.Explode();
                    #endregion
                    break;
                case NetMsgType.Explosion:
                    #region Explosion
                    ID = msg.ReadUInt16();
                    var Radius = msg.ReadFloat();
                    var exploding = Sector.Redria.Objects.Retrieve(ID);
                    if (exploding != null)
                    {
                        new Explosion(exploding.Position, Radius);
                        exploding.Destroy();
                    }
                    #endregion
                    break;
                case NetMsgType.Lockon:
                    #region Lockon
                    if (!(MenuManager.Menu is ShipHUD))
                        break;
                    ID = msg.ReadUInt16();
                    var LockonStatus = (LockonStatus)msg.ReadByte();
                    ShipHUD Menu = (ShipHUD)MenuManager.Menu;
                    if (LockonStatus > LockonStatus.Locked)
                    {
                        if (LockonStatus == LockonStatus.EnemyLock)
                        {
                            Menu.enemyLock = true;
                        }
                        else if (LockonStatus == LockonStatus.EnemyMissile)
                        {
                            Menu.enemyLock = false;
                            Menu.enemyMissile = true;
                        }
                        else
                        {
                            Menu.enemyMissile = false;
                            Menu.enemyLock = false;
                        }
                    }
                    else
                    {
                        if (ID == ushort.MaxValue)
                        {
                            Menu.Target = null;
                            Menu.LockStatus = LockonStatus.NotLocked;
                        }
                        else
                        {
                            Menu.Target = Sector.Redria.Ships.Retrieve(ID);
                            Menu.LockStatus = LockonStatus;
                            if (Menu.LockStatus == LockonStatus.Locking)
                                Resources.Sounds.LockingOn.Play();
                            else if (Menu.LockStatus == LockonStatus.Locked)
                                Resources.Sounds.LockedOn.Play();
                        }
                    }
                    #endregion
                    break;

                case NetMsgType.ShipUpdate:
                    #region ShipUpdate
                    var Health = msg.ReadFloat();
                    var Throttle = msg.ReadFloat();
                    var AmmoCount = msg.ReadByte();
                    var Ammo = new ushort[AmmoCount];
                    for (byte i = 0; i < AmmoCount; i++)
                    {
                        Ammo[i] = msg.ReadUInt16();
                    }
                    if (MenuManager.Menu is ShipHUD)
                    {
                        var HUD = (ShipHUD)MenuManager.Menu;
                        HUD.SetHealth((int)Health);

                        for (int i = 0; i < Ammo.Length; i++)
                            HUD.SetAmmo(i, Ammo[i]);
                        ping = msg.SenderConnection.AverageRoundtripTime * 1000;
                        HUD.SetPing(ping);

                        var ship = (ShipObj)Camera.Target;
                        ship.SetThrottle(Throttle);
                    }

                    #endregion
                    break;
                default:
                    Console.WriteLine("Unhandled NetMsgType: " + datatype);
                    break;
            }
        }
コード例 #4
0
ファイル: DataManager.cs プロジェクト: Aryn/Mobile-Fortress
 static void WeaponsFromData(ShipData ship, int[] weapondata)
 {
     if (weapondata != null)
     {
         for (int i = 0; i < weapondata.Length; i++)
         {
             Vector3? freeSlot = FreeSlot(ship, ship.Nose);
             if (freeSlot != null)
             {
                 ship.SetWeapon((Vector3)freeSlot, WeaponData.WeaponTypes[weapondata[i]].Copy());
                 continue;
             }
             freeSlot = FreeSlot(ship, ship.Core);
             if (freeSlot != null)
             {
                 ship.SetWeapon((Vector3)freeSlot, WeaponData.WeaponTypes[weapondata[i]].Copy());
                 continue;
             }
             freeSlot = FreeSlot(ship, ship.Engine);
             if (freeSlot != null)
             {
                 ship.SetWeapon((Vector3)freeSlot, WeaponData.WeaponTypes[weapondata[i]].Copy());
                 continue;
             }
         }
     }
 }
コード例 #5
0
ファイル: DataManager.cs プロジェクト: Aryn/Mobile-Fortress
 static Vector3? FreeSlot(ShipData ship, PartData part)
 {
     if (part.WeaponSlots == null) return null;
     foreach (Vector3 offset in part.WeaponSlots)
     {
         if (ship.Weapons[offset] == null) return offset;
     }
     return null;
 }
コード例 #6
0
        public override void Initialize()
        {
            Viewport viewport = MobileFortressClient.Game.GraphicsDevice.Viewport;

            Weapon1 = new UIWeaponSelector(this, new Point(12, viewport.Height- 256 - 48));
            Weapon2 = new UIWeaponSelector(this, new Point(12, viewport.Height - 192 - 36));
            Weapon3 = new UIWeaponSelector(this, new Point(12, viewport.Height - 128 - 24));
            Weapon4 = new UIWeaponSelector(this, new Point(12, viewport.Height - 64 - 12));
            Weapon1.NameBar.Clicked += SelectPart;
            Weapon2.NameBar.Clicked += SelectPart;
            Weapon3.NameBar.Clicked += SelectPart;
            Weapon4.NameBar.Clicked += SelectPart;
            Weapon1.graphicBox.Clicked += IncrementWeaponGroup;
            Weapon2.graphicBox.Clicked += IncrementWeaponGroup;
            Weapon3.graphicBox.Clicked += IncrementWeaponGroup;
            Weapon4.graphicBox.Clicked += IncrementWeaponGroup;
            Weapon1.UpArrow.Clicked += PreviousWeapon;
            Weapon1.DownArrow.Clicked += NextWeapon;
            Weapon2.UpArrow.Clicked += PreviousWeapon;
            Weapon2.DownArrow.Clicked += NextWeapon;
            Weapon3.UpArrow.Clicked += PreviousWeapon;
            Weapon3.DownArrow.Clicked += NextWeapon;
            Weapon4.UpArrow.Clicked += PreviousWeapon;
            Weapon4.DownArrow.Clicked += NextWeapon;

            Ship = new ShipData(1, 1, 1);

            Nose = new UIPartSelector(this, new Point(375 + 12, viewport.Height - 192 - 36 + 8));
            Nose.Part = Ship.Nose;
            Nose.UpArrow.Clicked += PreviousNose;
            Nose.DownArrow.Clicked += NextNose;
            Nose.NameBar.Clicked += SelectPart;
            Core = new UIPartSelector(this, new Point(375 + 12, viewport.Height - 128 - 24 + 8));
            Core.PartType = "Core";
            Core.Part = Ship.Core;
            Core.UpArrow.Clicked += PreviousCore;
            Core.DownArrow.Clicked += NextCore;
            Core.NameBar.Clicked += SelectPart;
            Engine = new UIPartSelector(this, new Point(375 + 12, viewport.Height - 64 - 12 + 8));
            Engine.PartType = "Engine";
            Engine.Part = Ship.Engine;
            Engine.UpArrow.Clicked += PreviousEngine;
            Engine.DownArrow.Clicked += NextEngine;
            Engine.NameBar.Clicked += SelectPart;

            ConfirmButton = new UIStandardButton(this, new Point(viewport.Width - 198 - 16, 8), "Launch");
            ConfirmButton.hasButton = true;
            ConfirmButton.Clicked += Confirm;
            Manager.Elements.Add(ConfirmButton);

            Texture2D tex = Resources.Menus.Customization.DescriptionScreen;
            DescriptionBox = new UIElement(this, tex,
                new Rectangle(5, 5, tex.Width, tex.Height));

            Manager.ClickAway += SelectPart;

            pointerTex = Resources.Menus.Title.Pointer;
            pointerDimensions = new Rectangle(0, 0, pointerTex.Width, pointerTex.Height);

            Camera.CustomizationSetup(MobileFortressClient.Game,new Vector3(0,1.5f,6));
        }