Exemple #1
0
        public SpaceGameplay(FreelancerGame g, GameSession session) : base(g)
        {
            FLLog.Info("Game", "Starting Gameplay Demo");
            sys = g.GameData.GetSystem(session.PlayerSystem);
            var shp = g.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            this.session = session;
            player       = new GameObject(shp.Drawable, g.ResourceManager, false);
            control      = new ShipControlComponent(player);
            control.Ship = shp;
            player.Components.Add(control);
            powerCore = new PowerCoreComponent(player)
            {
                ThrustCapacity   = 1000,
                ThrustChargeRate = 100
            };
            player.Components.Add(powerCore);
            player.PhysicsComponent.Position             = session.PlayerPosition;
            player.PhysicsComponent.Orientation          = session.PlayerOrientation;
            player.PhysicsComponent.Material.Restitution = 1;
            player.PhysicsComponent.Mass = shp.Mass;
            player.Nickname = "player";
            foreach (var equipment in session.MountedEquipment)
            {
                var equip = g.GameData.GetEquipment(equipment.Value);
                var obj   = new GameObject(equip, player.GetHardpoint(equipment.Key), player);
                player.Children.Add(obj);
            }

            camera = new ChaseCamera(Game.Viewport);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = new Matrix4(player.PhysicsComponent.Orientation);
            camera.Reset();

            sysrender = new SystemRenderer(camera, g.GameData, g.ResourceManager, g);
            world     = new GameWorld(sysrender);
            world.LoadSystem(sys, g.ResourceManager);
            world.Objects.Add(player);
            world.Physics.SetDampingFactors(0.01f, 1f);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            var eng = new GameData.Items.Engine()
            {
                FireEffect = "gf_li_smallengine02_fire", LinearDrag = 600, MaxForce = 48000
            };

            player.Components.Add((ecpt = new EngineComponent(player, eng, g)));
            ecpt.Speed = 0;
            player.Register(sysrender, world.Physics);
            g.Sound.PlayMusic(sys.MusicSpace);
            trender = new Renderer2D(Game.RenderState);
            font    = g.Fonts.GetSystemFont("Agency FB");
            g.Keyboard.TextInput += G_Keyboard_TextInput;
            debugphysics          = new PhysicsDebugRenderer();
            cur_arrow             = g.ResourceManager.GetCursor("cross");
            cur_reticle           = g.ResourceManager.GetCursor("fire_neutral");
            current_cur           = cur_arrow;
            hud = new Hud(g);
            hud.SetManeuver("FreeFlight");
            Game.Keyboard.TextInput += Game_TextInput;
            g.Keyboard.KeyDown      += Keyboard_KeyDown;
            input = new InputManager(Game);
            input.ToggleActivated       += Input_ToggleActivated;
            input.ToggleUp              += Input_ToggleUp;
            hud.OnManeuverSelected      += Hud_OnManeuverSelected;
            hud.OnEntered               += Hud_OnTextEntry;
            pilotcomponent               = new AutopilotComponent(player);
            pilotcomponent.DockComplete += Pilotcomponent_DockComplete;
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
        }
        void FinishLoad()
        {
            var shp = Game.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            player       = new GameObject(shp.Drawable, Game.ResourceManager, false);
            control      = new ShipControlComponent(player);
            control.Ship = shp;
            player.Components.Add(control);
            weapons = new WeaponControlComponent(player);
            player.Components.Add(weapons);
            powerCore = new PowerCoreComponent(player)
            {
                ThrustCapacity   = 1000,
                ThrustChargeRate = 100
            };
            player.Components.Add(powerCore);
            player.Transform             = new Matrix4(session.PlayerOrientation) * Matrix4.CreateTranslation(session.PlayerPosition);
            player.PhysicsComponent.Mass = shp.Mass;
            if (shp.Mass < 0)
            {
                FLLog.Error("Ship", "Mass < 0");
            }
            player.Nickname = "player";
            foreach (var equipment in session.MountedEquipment)
            {
                var equip = Game.GameData.GetEquipment(equipment.Value);
                if (equip == null)
                {
                    continue;
                }
                equip.LoadResources();
                var obj = new GameObject(equip, player.GetHardpoint(equipment.Key), player);
                player.Children.Add(obj);
            }

            camera = new ChaseCamera(Game.Viewport);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = player.Transform.ClearTranslation();
            var offset = shp.ChaseOffset;

            camera.DesiredPositionOffset = offset;
            camera.Reset();

            sysrender = new SystemRenderer(camera, Game.GameData, Game.ResourceManager, Game);
            world     = new GameWorld(sysrender);
            world.LoadSystem(sys, Game.ResourceManager);

            world.Objects.Add(player);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            var eng = new GameData.Items.Engine()
            {
                FireEffect = "gf_li_smallengine02_fire", LinearDrag = 600, MaxForce = 48000
            };

            player.Components.Add((ecpt = new EngineComponent(player, eng, Game)));
            ecpt.Speed = 0;
            player.Register(world.Physics);
            Game.Sound.PlayMusic(sys.MusicSpace);
            Game.Keyboard.TextInput += G_Keyboard_TextInput;
            debugphysics             = new PhysicsDebugRenderer();
            //world.Physics.EnableWireframes(debugphysics);
            cur_arrow                = Game.ResourceManager.GetCursor("cross");
            cur_reticle              = Game.ResourceManager.GetCursor("fire_neutral");
            current_cur              = cur_arrow;
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += Mouse_MouseDown;
            input = new InputManager(Game);
            input.ToggleActivated       += Input_ToggleActivated;
            input.ToggleUp              += Input_ToggleUp;
            pilotcomponent               = new AutopilotComponent(player);
            pilotcomponent.DockComplete += Pilotcomponent_DockComplete;
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
            ConstructHud();
            FadeIn(0.5, 0.5);
        }