public override void Create() { SoundLibrary.Load(); InstanceManager.Clear(); ParticleManager.Load(); Load(); OverDrawChildren2D = AddTag(GameObjectTag._2DOverDraw); OverDrawViewsChildren = AddTag(GameObjectTag.OverDrawViews); Draw2DChildren = AddTag(GameObjectTag._2DForward); #if EDITOR && WINDOWS if (ParentLevel.LevelForEditing) { PreDrawChildren = AddTag(GameObjectTag._2DPreDraw); } else #endif { ForwardChildren = AddTag(GameObjectTag._3DForward); BackgroundChildren = AddTag(GameObjectTag._3DBackground); DepthOverChildren = AddTag(GameObjectTag._3DDepthOver); } SolidChildren = AddTag(GameObjectTag._2DSolid); ShipChildren = AddTag(GameObjectTag.ShipGameUnitBasic); DistortionChildren = AddTag(GameObjectTag._3DDistortion); SolidQuadGrid = Add(new QuadGrid()); #if DRAWQUAD DrawQuadGrid = Add(new QuadGrid()); #endif FactionManager.Init(); base.Create(); }
public override void Destroy() { InstanceManager.RemoveChild(frame); base.Destroy(); }
public override void PreDraw() { #if EDITOR && WINDOWS if (!ParentLevel.LevelForEditing) #endif { distortionRenderer.SetRenderTarget(); Camera3D currentCamera = null; foreach (WorldViewer3D s in WorldViewerChildren) { Render.CurrentWorldViewer3D = s; s.getSceneView().Set(); Render.CurrentView = s.getSceneView(); currentCamera = s.getCamera(); CurrentCamera = currentCamera; foreach (GameObject g in DistortionChildren) { g.Draw3D(currentCamera, GameObjectTag._3DDistortion); } InstanceManager.DrawDistortion(currentCamera); ParticleManager.DrawDistortion(currentCamera); } } Game1.graphicsDevice.SetRenderTarget(FinalTarget); Game1.graphicsDevice.Clear(Color.Black); #if EDITOR && WINDOWS if (!ParentLevel.LevelForEditing) #endif { Camera3D currentCamera = null; foreach (WorldViewer3D s in WorldViewerChildren) { Game1.graphicsDevice.BlendState = BlendState.Opaque; Game1.graphicsDevice.DepthStencilState = DepthStencilState.None; Render.CurrentWorldViewer3D = s; if (s.GetType().Equals(typeof(PlayerShip))) { DrawingShip = (PlayerShip)s; } s.getSceneView().Set(); Render.CurrentView = s.getSceneView(); currentCamera = s.getCamera(); CurrentCamera = currentCamera; foreach (GameObject g in BackgroundChildren) { g.Draw3D(currentCamera, GameObjectTag._3DBackground); } Game1.graphicsDevice.DepthStencilState = DepthStencilState.Default; Game1.graphicsDevice.BlendState = BlendState.AlphaBlend; foreach (GameObject g in ForwardChildren) { g.Draw3D(currentCamera, GameObjectTag._3DForward); } InstanceManager.DrawShield(currentCamera); ParticleManager.PreDraw(currentCamera); InstanceManager.Draw(currentCamera); ParticleManager.Draw(currentCamera); Game1.graphicsDevice.DepthStencilState = DepthStencilState.None; Game1.graphicsDevice.BlendState = BlendState.AlphaBlend; foreach (GameObject g in DepthOverChildren) { g.Draw3D(currentCamera, GameObjectTag._3DForward); } } MasterManager.SetViewportToFullscreen(); } }
public void Deactivate() { particleAlpha = 0; InstanceManager.RemoveChild(this); RemoveTag(GameObjectTag.Update); }
public void Eliminate() { DeathParticles(); InstanceManager.RemoveChild(this); Destroy(); }
public override void BlowUp() { if (Dead || Lives < 1) { return; } Vector3 P3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 10; i++) { LineParticleSystem.AddParticle(P3, P3 + Rand.V3() * MaxEngagementDistance, TeamInfo.GetColor(GetTeam())); } foreach (Faction f in FactionManager.Factions) { if (MyCard == null) { MyCard = (TurretCard)FactionCard.FactionTurretDeck[0]; } if (f.Team != GetTeam()) { f.roundReport.TurretsKilled++; f.AddEvent(MyCard.Name + " Destroyed", new Color(1, 0.5f, 0.5f), FactionEvent.KillTexture); } else { f.roundReport.TurretsLost++; f.AddEvent(MyCard.Name + " Lost", new Color(1, 0.5f, 0.5f), FactionEvent.LossTexture); } } if (ShouldDeathSound) { SoundManager.Play3DSound(DeathSound, new Vector3(Position.X(), Y, Position.Y()), DeathVolume, 1000, 1); ShouldDeathSound = false; } FreezeMult = 0; VirusTime = 0; DeathParticles(); Lives--; Dead = true; if (MyBustedTurret == null) { MyBustedTurret = new BustedTurret(this); ParentLevel.AddObject(MyBustedTurret); MyBustedTurret.SetPosition(getPosition()); } MyBustedTurret.WorldMatrix = WorldMatrix; MyBustedTurret.Activate(); InstanceManager.RemoveChild(this); RemoveTag(GameObjectTag._2DSolid); RemoveTag(GameObjectTag._2DForward); LinkedList <GameObject> GList = Parent2DScene.GetList(GameObjectTag._2DSolid); if (GList.Contains(this)) { GList.Remove(this); } BuildTimer = 0; float BulletExplosionDistance = 200; float BulletExplosionDamage = 1f; QuadGrid grid = Parent2DScene.quadGrids.First.Value; for (int i = 0; i < 2; i++) { bool ActivateDeathSound = true; foreach (Basic2DObject o in grid.Enumerate(Position.get(), new Vector2(BulletExplosionDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitShip))) { BasicShipGameObject s = (BasicShipGameObject)o; float dist = Vector2.Distance(s.Position.get(), Position.get()) - o.Size.X() / 2; if (dist < BulletExplosionDistance && GetTeam() != s.GetTeam() && s.CanBeTargeted()) { float DistMult = 1; if (dist > 0) { DistMult = (BulletExplosionDistance - dist) / BulletExplosionDistance; } if (s.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip ship = (UnitShip)s; ship.CanDeathSound = ActivateDeathSound; } s.Damage(DistMult * BulletExplosionDamage, DistMult, Vector2.Normalize(s.Position.get() - Position.get()), this, AttackType.Explosion); if (s.Dead) { ActivateDeathSound = false; } else if (s.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip ship = (UnitShip)s; ship.CanDeathSound = true; } } } } } if (ShieldAlpha > 0) { ShieldInstancer.Remove(this); ShieldAlpha = -1; } }
private void UpdateFieldState(GameTime gameTime) { InvTime -= gameTime.ElapsedGameTime.Milliseconds; if (InvTime < 1) { if (FieldStateTime > 0) { FieldStateTime -= gameTime.ElapsedGameTime.Milliseconds; if (fieldState == FieldState.SpeedBoost) { if (MyColor.R > 64) { MyColor.R = (byte)Math.Max(MyColor.R - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } if (MyColor.G < 255) { MyColor.G = (byte)Math.Min(MyColor.G + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 255); } if (MyColor.B > 64) { MyColor.B = (byte)Math.Max(MyColor.B - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } ParticleManager.CreateParticle(new Vector3(Position.X(), Y, Position.Y()), Vector3.Zero, new Color(0.25f, 1, 0.5f), Size.X() * 10, 1); } if (fieldState == FieldState.DamageBoost) { if (MyColor.R < 255) { MyColor.R = (byte)Math.Max(MyColor.R + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 255); } if (MyColor.G > 64) { MyColor.G = (byte)Math.Min(MyColor.G - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } if (MyColor.B > 64) { MyColor.B = (byte)Math.Max(MyColor.B - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } ParticleManager.CreateParticle(new Vector3(Position.X(), Y, Position.Y()), Vector3.Zero, new Color(1, 0.5f, 0.25f), Size.X() * 10, 1); } if (fieldState == FieldState.Cloaked) { if (CloakAlpha < 1) { if (!CloakCommited && !Dead) { CloakCommited = true; InstanceManager.AddDisplacementChild(this); } CloakAlpha += gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed; if (CloakAlpha > 1) { CloakAlpha = 1; MyColor = new Color(0.25f, 0.25f, 0.25f, 0) * 0; } else { MyColor = new Color(0.25f, 0.25f, 0.25f, 1) * (1 - CloakAlpha); } } if (FieldStateTime < 0) { SoundManager.Play3DSound("UnitUnCloak", new Vector3(Position.X(), Y, Position.Y()), 0.2f, 700, 3); } } } else { if (CloakAlpha > 0) { CloakAlpha -= gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed; if (CloakAlpha < 0) { CloakAlpha = 0; MyColor = new Color(0.25f, 0.25f, 0.25f, 1); if (CloakCommited) { CloakCommited = false; InstanceManager.RemoveDisplacementChild(this); } } else { MyColor = new Color(0.25f, 0.25f, 0.25f, 1) * (1 - CloakAlpha); } } else { //if (IsGhostMode) // ParticleManager.CreateParticle(new Vector3(Position.X(), Y, Position.Y()), Vector3.Zero, new Color(0.5f, 0.25f, 0.5f), Size.X() * 10, 1); int TargetR = 64; int TargetB = 64; if (MyColor.R < TargetR) { MyColor.R = (byte)Math.Min(MyColor.R + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, TargetR); } else if (MyColor.R > TargetR) { MyColor.R = (byte)Math.Max(MyColor.R - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, TargetR); } if (MyColor.G < 64) { MyColor.G = (byte)Math.Min(MyColor.G + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } else if (MyColor.G > 64) { MyColor.G = (byte)Math.Max(MyColor.G - gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 64); } if (MyColor.B < TargetB) { MyColor.B = (byte)Math.Min(MyColor.B + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, TargetB); } } } } else { if (MyColor.R < 255) { MyColor.R = (byte)Math.Min(MyColor.R + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 255); } if (MyColor.G < 255) { MyColor.G = (byte)Math.Min(MyColor.G + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 255); } if (MyColor.B < 255) { MyColor.B = (byte)Math.Min(MyColor.B + gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * CloakAlphaChangeSpeed * 255, 255); } } }
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; } } }