コード例 #1
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
 public void DeletePlanet(Planet planet)
 {
     if (planet == null)
         return;
     if (defaultConnection != null && !defaultConnection.Dead)
     {
         string Command = string.Format("+DELETE {0}\n",planet.ID);
         defaultConnection.Write(Command);
     }
     lock (Planets)
     {
         Planets.Remove(planet);
         SelectionChanged(this, EventArgs.Empty);
     }
 }
コード例 #2
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
        private IEnumerable<Planet> LoadMap(string map)
        {
            Chance = MathHelper.Lerp(0.1f,0.6f,(float)rnd.NextDouble());
            List<Planet> mapPlanets = new List<Planet>();
            XmlReader xmlReader = XmlReader.Create(map);
            xmlReader.ReadStartElement();

            //xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Width");
            int Width = xmlReader.ReadContentAsInt();

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Height");
            int Height = xmlReader.ReadContentAsInt();

            MapWidth = Width;
            MapHeight = Height;
            RefreshLine();
            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("Format");
            int Format = xmlReader.ReadContentAsInt();

            xmlReader.Read();
            xmlReader.MoveToElement();
            xmlReader.ReadStartElement("HasScript");
            bool HasScript = xmlReader.ReadContentAsBoolean();
            if (HasScript)
            {
                xmlReader.ReadToFollowing("Script");
                while (xmlReader.Read())
                {
                    if (xmlReader.LocalName == "Script" && !xmlReader.IsStartElement())
                    {
                        break;
                    }
                }
            }
            while (xmlReader.Read())
            {
                /*Read planet header*/
                if (xmlReader.LocalName == "Planet" && xmlReader.IsStartElement())
                {
                    /*Read the ID element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("ID");
                    int ID = xmlReader.ReadContentAsInt();

                    /*Read the owner element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Owner");
                    string owner = xmlReader.ReadContentAsString();

                    /*Read the forces element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Forces");
                    int forces = xmlReader.ReadContentAsInt();

                    /*Read the growth element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Growth");
                    int growth = xmlReader.ReadContentAsInt();

                    /*Read the growth cooldown element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("GrowthCooldown");
                    int growthcd = xmlReader.ReadContentAsInt();

                    /*Read the size element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Size");
                    float size = xmlReader.ReadContentAsFloat();

                    /*Read the people element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("HasPeople");
                    bool hasppl = xmlReader.ReadContentAsBoolean();

                    /*Read the Position element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Position");
                    Microsoft.Xna.Framework.Vector2 Position = new Microsoft.Xna.Framework.Vector2();

                    /*Read the X element*/
                    //xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("X");
                    Position.X = xmlReader.ReadContentAsInt();

                    /*Read the Y element*/
                    xmlReader.Read();
                    xmlReader.MoveToElement();
                    xmlReader.ReadStartElement("Y");
                    Position.Y = xmlReader.ReadContentAsInt();

                    Planet p = new Planet();
                    p.ID = ID;
                    p.Position = Position;
                    p.Growth = growth;
                    p.GrowthCounter = growthcd;
                    p.Owner = (PlayerType)Enum.Parse(typeof(PlayerType), owner, false);
                    p.Forces = forces;
                    p.PlanetSize = size;
                    p.HasPeople = hasppl;
                    if (defaultConnection != null && !defaultConnection.Dead)
                    {
                        string Command = string.Format("+ADD {0} {1} {2} {3} {4} {5} {6} {7}\n", p.ID, p.Position.X, p.Position.Y, p.PlanetSize, p.Forces, (int)p.Owner, p.GrowthCounter, p.Growth);
                        defaultConnection.Write(Command);
                    }
                    mapPlanets.Add(p);
                }

            }
            xmlReader.Close();
            xmlReader = null;
            return mapPlanets;
        }
