Example #1
0
        void _checkKeys(IGameTimeService gameTime)
        {
            if (PlayerPilot == null || PlayerPilot.PilotType != PilotType.Player)
            {
                return;//This is a semi ugly hack to enable bot clients for stress testing.
            }


            if (KeyboardManager.EnterMode.IsBindTapped() || GamepadManager.EnterMode.IsBindTapped())
            {
                if (PlayerShip.EnterMode == false)
                {
                    PlayerShip.EnterMode = true;
                }
                else
                {
                    PlayerShip.EnterMode = false;
                }
            }

#if ADMIN
            if (KeyboardManager.SetPosTo0.IsBindTapped())
            {
                PlayerShip.Position = new Microsoft.Xna.Framework.Vector2(0, 0);
            }
            if (KeyboardManager.AdminMoveDown.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X, oldPos.Y + 1);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveUp.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X, oldPos.Y - 1);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveLeft.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X - 1, oldPos.Y);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveRight.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X + 1, oldPos.Y);
                PlayerShip.Position = newPos;
            }
#endif


            Ship playerShip = PlayerShip;


            if (PlayerShip != null && PlayerShip.Pilot.IsAlive)
            {
                PlayerPilot playerPilot = (PlayerPilot)playerShip.Pilot;

                #region Movement

                if (KeyboardManager.HoldPlayerPosition.IsBindTapped() || GamepadManager.HoldPlayerPosition.IsBindTapped())
                {
                    playerPilot.HoldingPosition = true;
                }

                if (playerPilot.HoldingPosition)
                {
                    playerPilot.StopShip(gameTime);
                }

                if (KeyboardManager.TurnLeft.IsBindPressed() || GamepadManager.TurnLeft.IsBindPressed())
                {
                    playerShip.IsTurningCounterClockwise = true;
                    playerPilot.HoldingPosition          = false;
                }
                else
                {
                    playerShip.IsTurningCounterClockwise = false;
                }
                if (KeyboardManager.TurnRight.IsBindPressed() || GamepadManager.TurnRight.IsBindPressed())
                {
                    playerShip.IsTurningClockwise = true;
                    playerPilot.HoldingPosition   = false;
                }
                else
                {
                    playerShip.IsTurningClockwise = false;
                }

                if (KeyboardManager.ThrustUp.IsBindPressed() || GamepadManager.ThrustUp.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed()) //If boosting
                    {
                        playerShip.Thrust(ThrustTypes.BoostForward);
                    }
                    else //If not boosting
                    {
                        playerShip.Thrust(ThrustTypes.Forward);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustDown.IsBindPressed() || GamepadManager.ThrustDown.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostBackward);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.Backward);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustLateralLeft.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostLeftLateral);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.LeftLateral);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustLateralRight.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostRightLateral);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.RightLateral);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else
                {
                    playerShip.Thrusting = false;
                }

                #endregion

                #region Firing Weapons

                if (KeyboardManager.FireWeapon1.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(1, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(1, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon2.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(2, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(2, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon3.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(3, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(3, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon4.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(4, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(4, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon5.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(5, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(5, gameTime, PlayerShip);
                }



                if (KeyboardManager.FireMissile.IsBindTapped() || GamepadManager.FireMissile.IsBindTapped())
                {
                    playerShip.TryFireWeapon(gameTime, 0);
                    playerPilot.HoldingPosition = false;
                }

                if (KeyboardManager.SwitchMissile.IsBindTapped())//probably debug
                {
                    playerShip.MissileLauncher.SetMissileType(Debugging.MissileTypes.GetCurrentMoveNext());
                }


                #endregion
            }


            if (KeyboardManager.IsTapped(Keys.K))
            {
                PlayerShip.Kill();
            }


            if (KeyboardManager.IsTapped(Keys.R))
            {
                PlayerShip.Revive(10000, 10000);
            }
        }
Example #2
0
        public SettingsManager()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;

            ClientLogger.LogInfo("Base Path: " + path);
            try
            {
                if (!File.Exists(path + "settings.txt"))
                {
                    ClientLogger.LogInfo("Settings file not found, creating default");
                    // Writes settings file with base configuration.
                    var file = new StreamWriter(path + "settings.txt", false);
                    file.WriteLine("Settings File");
                    file.WriteLine("GraphicsWidth: 1024");
                    file.WriteLine("GraphicsHeight: 768");
                    file.WriteLine("Fullscreen: False");
                    file.WriteLine("Quality: High");
                    file.WriteLine("# Controls can be bound to custom keys here. Multiple keys are separated by commas.");
                    file.WriteLine("# Example: KeyBind ThrustUp = Up, W");
                    file.WriteLine("KeyBind: ThrustUp = Up, W");
                    file.Close();
                }
                var strings = File.ReadAllLines(path + "settings.txt");
                // Reads the whole file, returns each line as a string
                ClientLogger.LogInfo("Read " + strings.Count() + " lines");

                for (int i = 0; i < strings.Count(); i++)
                {
                    if (strings.Count() == 0)
                    {
                        continue;
                    }
                    ClientLogger.LogInfo("Line: " + strings[i]);

                    if (strings[i].StartsWith("#"))
                    {
                        continue;
                    }
                    else if (strings[i].StartsWith("GraphicsWidth: "))
                    {
                        string[] line = strings[i].Split(' ');
                        try
                        {
                            RenderingMath.WindowSizeX = int.Parse(line[1]);
                            GameWidth = int.Parse(line[1]);
                            RenderingMath.IsChanged = true;
                        }
                        catch
                        {
                            ClientLogger.Log(Log_Type.WARNING, "Invalid GraphicsWidth specified. Defaulting to 1024x768");
                            RenderingMath.WindowSizeX = 1366;
                            RenderingMath.WindowSizeY = 768;
                            RenderingMath.IsChanged   = true;
                        }
                    }
                    else if (strings[i].StartsWith("GraphicsHeight: "))
                    {
                        string[] line = strings[i].Split(' ');
                        try
                        {
                            RenderingMath.WindowSizeY = int.Parse(line[1]);
                            GameHeight = int.Parse(line[1]);
                            RenderingMath.IsChanged = true;
                        }
                        catch
                        {
                            ClientLogger.Log(Log_Type.WARNING, "Invalid GraphicsHeight specified. Defaulting to 1024x768");
                            RenderingMath.WindowSizeX = 1366;
                            RenderingMath.WindowSizeY = 768;
                            GameWidth  = 1366;
                            GameHeight = 768;
                            RenderingMath.IsChanged = true;
                        }
                    }
                    else if (strings[i].StartsWith("Fullscreen: "))
                    {
                        string[] line = strings[i].Split(' ');
                        try
                        {
                            if (bool.Parse(line[1]))
                            {
                                RenderingMath.Fullscreen = true;
                                Fullscreen = true;
                                RenderingMath.IsChanged = true;
                            }
                            else
                            {
                                RenderingMath.Fullscreen = false;
                                Fullscreen = false;
                                RenderingMath.IsChanged = true;
                            }
                        }
                        catch
                        {
                            ClientLogger.Log(Log_Type.WARNING, "Invalid Fullscreen boolean specified. Defaulting to Windowed");
                            RenderingMath.Fullscreen = false;
                            Fullscreen = false;
                            RenderingMath.IsChanged = true;
                        }
                    }
                    //else if (strings[i].StartsWith("ChatAlwaysFocus: "))
                    //{
                    //    string[] line = strings[i].Split(' ');
                    //    try
                    //    {
                    //        if (bool.Parse(line[1]))
                    //        {
                    //            _chatManager.chatAlwaysFocus = true;
                    //            ChatAlwaysFocus = true;
                    //        }
                    //        else
                    //        {
                    //            _chatManager.chatAlwaysFocus = false;
                    //            ChatAlwaysFocus = false;
                    //            RenderingMath.IsChanged = true;
                    //        }
                    //    }
                    //    catch
                    //    {
                    //        Logger.Log(Log_Type.WARNING, "Invalid Keyboard Focus boolean specified. Defaulting to false");
                    //        _chatManager.chatAlwaysFocus = false;
                    //        ChatAlwaysFocus = false;
                    //    }
                    //}
                    else if (strings[i].StartsWith("KeyBind: "))
                    {
                        KeyboardManager.CheckForKeyBind(strings[i]);
                    }
                }
            }
            catch
            {
                ClientLogger.Log(Log_Type.ERROR, "Couldn't find settings file, or write new one. " + path + "settings.txt");
                throw new FileLoadException("Couldn't find settings file, or write new one", path + "settings.txt");
            }
        }