//This method deserializes a string and puts the information into the instance itself. public override void Deserialize(string info) { base.Deserialize(info); Points = Convert.ToInt32(JsonUtils.ExtractValue(info, "points")); foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(info, "orblist"))) { Orbs.Add(Convert.ToInt32(s)); } GamePowerup = new Powerup(); var strs = JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(info, "powerups")); for (int i = 0; i < Math.Min(strs.Count, 3); ++i) { switch (strs[i]) { case "ghost": GamePowerup.CurrentPowerups.Add(Powerup.powerups.ghost); GamePowerup.CarryingGhost = true; break; case "destabilize": GamePowerup.CurrentPowerups.Add(Powerup.powerups.destabilize); GamePowerup.CarryingDestabilize = true; break; case "neutralize": GamePowerup.CurrentPowerups.Add(Powerup.powerups.neutralize); GamePowerup.CarryingNeutralize = true; break; } } }
//This method usually spawns an orb. public void SpawnOrb() { double xc = Random.NextDouble() * 5000.0; double yc = Random.NextDouble() * 5000.0; if (!NearOtherObject(xc, yc)) { Orb orb = new Orb(xc, yc, Random.Next(6)); Orbs.Add(orb); GameObjects.Add(orb); } }