public override void Update(GameTime gameTime) { if (!Dead) { if (ShutDownTime > 0 || VirusTime > 0) { ShutDownTime = 0; VirusTime = 0; } else { SearchTime += gameTime.ElapsedGameTime.Milliseconds; if (SearchTime > PulseSearchTime) { SearchTime -= PulseSearchTime; bool Found = false; QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(MaxEngagementDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip s = (UnitShip)o; if (!s.Dead && !s.IsAlly(this) && Vector2.Distance(Position.get(), o.Position.get()) < MaxEngagementDistance) { if (s.CanBeTargeted() && s.SnapBounce()) { s.ShieldDamage = s.ShieldToughness + 1; s.LastDamager = this; s.FreezeTime = 1000; s.StunState = AttackType.Melee; s.SetSpeed(Vector2.Normalize(s.Position.get() - Position.get()) * 16); } PulseSearchTime += (int)(StartingMaxSearchTime / 100f * (1.5f + s.UnitLevel)); Found = true; } } } if (Found) { SoundManager.Play3DSound("PulseTurretFire", new Vector3(Position.X(), Y, Position.Y()), 0.75f, 800, 2); Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * MaxEngagementDistance / 1000f * 3, ParticleColor, 40, 5); } for (int i = 0; i < 2; i++) { FlareSystem.AddLightingPoint(Position3, new Vector3(0.3f), new Vector3(0, 0, 1), MaxEngagementDistance / 10, 40, 5, 10); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 6, 5); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 3, 4); } } } } } base.Update(gameTime); }
public override bool Trigger(PlayerShip p) { Vector3 Position3 = new Vector3(p.Position.X(), 0, p.Position.Y()); for (int i = 0; i < 10; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 2000, ParticleColor, 20, 5); } ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 4000, 5); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 400, 7); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 300, 7); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 500, 7); for (int i = 0; i < 2; i++) { FlamingChunkSystem.AddParticle(Position3, Rand.V3() / 1.5f, new Vector3(0, -0.25f, 0), Rand.V3(), Rand.V3() / 10, 150, 30, new Vector3(0.2f, 0.5f, 1), new Vector3(0.2f, 0.5f, 1), 0, 3); } ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(0.5f, 0.75f, 1), p.Size.X() * 50, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(0.5f, 0.75f, 1), 200, 5); } float MaxDist = 600; foreach (GameObject g in p.Parent2DScene.quadGrids.First.Value.Enumerate(p.Position.get(), new Vector2(MaxDist * 2))) { if (g.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip s = (UnitShip)g; if (Vector2.Distance(p.Position.get(), s.Position.get()) < MaxDist && s.IsAlly(p)) { s.InvTime = Math.Max(s.InvTime, (int)(10000)); } } } return(true); }
public override void Update(GameTime gameTime) { if (!Dead) { if (ShutDownTime > 0 || VirusTime > 0) { if (ShutDownTime > 0) { ShutDownTime -= gameTime.ElapsedGameTime.Milliseconds * 3; } else { Rotation.set(Rotation.get() + MathHelper.ToRadians(gameTime.ElapsedGameTime.Milliseconds * 20)); } } else { SearchTime += gameTime.ElapsedGameTime.Milliseconds; if (SearchTime > SnapSearchTime) { SearchTime -= SnapSearchTime; bool Found = false; QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(MaxEngagementDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip s = (UnitShip)o; if (!s.Dead && !s.IsAlly(this) && Vector2.Distance(Position.get(), o.Position.get()) < MaxEngagementDistance) { if (s.CanBeTargeted() && s.SnapBounce()) { s.EMP(this, IsUpdgraded ? 1 : 0); } SnapSearchTime += (int)(StartingMaxSearchTime / 20 * (1.5f + s.UnitLevel) / 2f); Found = true; } } } if (Found) { SoundManager.Play3DSound("SnapTurretFire", new Vector3(Position.X(), Y, Position.Y()), 0.75f, 800, 2); Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * MaxEngagementDistance / 1000f * 3, ParticleColor, 40, 5); } for (int i = 0; i < 2; i++) { FlareSystem.AddLightingPoint(Position3, new Vector3(0.3f), new Vector3(0, 0, 1), MaxEngagementDistance / 10, 40, 5, 10); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 6, 5); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 3, 4); } } } } } base.Update(gameTime); }
private void TestCollisions() { QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value; Vector2 UpperLeftCorner = Vector2.Zero; Vector2 LowerRightCorner = Vector2.Zero; if (SearchTime < MaxSearchTime) { UpperLeftCorner = Logic.Min(PreviousPosition, getPosition()); LowerRightCorner = Logic.Max(PreviousPosition, getPosition()); } else { SearchTime = 0; UpperLeftCorner = Logic.Min(PreviousPosition, getPosition() - BulletDodgeDistance); LowerRightCorner = Logic.Max(PreviousPosition, getPosition() + BulletDodgeDistance); } if (UpperLeftCorner.X < quadGrid.Min.X || UpperLeftCorner.Y < quadGrid.Min.Y || LowerRightCorner.X > quadGrid.Max.X || LowerRightCorner.Y > quadGrid.Max.Y) { return; } QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X); QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X); QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y); QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y); foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax)) { if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject))) { if (CheckCircle(g)) { BasicShipGameObject s = (BasicShipGameObject)g; s = s.ReturnCollision(); if (s != null && s.StopsBullet(ParentUnit)) { Collide(s); if (Destroyed) { return; } } } else if (g.GetType().IsSubclassOf(typeof(UnitShip))) { float d = Vector2.Distance(getPosition(), g.getPosition()); if (d < BulletDodgeDistance.X && d - Speed.Length() / 4 > Vector2.Distance(Position.get() + Speed, g.getPosition())) { UnitShip u = (UnitShip)g; if (u.BulletDodgeDistance > 0 && !u.IsAlly(ParentUnit)) { u.SetBulletToDodge(this); } } } } } }