Exemplo n.º 1
0
 public static BackgroundItemStruct fromXML(XmlElement element)
 {
     BackgroundItemStruct str = new BackgroundItemStruct();
     str.location = XMLUtil.fromXMLVector2(element.GetElementsByTagName("location")[0]);
     str.texturePath = element.GetElementsByTagName("path")[0].FirstChild.Value;
     str.rotation = element.GetAttribute("rotation") != "" ? float.Parse(element.GetAttribute("rotation")) : 0f;
     str.scale = element.GetAttribute("scale") == "" ? 1f : float.Parse(element.GetAttribute("scale"));
     return str;
 }
Exemplo n.º 2
0
        public static BackgroundItemStruct fromXML(XmlElement element)
        {
            BackgroundItemStruct str = new BackgroundItemStruct();

            str.location    = XMLUtil.fromXMLVector2(element.GetElementsByTagName("location")[0]);
            str.texturePath = element.GetElementsByTagName("path")[0].FirstChild.Value;
            str.rotation    = element.GetAttribute("rotation") != "" ? float.Parse(element.GetAttribute("rotation")) : 0f;
            str.scale       = element.GetAttribute("scale") == "" ? 1f : float.Parse(element.GetAttribute("scale"));
            return(str);
        }
Exemplo n.º 3
0
        public static Level fromXML(XmlElement node, Game gameref, String campaignPath)
        {
            Level newLvl = new Level();

            newLvl.number = int.Parse(node.GetElementsByTagName("number")[0].FirstChild.Value);
            if (node.HasAttribute("autoProgress"))
            {
                newLvl.autoProgress = bool.Parse(node.GetAttribute("autoProgress"));
            }
            newLvl.name = node.GetAttribute("name");
            foreach (string singleAdj in node.GetElementsByTagName("adj")[0].FirstChild.Value.Split(','))
            {
                newLvl.adjacent.Add(Int32.Parse(singleAdj));
            }
            XmlNodeList list = node.GetElementsByTagName("prereq");

            if (list.Count > 0 && list[0].FirstChild != null)
            {
                foreach (string singlePrereq in node.GetElementsByTagName("prereq")[0].FirstChild.Value.Split(','))
                {
                    newLvl.prereq.Add(Int32.Parse(singlePrereq));
                }
            }
            newLvl.loc = XMLUtil.fromXMLVector2(node.GetElementsByTagName("location")[0]);
            if (node.GetElementsByTagName("horizonPath").Count > 0)
            {
                newLvl.horizon = node.GetElementsByTagName("horizonPath")[0].FirstChild.Value;
            }
            if (node.GetElementsByTagName("items").Count > 0)
            {
                foreach (XmlElement item in node.GetElementsByTagName("items")[0].ChildNodes)
                {
                    newLvl.items.Add(GameItem.fromXML(item));
                }
            }
            if (node.GetElementsByTagName("spawns").Count > 0)
            {
                foreach (XmlElement item in node.GetElementsByTagName("spawns")[0].ChildNodes)
                {
                    newLvl.spawns.Add(SpawnPoint.fromXML(item));
                }
            }

            /*XmlNodeList storyNodes = node.GetElementsByTagName("story");
             * if (storyNodes.Count > 0 && storyNodes[0].ChildNodes.Count > 0)
             *  foreach (XmlNode item in storyNodes[0].ChildNodes)
             *      newLvl.storyElements.Add(StoryElement.fromXML(item, gameref));*/
            newLvl.levelLength = int.Parse(node.GetAttribute("length"));
            foreach (XmlElement graphic in node.GetElementsByTagName("graphic"))
            {
                newLvl.backgroundItems.Add(BackgroundItemStruct.fromXML(graphic));
            }
            return(newLvl);
        }
Exemplo n.º 4
0
 public void setGuiControls(BackgroundItemStruct backgroundItemStruct)
 {
     backgroundRotationText.Text = backgroundItemStruct.rotation.ToString();
     backgroundScaleField.Text = backgroundItemStruct.scale.ToString();
     backgroundTextureField.Text = backgroundItemStruct.texturePath;
 }
Exemplo n.º 5
0
 private void backgroundSpawnButton_Click(object sender, EventArgs e)
 {
     BackgroundItemStruct str = new BackgroundItemStruct();
     str.texturePath = backgroundTextureLabel.Text;
     str.location = gameref.currentLocation;
     str.rotation = float.Parse(backgroundRotationText.Text);
     str.scale = float.Parse(backgroundScaleField.Text);
     gameref.CurrentLevel.backgroundItems.Add(str);
 }
