public override void Update(GameTime gameTime) { frame.WorldMatrix = WorldMatrix; if (UnitCount > 0 && !Dead && WaveFSM.WaveStepState.WeaponsFree) { UnitDelay += gameTime.ElapsedGameTime.Milliseconds; if (UnitDelay > MaxUnitDelay) { UnitCount--; UnitDelay -= MaxUnitDelay; UnitShip s = (UnitShip)SpawnCard.GetUnit(FactionNumber); ParentLevel.AddObject(s); s.SetLevel((IsUpdgraded ? 3 : 2) * WaveManager.DifficultyMult, 1); if (GetTeam() == WaveManager.ActiveTeam) { float Theta = 0; float Offset = 0; Vector3 Position3 = new Vector3(Position.X(), Y, Position.Y()); while (!TestFree(Position.get(), Theta, Offset, Size.X())) { Theta += (float)Math.PI / 10f; if (Theta > Math.PI * 2) { Theta -= (float)Math.PI * 2; Offset += Size.X() / 2; } } Vector2 BestPosition = Position.get() + Logic.ToVector2(Theta) * Offset; s.Position.set(BestPosition); Position3 = new Vector3(BestPosition.X, 0, BestPosition.Y); for (int j = 0; j < 30; j++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } Position3 = new Vector3(Position.X(), 0, Position.Y()); ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(1, 0.75f, 0.5f), Size.X() * 5, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } } else { s.Position.set(NeutralManager.GetSpawnPosition()); } } } base.Update(gameTime); }
private void SpawnUnit(UnitShip s) { ParentLevel.AddObject(s); s.SetLevel(1, 1); PlaceRotationMult += PlaceRotationMultChange; if (PlaceRotationMult > 1) { PlaceRotationMult -= 1; } s.Position.set(Position.get() + Logic.ToVector2(PlaceRotationMult * PlaceRotation) * (Size.X() + s.Size.X()) / 1.95f); }
private void SummonUnits() { if (!CanSummon) { return; } Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); CanSummon = false; HasSummoned = true; float Theta = 0; float Offset = Size.X() * 2; for (int i = 0; i < SummonCard.GhostCount; i++) { UnitShip u = (UnitShip)SummonCard.GetUnit(FactionNumber); ParentLevel.AddObject(u); while (!TestFree(Position.get(), Theta, Offset, Size.X())) { Theta += (float)Math.PI / 10f; if (Theta > Math.PI * 2) { Theta -= (float)Math.PI * 2; Offset += Size.X(); } } Vector2 BestPosition = Logic.ToVector2(Theta) * Offset + Position.get(); u.SetForGhost(); u.SetLevel(UnitLevel, 1); u.Position.set(BestPosition); Position3 = new Vector3(BestPosition.X, 0, BestPosition.Y); for (int j = 0; j < 30; j++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } } Position3 = new Vector3(Position.X(), 0, Position.Y()); ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(1, 0.75f, 0.5f), Size.X() * 5, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } }
private void Activate() { if (!WaveStepState.WeaponsFree) { return; } FactionManager.AddEnergy(ParentShip.FactionNumber, -150); Vector3 Position3 = new Vector3(ParentShip.Position.X(), 0, ParentShip.Position.Y()); float Theta = 0; float Offset = ParentShip.Size.X() * 2; FactionManager.Factions[ParentShip.FactionNumber].roundReport.UnitsSpawned += MyCard.GhostCount; for (int i = 0; i < MyCard.GhostCount; i++) { UnitShip u = (UnitShip)MyCard.GetUnit(ParentShip.FactionNumber); ParentShip.ParentLevel.AddObject(u); while (!ParentShip.TestFree(ParentShip.Position.get(), Theta, Offset, ParentShip.Size.X())) { Theta += (float)Math.PI / 10f; if (Theta > Math.PI * 2) { Theta -= (float)Math.PI * 2; Offset += ParentShip.Size.X(); } } Vector2 BestPosition = Logic.ToVector2(Theta) * Offset + ParentShip.Position.get(); u.SetForGhost(); u.Position.set(BestPosition); u.SetLevel(WaveManager.CurrentWave / 5f * WaveCard.LevelMult, 1); Position3 = new Vector3(BestPosition.X, 0, BestPosition.Y); for (int j = 0; j < 30; j++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } } ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(1, 0.75f, 0.5f), ParentShip.Size.X() * 5, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(1, 0.75f, 0.5f), 20, 5); } }
public virtual void Fire(float DirectionR) { if (ParentUnit == null) { return; } if (ReloadTime <= 0) { bool CreatedMatrix = false; Matrix RotationMatrix = Matrix.Identity; SoundManager.Play3DSound(FireSound, new Vector3(ParentUnit.Position.X(), ParentUnit.Y, ParentUnit.Position.Y()), FireVolume, FireDistance, FireExponent); if (!CreatedMatrix) { CreatedMatrix = true; RotationMatrix = Matrix.CreateRotationZ(DirectionR); } ROF -= MaxROF; BurstTime = 0; ClipSize--; BurstSize--; if (Ammo > 0) { Ammo--; } for (int i = 0; i < BulletCount; i++) { Bullet b = getBullet(); ParentUnit.ParentLevel.AddObject(b); b.SetShipParent(ParentUnit); b.SetPosition(ParentUnit.Position.get() + Vector2.Transform(getPositionPattern(i), RotationMatrix), false); b.SetSpeed(BulletSpeed * Logic.ToVector2(DirectionR + Accuracy - Rand.F() * Accuracy * 2 + getDirectionPattern(i))); b.SetAttackType(attackType); b.SetStartingPosition(b.getPosition()); b.SetDamage(Damage, PushTime, PushVelocityMult); b.SetModifierFactor(ModifierFactor); b.SetLifeTime(LifeTime); b.SetExplosive(BulletExplosionDistance, BulletExplosionDamage); //b.AddTime(ROF); } } }
public override void Update(GameTime gameTime) { int Mult = 4; Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, 60 * Mult, 1); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (70 + Rand.F() * 70) * Mult, 1); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (10 + Rand.F() * 20) * Mult, 2); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (10 + Rand.F() * 20) * Mult, 0); FlareSystem.AddLightning(Position3, ParticleColor2, 4, 20, 4, 10); SearchTime += gameTime.ElapsedGameTime.Milliseconds; if (SearchTime > MaxSearchTime || (AttackTarget != null && !AttackTarget.CanBeTargeted())) { SearchTime -= MaxSearchTime; AttackTarget = null; float BestDistance = SearchDistance; QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(SearchDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitBasic s = (UnitBasic)o; if (s.CanBeTargeted() && !s.IsAlly(ParentUnit)) { float d = Vector2.Distance(Position.get(), o.Position.get()); if (d < BestDistance && !o.GetType().Equals(typeof(CrystalWall))) { BestDistance = d; AttackTarget = s; } } } } } if (AttackTarget != null) { Speed = Logic.ToVector2(Logic.Clerp(Logic.ToAngle(Speed), Logic.ToAngle(AttackTarget.Position.get() - Position.get()), TurnSpeed * gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f)) * SpeedL; } base.Update(gameTime); }
public bool TestFree(Vector2 Position, float Angle, float Offset, float Size) { QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Logic.ToVector2(Angle) * Offset, new Vector2(Size * 2))) { if (o.GetType().IsSubclassOf(typeof(BasicShipGameObject))) { BasicShipGameObject s = (BasicShipGameObject)o; if (Vector2.Distance(Logic.ToVector2(Angle) * Offset, o.Position.get()) < (Size + o.Size.X()) / 2) { return(false); } } } return(true); }
public override void Trigger() { if (RechargeTime >= MaxRechargeTime) { RechargeTime = 0; WindowMissileBullet b = new WindowMissileBullet(); ParentShip.ParentLevel.AddObject(b); b.SetShipParent(ParentShip); b.SetPosition(ParentShip.getPosition()); b.SetStartingPosition(b.getPosition()); b.SetSpeed(BulletStartSpeed * Logic.ToVector2(Logic.ToAngle(ParentShip.AdjustedAimPointer - ParentShip.getPosition()))); b.SetDamage(BulletDamage, BulletPushTime, BulletVelocityMult); b.SetAttackType(AttackType.Blue); b.SetModifierFactor(1); b.SetLifeTime(BulletLifeTime); b.SetExplosive(ExplosionDistance, ExplosionDamage); } base.Trigger(); }
public void Accelerate(GameTime gameTime, Vector2 Amount) { Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), Logic.ToAngle(Amount), RotationSpeed * gameTime.ElapsedGameTime.Milliseconds * 60.0f / 1000.0f))); SetSpeed(Logic.ToVector2(Rotation.getAsRadians()) * Acceleration * 5 * (FieldStateTime > 0 ? fieldState == FieldState.SpeedBoost ? 1.25f : 0.33f : 1)); RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z); }
public virtual void Fire(GameTime gameTime) { if (ReloadTime <= 0) { bool CreatedMatrix = false; Matrix RotationMatrix = Matrix.Identity; ChargeTime += gameTime.ElapsedGameTime.Milliseconds; if (ChargeTime > MaxChargeTime) { while (ROF >= MaxROF && ClipSize > 0 && BurstSize > 0 && (Ammo > 0 || Ammo == -100)) { Vector3 P = Parent != null ? new Vector3(Parent.getParent().Position.X(), 0, Parent.getParent().Position.Y()) : new Vector3(ParentUnit.Position.X(), 0, ParentUnit.Position.Y()); SoundManager.Play3DSound(FireSound, P, FireVolume, FireDistance, FireExponent); ChargeTime = 0; if (!CreatedMatrix) { CreatedMatrix = true; if (Parent != null) { RotationMatrix = Matrix.CreateRotationZ(-Parent.getRotation()); } else if (ParentUnit.Guns != null) { RotationMatrix = Matrix.CreateRotationZ(-ParentUnit.Guns[0].getRotation()); } } ROF -= MaxROF; BurstTime = 0; ClipSize--; BurstSize--; if (Ammo > 0) { Ammo--; } for (int i = 0; i < BulletCount; i++) { Bullet b = getBullet(); if (Parent != null) { if (Parent.getParent().GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip s = (UnitShip)Parent.getParent(); if (s.IsHuge) { b.Big = true; } } Parent.getParent().ParentLevel.AddObject(b); b.SetShipParent(Parent.getParent()); ParentUnit = Parent.getParent(); Vector3 P3 = InstanceManager.GetWeaponPosition(ParentUnit.GetIntType(), new Vector3(ParentUnit.Position.X(), ParentUnit.Y, ParentUnit.Position.Y()), ref ParentUnit.RotationMatrix, ParentUnit.WeaponIndexID++, ParentUnit.Size.X()); Vector2 P2 = getPositionPattern(i); if (P2 != Vector2.Zero) { P2 = Vector2.Transform(P2, RotationMatrix); } b.SetPosition(new Vector2(P3.X, P3.Z) + P2, false); b.Y = P3.Y; Vector2 v = BulletSpeed * Logic.ToVector2(Parent.getRotation() + Accuracy - Rand.F() * Accuracy * 2 + getDirectionPattern(i)); b.SetSpeed(v); } else { ParentUnit.ParentLevel.AddObject(b); if (ParentUnit.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip s = (UnitShip)ParentUnit; if (s.IsHuge) { b.Big = true; } } b.SetShipParent(ParentUnit); b.SetPosition(ParentUnit.Position.get() + Vector2.Transform(getPositionPattern(i), RotationMatrix), false); b.SetSpeed(BulletSpeed * Logic.ToVector2(ParentUnit.Guns[0].getRotation() + Accuracy - Rand.F() * Accuracy * 2 + getDirectionPattern(i))); } b.SetAttackType(attackType); b.SetStartingPosition(b.getPosition()); b.SetDamage(Damage, PushTime, PushVelocityMult); b.SetModifierFactor(ModifierFactor); b.SetLifeTime(LifeTime); b.SetExplosive(BulletExplosionDistance, BulletExplosionDamage); b.AddTime(ROF); } } } else { CreateChargeParticles(ChargeTime / (float)(MaxChargeTime)); } if (ClipSize <= 0) { ReloadTime += gameTime.ElapsedGameTime.Milliseconds; } } }