public static SpawnPoint fromXML(XmlNode node)
 {
     SpawnPoint point = new SpawnPoint();
     point.fromNode = node;
     foreach (XmlNode itemChild in node)
         if (itemChild.Name.Equals("loc"))
         {
             string[] locStr = itemChild.FirstChild.Value.Split(',');
             point.loc = new Vector2(float.Parse(locStr[0]), float.Parse(locStr[1]));
         }
         else if (itemChild.Name.Equals("triggerLocation"))
         {
             string[] locStr = itemChild.FirstChild.Value.Split(',');
             point.triggerLocation = new Vector2(float.Parse(locStr[0]), float.Parse(locStr[1]));
         }
         else if (itemChild.Name.Equals("count"))
             point.count = uint.Parse(itemChild.FirstChild.Value);
         else if (itemChild.Name.Equals("bosses"))
             point.bosses = uint.Parse(itemChild.FirstChild.Value);
         else if (itemChild.Name.Equals("level"))
             point.level = uint.Parse(itemChild.FirstChild.Value);
         else if (itemChild.Name.Equals("width"))
             point.triggerWidth = uint.Parse(itemChild.FirstChild.Value);
         else if (itemChild.Name.Equals("type"))
             point.type = itemChild.FirstChild.Value;
     return point;
 }
Ejemplo n.º 2
0
 public void setGuiControls(SpawnPoint spawn)
 {
     enemyCountBox.Text = spawn.count.ToString();
     enemyTypeText.Text = spawn.type.ToString();
     enemyLevelTextfield.Text = spawn.level.ToString();
 }
Ejemplo n.º 3
0
 private void enemySpawnButton_Click(object sender, EventArgs e)
 {
     try
     {
         string[] locStr = enemyTriggerLocationTextbox.Text.Split(',');
         SpawnPoint spawn = new SpawnPoint();
         spawn.count = uint.Parse(enemyCountBox.Text);
         spawn.type = enemyTypeText.Text;
         spawn.level = uint.Parse(enemyLevelTextfield.Text);
         spawn.loc = gameref.currentLocation;
         spawn.triggerLocation = new Vector2(float.Parse(locStr[0]), float.Parse(locStr[1]));
         spawn.triggerWidth = uint.Parse(enemyTriggerWidthTextbox.Text);
         gameref.CurrentLevel.spawns.Add(spawn);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception from spawn point:\n" + ex.StackTrace);
     }
 }
Ejemplo n.º 4
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);
 }
 public SpawnPoint Clone()
 {
     return(SpawnPoint.fromXML(fromNode));
 }