//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; } } }
//Sets TargetWell to the nearest well that is requesting a color orb currently being carried public void TargetNearestWell() { Well closestWell = null; double xDist; double yDist; double dist; double compareDist = 5000 * Math.Sqrt(2); foreach (Well well in ParentGame.StableWells) { xDist = well.Xcoor - this.Xcoor; yDist = well.Ycoor - this.Ycoor; dist = Math.Sqrt(Math.Pow(xDist, 2) + Math.Pow(yDist, 2)); if (dist < compareDist) { if (Orbs.Contains(well.Orbs) && !well.IsGhost) { closestWell = well; compareDist = dist; } } } if (closestWell == null) { Orbs.Clear(); } else { TargetWell = closestWell; } }
public override int GetHashCode() { int hash = 17; hash = 31 * hash + Orbs.GetHashCode(); hash = 31 * hash + Enhancements.GetHashCode(); return(hash); }
//This method updates the player's position and what orbs it has. public void UpdatePlayer() { if (!IsCheat) { UpdateGravity(Player); } Player.Move(HorizontalInput, VerticalInput); Well well = Player.WellOver(); if (well != null) { int originalColor = well.Orbs; if (!well.IsStable) { if (!IsCheat && !Player.IsImmune) { IsOver = true; Timer.Stop(); } } else if (Player.DepositOrbs(well)) { int objIndex = StableWells.FindIndex(item => item.Equals(well)); UpdateAnimationEvent(this, new AnimationEventArgs(false, AnimationType.Stable, objIndex, 12, 0)); StableWells.Remove(well); GameObjects.Remove(well); Player.GamePowerup.AddNew(); Points += 100; } else if (well.Orbs != originalColor) { GameInvokeSoundEvent(this, SoundEffect.OrbDrop); int objIndex = StableWells.FindIndex(item => item.Equals(well)); UpdateAnimationEvent(this, new AnimationEventArgs(true, AnimationType.Stable, objIndex, well.Orbs, 6 + well.Orbs)); } } Orb orb = Player.OrbOver(); if (orb != null) { if (Player.Orbs.Count < 5) { Orbs.Remove(orb); GameObjects.Remove(orb); Player.Orbs.Add(orb.Color); Player.Orbs.Sort(); GameInvokeSoundEvent(this, SoundEffect.OrbGrab); } } if (Player.ImmuneTicksLeft > 0) { --Player.ImmuneTicksLeft; } if (Player.ImmuneTicksLeft == 0) { Player.IsImmune = false; } }
//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); } }
//Updates AI position and collected orbs public void UpdateAI() { foreach (AIShip aI in AIShips.ToList()) { UpdateGravity(aI); aI.AIMove(); Well well = aI.WellOver(); if (well != null) { int originalColor = well.Orbs; if (!well.IsStable) { if (well.IsTrap && well.Owner == Player) { Points += 200; } int objIndex = AIShips.FindIndex(item => item.Equals(aI)); UpdateAnimationEvent(this, new AnimationEventArgs(false, AnimationType.AI, objIndex, 8, 0)); AIShips.Remove(aI); GameObjects.Remove(aI); } else if (aI.DepositOrbs(well)) { int objIndex = StableWells.FindIndex(item => item.Equals(well)); UpdateAnimationEvent(this, new AnimationEventArgs(false, AnimationType.Stable, objIndex, 12, 0)); StableWells.Remove(well); GameObjects.Remove(well); aI.GamePowerup.AddNew(); aI.SetTargetPos(); } else if (well.Orbs != originalColor) { int objIndex = StableWells.FindIndex(item => item.Equals(well)); UpdateAnimationEvent(this, new AnimationEventArgs(true, AnimationType.Stable, objIndex, well.Orbs, 6 + well.Orbs)); } } Orb orb = aI.OrbOver(); if (orb != null) { if (aI.Orbs.Count < 5) { Orbs.Remove(orb); GameObjects.Remove(orb); aI.Orbs.Add(orb.Color); aI.Orbs.Sort(); aI.SetTargetPos(); } } aI.UseNeutralize(); aI.UseDestabilize(); aI.UseGhost(); } }
//This method gives the ship a speed boost. public void SpeedBoost() { if (Orbs.Count >= 3) { // InvokeSoundEventForShip(this, SoundEffect.Boost); for (int i = 0; i < 3; ++i) { int orbIndex = rand.Next(Orbs.Count); Orbs.RemoveAt(orbIndex); } BoostFactor += 2.0; } }
//This method gives the ship a speed boost. public void SpeedBoost() { if (Orbs.Count >= 3) { if (ParentGame.Player == this) { GameInvokeSoundEvent(this, SoundEffect.Boost); } for (int i = 0; i < 3; ++i) { int orbIndex = rand.Next(Orbs.Count); Orbs.RemoveAt(orbIndex); } BoostFactor += 2.0; } }
//This method updates the player's position and what orbs it has. public void UpdatePlayer(Ship Player) { UpdateGravity(Player); Player.Move(); Well well = Player.WellOver(); if (well != null) { int originalColor = well.Orbs; if (!well.IsStable) { if (!Player.IsImmune) { Player.Die(); } } else if (Player.DepositOrbs(well)) { StableWells.Remove(well); GameObjects.Remove(well); Player.GamePowerup.AddNew(); Player.Points += 100; } } Orb orb = Player.OrbOver(); if (orb != null) { if (Player.Orbs.Count < 5) { Orbs.Remove(orb); GameObjects.Remove(orb); Player.Orbs.Add(orb.Color); Player.Orbs.Sort(); } } if (Player.ImmuneTicksLeft > 0) { --Player.ImmuneTicksLeft; } if (Player.ImmuneTicksLeft == 0) { Player.IsImmune = false; } }
//Updates AI position and collected orbs public void UpdateAI() { foreach (AIShip aI in AIShips.ToList()) { UpdateGravity(aI); aI.AIMove(); Well well = aI.WellOver(); if (well != null) { if (!well.IsStable) { if (well.IsTrap) { well.PlayerWhoSetTrap.Points += 200; } AIShips.Remove(aI); GameObjects.Remove(aI); } else if (aI.DepositOrbs(well) && !well.IsGhost) { StableWells.Remove(well); GameObjects.Remove(well); aI.GamePowerup.AddNew(); aI.SetTargetPos(); } } Orb orb = aI.OrbOver(); if (orb != null) { if (aI.Orbs.Count < 5) { Orbs.Remove(orb); GameObjects.Remove(orb); aI.Orbs.Add(orb.Color); aI.Orbs.Sort(); aI.SetTargetPos(); } } aI.UseNeutralize(); aI.UseDestabilize(); aI.UseGhost(); } }
//This method deposits all of the orbs it can into a given well. public bool DepositOrbs(Well well) { bool completed = false; foreach (int orb in Orbs.ToList()) { if (orb == well.Orbs) { if (well.Orbs == 5) { completed = true; } else { well.Orbs++; } IncrementScore(); Orbs.Remove(orb); well.TicksLeft = ParentGame.WellDestabFreq; } } return(completed); }
//This method deposits all of the orbs it can into a given well. public bool DepositOrbs(Well well) { bool completed = false; foreach (int orb in Orbs.ToList()) { if (orb == well.Orbs && (!well.IsGhost || this == well.Owner)) { if (well.Orbs == 5) { completed = true; } well.Orbs++; IncrementScore(); Orbs.Remove(orb); well.TicksLeft = ParentGame.WellDestabFreq; } } if (well.Orbs == 6) { well.Orbs = 5; } return(completed); }
public override void Update() { // Change particle colours Color newColour; // Exhaust/explosion colour switch (GM.instance.rnd.Next(3)) { case 1: newColour = Color.Orange; break; case 2: newColour = Color.OrangeRed; break; default: newColour = Color.Red; break; } GM.instance.ParticleBases["exhaust"].Colour = newColour; // Accretion disk colour switch (GM.instance.rnd.Next(6)) { case 1: newColour = Color.BlueViolet; break; case 2: newColour = Color.Red; break; case 3: newColour = Color.Purple; break; case 4: newColour = Color.PaleVioletRed; break; case 5: newColour = Color.Blue; break; default: newColour = Color.Purple; break; } GM.instance.ParticleBases["accretion"].Colour = newColour; // Update system objects foreach (GameObject obj in Objs) { obj.Update(); } // Add queued objects to world UnqueueObjects(); // Decay everything for (int i = Decayables.Count - 1; i > -1; i--) { if (Decayables[i].TTL < 0) { var remove = Decayables[i]; if (remove.Equals(Shoot)) { Shoot = null; } Decayables.RemoveAt(i); Objs.Remove(remove as GameObject); } else { break; } } // Attract to star Star.Attract(User as IGravitable); // Check collisions if (Shoot != null) { for (int i = Orbs.Count - 1; i > -1; i--) { if ((Shoot.Pos - Orbs[i].Pos).Length() < 50) { Orbs[i].Explode(); Objs.Remove(Orbs[i] as GameObject); Orbs.RemoveAt(i); Objs.Remove(Shoot); Shoot = null; break; } } } }