public override void OnCollected(Player collectedBy) { level.Score += PointValue; int toHeal, toHealMax; if (!int.TryParse(Heal, out toHeal)) { if (Heal.EndsWith("%")) toHeal = level.Player.MaxHealth * int.Parse(Heal.Substring(0, Heal.Length - 1)) / 100; else throw new Exception("Cannot heal player - templating error."); } if (!int.TryParse(MaxHeal, out toHealMax)) { if (MaxHeal.EndsWith("%")) toHealMax = level.Player.MaxHealth * int.Parse(MaxHeal.Substring(0, MaxHeal.Length - 1)) / 100; else throw new Exception("Cannot heal player - templating error."); } if (toHeal < 0) level.Player.PoisonPlayer(toHeal, toHealMax); else level.Player.HealPlayer(toHeal, toHealMax); base.OnCollected(collectedBy); }
/// <summary> /// Called when this gem has been collected by a player and removed from the level. /// </summary> /// <param name="collectedBy"> /// The player who collected this gem. Although currently not used, this parameter would be /// useful for creating special powerup gems. For example, a gem could make the player invincible. /// </param> public virtual void OnCollected(Player collectedBy) { }
public override void OnCollected(Player collectedBy) { level.Score += PointValue; collectedSound.Play(); }
public void OnKilled(Player killedBy) { IsAlive = false; level.Score += PointsOnDeath; killedSound.Play(); }
/// <summary> /// Called when a item is collected. /// </summary> /// <param name="item">The item that was collected.</param> /// <param name="collectedBy">The player who collected this gem.</param> private void OnItemCollected(Item item, Player collectedBy) { item.OnCollected(collectedBy); }
private void OnEnemyKilled(Enemy enemy, Player killedBy) { enemy.OnKilled(killedBy); }
/// <summary> /// Iterates over every tile in the structure file and loads its /// appearance and behavior. This method also validates that the /// file is well-formed with a player start point, exit, etc. /// </summary> /// <param name="path"> /// The absolute path to the level file to be loaded. /// </param> private void LoadTiles(string path, int pHP, int pMaxHP) { // Load the level and ensure all of the lines are the same length. if (new FileInfo(path).Extension == ".xml") LoadXMLLevel("Worlds/" + path); else { #region PlaintextLoading LevelName = new FileInfo(path).Name.Replace(new FileInfo(path).Extension, ""); int width; List<string> lines = new List<string>(); using (StreamReader reader = new StreamReader("Worlds/" + path)) { defDest = reader.ReadLine().Trim(); string line = reader.ReadLine(); width = line.Length; while (line != null) { lines.Add(line); if (line.Length != width) throw new Exception(String.Format("The length of line {0} is different from all preceeding lines.", lines.Count)); line = reader.ReadLine(); } } // Allocate the tile grid. tiles = new Tile[width, lines.Count]; items = new List<Item>(); // Loop over every tile position, for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { // to load each tile. char tileType = lines[y][x]; tiles[x, y] = LoadTile(tileType, x, y); } } #endregion } if (start.Count == 0) throw new NotSupportedException("A level must have a starting point."); int max = 0; foreach (var pair in start) max += pair.Value; int chance = Content.Random.Next(max), current = 0; foreach (var pair in start) { current += pair.Value; if (chance < current) { chosenStart = pair.Key; break; } } player = new Player(this, chosenStart, pHP, pMaxHP); // Verify that the level has a beginning and an end. if (Player == null) throw new NotSupportedException("A level must have a starting point."); if (exits.Count == 0) throw new NotSupportedException("A level must have an exit."); }