Пример #1
0
        public Level(ContentManager GameContent, Game game, string LevelNameString, string LevelDirectory, string[] PlayerStrings, bool AllWeaponEnabled)
        {
            LevelName      = LevelNameString;
            EnabledWeapons = AllWeaponEnabled;

            Content = GameContent;
            Console.WriteLine("Initializing level");

            game.MainWindow.MouseEventButtonDownLeft  += new GameWindow.MouseEventHandler(PlayerManager.MouseClickDownLeft);
            game.MainWindow.MouseEventButtonUpLeft    += new GameWindow.MouseEventHandler(PlayerManager.MouseClickUpLeft);
            game.MainWindow.MouseEventButtonDownRight += new GameWindow.MouseEventHandler(PlayerManager.MouseClickDownRight);
            game.MainWindow.MouseEventButtonUpRight   += new GameWindow.MouseEventHandler(PlayerManager.MouseClickUpRight);
            game.MainWindow.MouseEventWheelUp         += new GameWindow.MouseEventHandler(PlayerManager.MouseWheelUp);
            game.MainWindow.MouseEventWheelDown       += new GameWindow.MouseEventHandler(PlayerManager.MouseWheelDown);

            ResourceManager.LoadResources(Content);
            LoadConfiguration(Path.Combine(LevelDirectory, LevelNameString));

            using (FileStream fileStream = new FileStream(Path.Combine(new string[] { LevelDirectory, LevelNameString, "Level" }) + ".png", FileMode.Open))
            {
                Ground = Texture2D.FromStream(game.GraphicsDevice, fileStream);
            }
            GroundData = new Color[Ground.Width * Ground.Height];
            Ground.GetData <Color>(GroundData);


            PlayerManager.Level = this;

            // Parse players
            foreach (var PlayerString in PlayerStrings)
            {
                if (string.IsNullOrEmpty(PlayerString))
                {
                    continue;
                }

                Player NewPlayer = new Player(PlayerManager);
                NewPlayer.Type = Player.PlayerType.Local;
                string[] Params = PlayerString.Substring(PlayerString.IndexOf('(') + 1, PlayerString.IndexOf(')') - PlayerString.IndexOf('(') - 1).Split(';');
                foreach (var Param in Params)
                {
                    if (Param.StartsWith("name="))
                    {
                        NewPlayer.Name = Param.Substring(Param.IndexOf('=') + 1);
                    }
                    else if (Param.StartsWith("color="))
                    {
                        string[] ColorString = Param.Substring(Param.IndexOf('=') + 1).Split(',');
                        NewPlayer.Color = new Microsoft.Xna.Framework.Color(int.Parse(ColorString[0]), int.Parse(ColorString[1]), int.Parse(ColorString[2]));
                    }
                    else if (Param.StartsWith("mouse="))
                    {
                        IntPtr MouseHandle = (IntPtr)int.Parse(Param.Substring(Param.IndexOf('=') + 1));

                        NewPlayer.LocalMouse = GameWindow.Instance.Mouses[MouseHandle];
                    }
                    else if (Param.StartsWith("keyboard="))
                    {
                        string KeyString = Param.Substring(Param.IndexOf('=') + 1);
                        if (KeyString.StartsWith("W"))
                        {
                            NewPlayer.LocalMoveLeft  = Keys.A;
                            NewPlayer.LocalMoveRight = Keys.D;
                            NewPlayer.LocalJump      = Keys.W;
                            NewPlayer.LocalShoot     = Keys.R;
                        }
                        else if (KeyString.StartsWith("Up"))
                        {
                            NewPlayer.LocalMoveLeft  = Keys.Left;
                            NewPlayer.LocalMoveRight = Keys.Right;
                            NewPlayer.LocalJump      = Keys.Up;
                            NewPlayer.LocalShoot     = Keys.Down;
                        }
                    }
                    else if (Param.StartsWith("weapons="))
                    {
                        // NYI
                    }
                }

                PlayerManager.AddPlayer(NewPlayer);
            }
        }
Пример #2
0
        public void LoadWeaponData(string DirectoryPath)
        {
            DirectoryInfo WeaponDirectory = new DirectoryInfo(DirectoryPath);

            foreach (var File in WeaponDirectory.EnumerateFiles("*.ini"))
            {
                const string WeaponSection = "Weapon";
                INIFile      WeaponFile    = new INIFile(File.FullName);

                WeaponData NewWeapon = new WeaponData();

                if (WeaponFile.TryLoading(WeaponSection, "ProjectileDamage"))
                {
                    NewWeapon.ProjectileDamage = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileForce"))
                {
                    NewWeapon.ProjectileForce = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileExplosionRadius"))
                {
                    NewWeapon.ProjectileExplosionRadius = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileMass"))
                {
                    NewWeapon.ProjectileMass = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileSpeed"))
                {
                    NewWeapon.ProjectileSpeed = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileLifeTime"))
                {
                    NewWeapon.ProjectileLifeTime = float.Parse(WeaponFile.LastLoadedData());
                }

                if (WeaponFile.TryLoading(WeaponSection, "ChargeTime"))
                {
                    NewWeapon.ChargeTime = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ChargeSpeedBonusStart"))
                {
                    NewWeapon.ChargeSpeedBonusStart = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ChargeDamageBonusStart"))
                {
                    NewWeapon.ChargeDamageBonusStart = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ChargeInaccuracyBonusUncharged"))
                {
                    NewWeapon.ChargeInaccuracyBonusUncharged = float.Parse(WeaponFile.LastLoadedData());
                }

                if (WeaponFile.TryLoading(WeaponSection, "SelfDamage"))
                {
                    NewWeapon.SelfDamage = bool.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "FirendlyFire"))
                {
                    NewWeapon.FirendlyFire = bool.Parse(WeaponFile.LastLoadedData());
                }


                if (WeaponFile.TryLoading(WeaponSection, "WeaponTexture"))
                {
                    NewWeapon.WeaponTexture = ResourceManager.GetTexture(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ProjectileTexture"))
                {
                    NewWeapon.ProjectileTexture = ResourceManager.GetTexture(WeaponFile.LastLoadedData());
                }

                if (WeaponFile.TryLoading(WeaponSection, "FireInterval"))
                {
                    NewWeapon.FireInterval = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "Recoil"))
                {
                    NewWeapon.Recoil = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "MagazineSize"))
                {
                    NewWeapon.MagazineSize = int.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "ReloadTime"))
                {
                    NewWeapon.ReloadTime = float.Parse(WeaponFile.LastLoadedData());
                }
                if (WeaponFile.TryLoading(WeaponSection, "Inaccuracy"))
                {
                    NewWeapon.Inaccuracy = float.Parse(WeaponFile.LastLoadedData());
                }

                NewWeapon.Name = File.Name.Substring(0, File.Name.LastIndexOf('.'));

                if (NewWeapon.WeaponTexture != null && NewWeapon.ProjectileTexture != null)
                {
                    Weapons.Add(NewWeapon.Name, NewWeapon);
                }
            }
        }