コード例 #3
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            remoteWorker.Heartbeat();
            MouseState NewState = Mouse.GetState();
            Vector2 MousePosition=new Vector2(NewState.X,NewState.Y)/Camera.Zoom-new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2)+Camera.Position;
            if (NewState.LeftButton == ButtonState.Pressed && OldState.LeftButton == ButtonState.Released)
            {
                lock (Planets)
                {
                    List<Planet> Selections = new List<Planet>(from P in Planets where (Vector2.Distance(P.Position, MousePosition) <= 64 * P.PlanetSize) orderby Vector2.Distance(P.Position, MousePosition) ascending select P);

                    if (Selections.Count > 0)
                    {
                        Selected = Selections[0];
                        SelectionChanged(this, EventArgs.Empty);
                    }
                }
            }
            else if (NewState.LeftButton == ButtonState.Pressed && OldState.LeftButton == ButtonState.Pressed)
            {
                if (Selected != null)
                {
                    Selected.Position = MousePosition;
                    if (defaultConnection != null && !defaultConnection.Dead)
                    {
                        string Command = string.Format("+UPDATE {0} {1} {2} {3} {4} {5} {6} {7}\n", Selected.ID, Selected.Position.X, Selected.Position.Y, Selected.PlanetSize, Selected.Forces, (int)Selected.Owner, Selected.GrowthCounter, Selected.Growth);
                        defaultConnection.Write(Command);
                    }
                }
            }
            else if(NewState.LeftButton==ButtonState.Released && OldState.LeftButton==ButtonState.Pressed)
            {
                if (Selected != null)
                {
                    if (defaultConnection != null && !defaultConnection.Dead)
                    {
                        string Command = string.Format("+UPDATE {0} {1} {2} {3} {4} {5} {6} {7}\n", Selected.ID, Selected.Position.X, Selected.Position.Y, Selected.PlanetSize, Selected.Forces, (int)Selected.Owner, Selected.GrowthCounter, Selected.Growth);
                        defaultConnection.Write(Command);
                    }
                }
                Selected=null;
            }
            if (NewState.RightButton == ButtonState.Pressed)
            {
                Camera.Position +=  new Vector2(OldState.X, OldState.Y)-new Vector2(NewState.X, NewState.Y);
            }
            OldState = NewState;

            base.Update(gameTime);
        }
コード例 #4
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
 public void ReflectVerticaly()
 {
     List<Planet> NewPlanets = new List<Planet>();
     foreach (Planet planet in Planets)
     {
         Planet newPlanet = new Planet();
         newPlanet.Position = new Vector2(MapWidth - planet.Position.X, planet.Position.Y);
         newPlanet.PlanetSize = planet.PlanetSize;
         newPlanet.ID = ++NextID;
         newPlanet.Owner = planet.Owner;
         if (defaultConnection != null && !defaultConnection.Dead)
         {
             string Command = string.Format("+ADD {0} {1} {2} {3} {4} {5} {6} {7}\n", newPlanet.ID, newPlanet.Position.X, newPlanet.Position.Y, newPlanet.PlanetSize, newPlanet.Forces, (int)newPlanet.Owner, newPlanet.GrowthCounter, newPlanet.Growth);
             defaultConnection.Write(Command);
         }
         NewPlanets.Add(newPlanet);
     }
     lock (Planets)
     {
         Planets.AddRange(NewPlanets);
     }
 }
コード例 #5
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
        public void RandomizePlanet(Planet planet)
        {
            int type = rnd.Next(3);
            planet.PlanetSize = type == 0 ? 0.5f : type == 1 ? 0.7f : 1f;
            planet.PlanetSize += MathHelper.Lerp(-0.1f,0.1f,(float)rnd.NextDouble());
            switch (type)
            {
                case 0:
                    planet.Forces = (int)(rnd.Next(0, 6) - 3 + 8);
                    planet.Growth = 1;
                    planet.GrowthCounter = 30;
                    break;
                case 1:
                    planet.Forces = (int)(rnd.Next(0, 6) - 3 + 15);
                    planet.Growth = 4;
                    planet.GrowthCounter = 40;
                    break;
                case 2:
                    planet.Forces = (int)(rnd.Next(0, 6) - 3 + 20);
                    planet.Growth = 6;
                    planet.GrowthCounter = 50;
                    break;
            }

            if (rnd.NextDouble() < Chance)
            {
                planet.HasPeople = true;
            }
        }
コード例 #6
0
ファイル: EditorBase.cs プロジェクト: Nessphoro/VelesConflict
 public void NewPlanet()
 {
     Planet newPlanet = new Planet();
     newPlanet.Position = Vector2.Zero;
     newPlanet.PlanetSize = 1f;
     newPlanet.ID = ++NextID;
     newPlanet.Owner = PlayerType.Neutral;
     RandomizePlanet(newPlanet);
     if (defaultConnection != null && !defaultConnection.Dead)
     {
         string Command = string.Format("+ADD {0} {1} {2} {3} {4} {5} {6} {7}\n", newPlanet.ID, newPlanet.Position.X, newPlanet.Position.Y, newPlanet.PlanetSize, newPlanet.Forces, (int)newPlanet.Owner, newPlanet.GrowthCounter, newPlanet.Growth);
         defaultConnection.Write(Command);
     }
     lock (Planets)
         Planets.Add(newPlanet);
 }