Exemplo n.º 6
0
 /// <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)
 {
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
         this.Exit();
     switch (currentState)
     {
         #region Leveleditor
         case Enums.State.Leveleditor:
             Vector2 currentLocation = new Vector2(Mouse.GetState().X + offset.X, resolution.ScreenHeight - (Mouse.GetState().Y + offset.Y));
             #region Moving gameitem
             if (ButtonState.Pressed == Mouse.GetState().LeftButton &&
                 ButtonState.Pressed != previousMouseState.LeftButton &&
                 Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
             {
                 this.currentLocation = currentLocation;
                 control.updateCurrentPositionLabel();
                 if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                     movingItem = CurrentLevel.getGameItemAtLocation(currentLocation.X, currentLocation.Y);
                 else if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                     movingSpawn = CurrentLevel.getSpawnAtLocation(currentLocation.X, currentLocation.Y, this);
                 else if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                 {
                     BackgroundItemStruct? str = CurrentLevel.getBackgroundItemAtLocation(currentLocation.X, currentLocation.Y, this);
                     if(str.HasValue)
                         movingBackgroundItem = str.Value;
                 }
             }
             if (ButtonState.Pressed == Mouse.GetState().LeftButton &&
                 Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
             {
                 if (movingItem != null)             movingItem.loc = currentLocation;
                 if (movingSpawn != null)            movingSpawn.loc = currentLocation;
                 movingBackgroundItem.location = currentLocation;
             }
             if (ButtonState.Pressed != Mouse.GetState().LeftButton &&
                 ButtonState.Pressed == previousMouseState.LeftButton &&
                 Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
             {
                 movingItem = null;
                 movingSpawn = null;
             }
             #endregion
             #region Remove level item
             if (ButtonState.Pressed == Mouse.GetState().RightButton &&
                 ButtonState.Pressed != previousMouseState.RightButton &&
                 Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
             {
                 if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                 {
                     GameItem item = CurrentLevel.getGameItemAtLocation(currentLocation.X, currentLocation.Y);
                     if (item != null)
                     {
                         CurrentLevel.items.Remove(item);
                         control.setGuiControls(item);
                     }
                 }
                 if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                 {
                     SpawnPoint spawn = CurrentLevel.getSpawnAtLocation(currentLocation.X, currentLocation.Y, this);
                     if (spawn != null)
                     {
                         CurrentLevel.spawns.Remove(spawn);
                         control.setGuiControls(spawn);
                     }
                 }
                 if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                 {
                     BackgroundItemStruct? str = CurrentLevel.getBackgroundItemAtLocation(currentLocation.X, currentLocation.Y, this);
                     if (str.HasValue)
                     {
                         CurrentLevel.backgroundItems.Remove(str.Value);
                         control.setGuiControls(str.Value);
                     }
                 }
             }
             #endregion
             break;
         #endregion
         #region Worldeditor
         case Enums.State.Worldeditor:
             //if clicked on a level, choose that, otherwise make a new one
             Vector2 point = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
             int indexOfClosestLevel = -1;
             float distance = float.MaxValue;
             foreach (Level level in levels)
             {
                 float newdistance = Vector2.Distance(level.loc, point);
                 if (newdistance < distance)
                 {
                     distance = newdistance;
                     indexOfClosestLevel = level.number;
                 }
             }
             if (ButtonState.Pressed == Mouse.GetState().LeftButton &&
                 ButtonState.Pressed != previousMouseState.LeftButton &&
                 Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
             {
                 if (distance < DISTANCE_FOR_SELECTION)
                 {
                     control.setLevelInfo(levels[indexOfClosestLevel].loc.X, levels[indexOfClosestLevel].loc.Y,
                         levels[indexOfClosestLevel].adjacent, levels[indexOfClosestLevel].prereq,
                         levels[indexOfClosestLevel].name, levels[indexOfClosestLevel].number,
                         levels[indexOfClosestLevel].autoProgress);
                     if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                     {
                         levels.RemoveAt(indexOfClosestLevel);
                         foreach (Level level in levels)
                         {
                             if (level.number >= indexOfClosestLevel)
                                 --level.number;
                             for (int i = 0; i < level.adjacent.Count; i++)
                                 if (level.adjacent[i] == indexOfClosestLevel)
                                     level.adjacent.RemoveAt(i);
                         }
                         selectedLevelIndex = 0;
                     }
                     else if (selectedLevelIndex == indexOfClosestLevel)
                         switchState();
                     else
                         selectedLevelIndex = indexOfClosestLevel;
                 }
                 else
                     addLevel();
             }
             break;
         #endregion
     }
     previousMouseState = Mouse.GetState();
     base.Update(gameTime);
 }