// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f); // Create a skybox sceneMgr.SetSkyBox(true, "Examples/SpaceSkyBox", 50); // Create a light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Position = new Vector3(20, 80, 50); // Also add a nice starship in Entity ent = sceneMgr.CreateEntity("razor", "razor.mesh"); sceneMgr.RootSceneNode.AttachObject(ent); pThrusters = sceneMgr.CreateParticleSystem("ParticleSys1", 200); pThrusters.MaterialName = "Examples/Flare"; pThrusters.SetDefaultDimensions(25, 25); ParticleEmitter pEmit1 = pThrusters.AddEmitter("Point"); ParticleEmitter pEmit2 = pThrusters.AddEmitter("Point"); // Thruster 1 pEmit1.Angle = new Degree(3); pEmit1.TimeToLive = 0.2f; pEmit1.EmissionRate = 70; pEmit1.ParticleVelocity = 50; pEmit1.Direction = -Vector3.UNIT_Z; pEmit1.SetColour(ColourValue.White, ColourValue.Red); // Thruster 2 pEmit2.Angle = new Degree(3); pEmit2.TimeToLive = 0.2f; pEmit2.EmissionRate = 70; pEmit2.ParticleVelocity = 50; pEmit2.Direction = -Vector3.UNIT_Z; pEmit2.SetColour(ColourValue.White, ColourValue.Red); // Set the position of the thrusters pEmit1.Position = new Vector3(5.7f, 0.0f, 0.0f); pEmit2.Position = new Vector3(-18.0f, 0.0f, 0.0f); sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(0.0f, 6.5f, -67.0f)) .AttachObject(pThrusters); }
protected override void CreateScene() { // since whole screen is being redrawn every frame, dont bother clearing // option works for GL right now, uncomment to test it out. huge fps increase // also, depth_write in the skybox material must be set to on //mainViewport.ClearEveryFrame = false; // set ambient light scene.AmbientLight = new ColorEx(1.0f, 0.5f, 0.5f, 0.5f); // create a skybox scene.SetSkyBox(true, "Skybox/Space", 50); // create a light Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); // add a nice starship Entity ship = scene.CreateEntity("razor", "razor.mesh"); scene.RootSceneNode.AttachObject(ship); thrusters = ParticleSystemManager.Instance.CreateSystem("ParticleSystem", 200); thrusters.MaterialName = "Particles/Flare"; thrusters.DefaultWidth = 25; thrusters.DefaultHeight = 25; ParticleEmitter emitter1 = thrusters.AddEmitter("Point"); ParticleEmitter emitter2 = thrusters.AddEmitter("Point"); // thruster 1 emitter1.Angle = 3; emitter1.TimeToLive = 0.2f; emitter1.EmissionRate = 70; emitter1.ParticleVelocity = 50; emitter1.Direction = -Vector3.UnitZ; emitter1.ColorRangeStart = ColorEx.White; emitter1.ColorRangeEnd = ColorEx.Red; // thruster 2 emitter2.Angle = 3; emitter2.TimeToLive = 0.2f; emitter2.EmissionRate = 70; emitter2.ParticleVelocity = 50; emitter2.Direction = -Vector3.UnitZ; emitter2.ColorRangeStart = ColorEx.White; emitter2.ColorRangeEnd = ColorEx.Red; // set the position of the thrusters emitter1.Position = new Vector3(5.7f, 0, 0); emitter2.Position = new Vector3(-18, 0, 0); scene.RootSceneNode.CreateChildSceneNode(new Vector3(0, 6.5f, -67), Quaternion.Identity).AttachObject(thrusters); }
// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f); // Create a skybox sceneMgr.SetSkyBox(true, "Examples/SpaceSkyBox", 50 ); // Create a light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Position = new Vector3(20,80,50); // Also add a nice starship in Entity ent = sceneMgr.CreateEntity( "razor", "razor.mesh" ); sceneMgr.RootSceneNode.AttachObject( ent ); pThrusters = sceneMgr.CreateParticleSystem( "ParticleSys1", 200 ); pThrusters.MaterialName = "Examples/Flare"; pThrusters.SetDefaultDimensions( 25, 25 ); ParticleEmitter pEmit1 = pThrusters.AddEmitter( "Point" ); ParticleEmitter pEmit2 = pThrusters.AddEmitter( "Point" ); // Thruster 1 pEmit1.Angle = new Degree(3); pEmit1.TimeToLive = 0.2f; pEmit1.EmissionRate = 70; pEmit1.ParticleVelocity = 50; pEmit1.Direction = -Vector3.UNIT_Z; pEmit1.SetColour(ColourValue.White, ColourValue.Red); // Thruster 2 pEmit2.Angle = new Degree(3); pEmit2.TimeToLive = 0.2f; pEmit2.EmissionRate = 70; pEmit2.ParticleVelocity = 50; pEmit2.Direction = -Vector3.UNIT_Z; pEmit2.SetColour(ColourValue.White, ColourValue.Red); // Set the position of the thrusters pEmit1.Position = new Vector3( 5.7f, 0.0f, 0.0f ); pEmit2.Position = new Vector3( -18.0f, 0.0f, 0.0f ); sceneMgr.RootSceneNode.CreateChildSceneNode( new Vector3( 0.0f, 6.5f, -67.0f ) ) .AttachObject(pThrusters); }
public App(Control control) { mRoot = new Root(String.Format("plugins-{0}.cfg", GetOS())); Initialiser.SetupResources("resources.cfg"); mRoot.ShowConfigDialog(); mRenderWindow = mRoot.Initialise(control); mSceneManager = mRoot.CreateSceneManager((UInt16)SceneType.Generic, "ExampleSMInstance"); mCamera = mSceneManager.CreateCamera("MainCamera"); mCamera.Position = new Math3D.Vector3(150, 150, 150); mCamera.LookAt(new Math3D.Vector3(0, 0, 0)); mCamera.NearClipDistance = 5; mViewport = mRenderWindow.AddViewport(mCamera); mViewport.BackgroundColor = Color.Blue; mCamera.AspectRatio = (float)mViewport.ActualWidth / (float)mViewport.ActualHeight; TextureManager.Instance.SetDefaultNumMipmaps(5); ResourceGroupManager.getSingleton().initialiseAllResourceGroups(); mSceneManager.AmbientLightColor = Color.FromArgb(125, 125, 125, 125); mSceneManager.SetSkyBox(true, "Examples/SpaceSkyBox", 50); mLight = mSceneManager.CreateLight("MainLight"); mLight.Position = new Math3D.Vector3(20, 80, 50); mEntity = mSceneManager.CreateEntity("razor", "razor.mesh"); mSceneManager.RootSceneNode.AttachObject(mEntity); mParticleSystem = mSceneManager.CreateParticleSystem("ParticleSys1", 200); mParticleSystem.MaterialName = "Examples/Flare"; mParticleSystem.SetDefaultDimensions(25, 25); mParticleEmitter1 = mParticleSystem.AddEmitter("Point"); mParticleEmitter1.TimeToLive = 0.2f; mParticleEmitter1.EmissionRate = 70.0f; mParticleEmitter1.ParticleVelocity = 100.0f; mParticleEmitter1.Direction = new Math3D.Vector3(0.0f, 0.0f, -1.0f); mParticleEmitter1.SetColors(Color.White, Color.Red); mParticleEmitter1.Position = new Math3D.Vector3(5.7f, 0.0f, 0.0f); mParticleEmitter2 = mParticleSystem.AddEmitter("Point"); mParticleEmitter2.TimeToLive = 0.2f; mParticleEmitter2.EmissionRate = 70.0f; mParticleEmitter2.ParticleVelocity = 100.0f; mParticleEmitter2.Direction = new Math3D.Vector3(0.0f, 0.0f, -1.0f); mParticleEmitter2.SetColors(Color.White, Color.Red); mParticleEmitter2.Position = new Math3D.Vector3(-18.0f, 0.0f, 0.0f); mSceneManager.RootSceneNode.CreateChildSceneNode(new Math3D.Vector3(0.0f, 6.5f, -67.0f)).AttachObject(mParticleSystem); }
protected override void CreateScene() { mSceneManager.AmbientLightColor = Color.FromArgb(125, 125, 125, 125); mSceneManager.SetSkyBox(true, "Examples/SpaceSkyBox", 50); mCameraTarget = mSceneManager.RootSceneNode.CreateChildSceneNode(); mCameraPosition = mCameraTarget.CreateChildSceneNode(new Vector3(0, 0, -200)); mCameraPosition.AttachObject(mCamera); mCamera.SetPosition(0, 0, 0); mCamera.LookAt = new Vector3(0, 0, 0); mCamera.NearClipDistance = 5; mLight = mSceneManager.CreateLight("MainLight"); mLight.Position = new Math3D.Vector3(20, 80, 50); mEntity = mSceneManager.CreateEntity("razor", "razor.mesh"); mSceneManager.RootSceneNode.AttachObject(mEntity); mParticleSystem = mSceneManager.CreateParticleSystem("ParticleSys1", 200); mParticleSystem.MaterialName = "Examples/Flare"; mParticleSystem.SetDefaultDimensions(25, 25); mParticleEmitter1 = mParticleSystem.AddEmitter("Point"); mParticleEmitter1.TimeToLive = 0.2f; mParticleEmitter1.EmissionRate = 70.0f; mParticleEmitter1.ParticleVelocity = 100.0f; mParticleEmitter1.Direction = new Math3D.Vector3(0.0f, 0.0f, -1.0f); mParticleEmitter1.SetColors(Color.White, Color.Red); mParticleEmitter1.Position = new Math3D.Vector3(5.7f, 0.0f, 0.0f); mParticleEmitter2 = mParticleSystem.AddEmitter("Point"); mParticleEmitter2.TimeToLive = 0.2f; mParticleEmitter2.EmissionRate = 70.0f; mParticleEmitter2.ParticleVelocity = 100.0f; mParticleEmitter2.Direction = new Math3D.Vector3(0.0f, 0.0f, -1.0f); mParticleEmitter2.SetColors(Color.White, Color.Red); mParticleEmitter2.Position = new Math3D.Vector3(-18.0f, 0.0f, 0.0f); mSceneManager.RootSceneNode. CreateChildSceneNode(new Math3D.Vector3(0.0f, 6.5f, -67.0f)).AttachObject(mParticleSystem); }
public void Kill(Entity target, int delayMillis = 0) { Logger.Debug("Simulator", "Kill", "Trying to kill " + target.ID); target.Kill(); if (target.Visible == true) { if (target.DeathAnimation == String.Empty) { //CreateParticleAt (SPAWN_PARTICLE, target.X, target.Y); var ps = new ParticleSystem("DEATH"); ps.TTL = 2000; ps.Layer = this.world.worldView.ObjectsLayer; ps.Position = new Vector2f(target.X * this.CellWidth + target.DeathRect.Left, target.Y * this.CellHeight + target.DeathRect.Top); var emitter = new Emitter(ps, 0); //emitter.Offset = new Vector2f (target.DeathRect.Top, target.DeathRect.Left); emitter.ParticleTTL = 800; emitter.SpawnCount = 64; emitter.SpawnDeltaTime = 50; emitter.StartDelay = 250; emitter.TTL = 90; emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 2); emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 2); emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 4); emitter.AddAnimator(new GravityAnimation(new Vector2f(0f, 0.0002f))); emitter.AddAnimator(new FadeAnimation(0, 0, 800)); emitter.AddVariator(new GridSpawner(target.DeathRect.Width, target.DeathRect.Height, 4, 4)); emitter.AddVariator(new BurstSpawner(0.05f)); var cps = new ColorPickerSpawner(); cps.AddColor(target.DeathMain); cps.AddColor(target.DeathMain); cps.AddColor(target.DeathSecundary); emitter.AddVariator(cps); ps.AddEmitter(emitter); //var ps = GameFactory.LoadParticleFromTemplate (pid, target.X * this.CellWidth, target.Y * this.CellHeight, this.world.worldView.ObjectsLayer); IoManager.AddWidget(ps); target.OutObject.AddAnimator(new FadeAnimation(0, delayMillis, 500)); } else { SetAnimation(target, target.DeathAnimation); } this.events.WaitAndRun(delayMillis /* + 500*/, new DestroyEvent(target.ID)); } else { this.DestroyObject(target.ID); } }
public PlayerObject(string name, Vector2 startingPos, AnimatedSprite sprite, Texture2D particleTex, Texture2D lightTex) : base(name, startingPos, sprite) { base.sprite.Position = startingPos; base.sprite.CollisionRange = 32; this.currentMovement = Movement.Stopped; this.angleOffset = MathHelper.PiOver2; this.mouseLoc = Vector2.Zero; //create ambient light TexturedLight ambient = new TexturedLight { Texture = lightTex, Intensity = 1.5f, Scale = new Vector2(384, 384), Rotation = Sprite.Angle, Color = Color.White, //Radius = 8, //ConeDecay = 0.2f, Enabled = true }; ambient.Position = Position; //ambient.Origin = new Vector2(0.1f, 0.5f); base.lights.Add("Ambient", ambient); //create engine particle system ParticleSystem engine = new ParticleSystem(Position); engine.AddEmitter( new Vector2(0.030f, 0.005f), new Vector2(0, -1), new Vector2(0.001f * MathHelper.Pi, 0.001f * MathHelper.Pi), new Vector2(0.85f, 1.05f), new Vector2(120 / 2, 140 / 2), new Vector2(60 / 4, 70 / 4), Color.Blue, Color.LightBlue, Color.Red, Color.Crimson, new Vector2(400 / 3, 500 / 3), new Vector2(100 / 3, 120 / 3), 1000, Vector2.Zero, particleTex); engine.Emitters[0].StopEmmiting = true; base.particleSystems.Add("Engine", engine); }
public ParticleEmitterCluster(ParticleSystem particleSystem, ParticleEmitter[] referenceEmitters, Vector3 position, uint particleQuotaPerEmitter, bool eternal) { this.ParticleSystem = particleSystem; this.ParticleQuotaPerEmitter = particleQuotaPerEmitter; this.Eternal = eternal; Emitters = new ParticleEmitter[referenceEmitters.Length]; for (int i = 0; i < referenceEmitters.Length; ++i) { Emitters[i] = ParticleSystem.AddEmitter(referenceEmitters[i].Type); referenceEmitters[i].CopyParametersTo(Emitters[i]); TimeToLive = Math.Max(TimeToLive, Emitters[i].MaxTimeToLive + Emitters[i].MaxDuration); } this.Position = position; ParticleSystem.ParticleQuota += ParticleQuotaPerEmitter; }
public ParticleEmitter xAddTypedEmitter(string type, Dictionary <string, string> defParams) { ParticleEmitter em = null; try { em = psystem.AddEmitter(type); em.Name = "Emitter" + emitterId++ + ":" + type; em.SetColour(new ColourValue(1, 1, 1, 1), new ColourValue(1, 1, 1, 0)); em.SetDuration(5, 10); em.SetEmitted(false); em.SetParticleVelocity(1, 2); em.SetRepeatDelay(0, 0.1f); em.SetTimeToLive(0, 10); em.Position = new Vector3(0, 3, 0); em.Direction = new Vector3(0, 1, 0); em.Angle = (new Degree(30)).ValueRadians; em.EmissionRate = 100; em.StartTime = 0; // apply params if (defParams != null) { foreach (KeyValuePair <string, string> p in defParams) { em.SetParameter(p.Key, p.Value); } } // create dummy MovableObject dummy = Utils.MakeDummy(sceneMgr, em.Name, "Dummy", 1); SceneNode node = sceneMgr.RootSceneNode.CreateChildSceneNode(em.Name); node.AttachObject(dummy); node.Position = em.Position; }catch (Exception err) { MessageBox.Show("Error: Invalid emitter settings" + err); } return(em); }
/// <summary> /// Default constructor. /// </summary> /// <param name="system">ParticleSystem that this Emitter will add itself to.</param> /// <param name="budget">Number of Particles available to this Emitter.</param> public Emitter(ParticleSystem system, int budget) { _budget = budget; _active = new LinkedList <Particle>(); _idle = new Queue <Particle>(_budget); _modifiers = new List <Modifier>(); _controllers = new List <Controller>(); _snapCache = new Queue <Snapshot>(1024); _snapshots = new Queue <Snapshot>(1024); _sleeping = true; _dischargeQuantity = 1; _lifespan = 1000; _color = Color.White; _opacity = 1f; _scale = 1f; _speed = 0f; _speedRange = 0f; _strip = system.DefaultImageStrip; _frame = 1; _blend = SpriteBlendMode.Additive; Position = Vector2.Zero; //Fill the idle Particles queue with Particles... for (int i = 0; i < _budget; i++) { _idle.Enqueue(new Particle()); } //Fill the Snapshot cache with empty Snapshots... for (int i = 0; i < 1024; i++) { _snapCache.Enqueue(GenerateSnapshot()); } system.AddEmitter(this); }
public PlayerObject(string name, Vector2 startingPos, AnimatedSprite sprite, Texture2D particleTex) : base(name, startingPos, sprite) { base.Angle = MathHelper.PiOver2; base.Sprite.CollisionRange = 32 * 1.4f; Light2D ambient = new Light2D { Texture = LightTextureBuilder.CreatePointLight(GameEngine.CurrentMap.Krypton.GraphicsDevice, 128), Intensity = 1.0f, Range = 256, Angle = Sprite.Angle, Fov = MathHelper.TwoPi, Color = Color.White, IsOn = true }; ambient.Position = Position; base.lights.Add("Ambient", ambient); ParticleSystem engine = new ParticleSystem(Position); engine.AddEmitter( new Vector2(0.098f, 0.016f), new Vector2(0, -1), new Vector2(0.001f * MathHelper.Pi, 0.001f * MathHelper.Pi), new Vector2(0.85f, 1.05f), new Vector2(120 / 2, 140 / 2), new Vector2(60 / 4, 70 / 4), Color.Yellow, Color.Orange, Color.Red, Color.Crimson, new Vector2(400 / 3, 500 / 3), new Vector2(100 / 3, 120 / 3), 500, Vector2.Zero, particleTex); engine.Emitters[0].StopEmmiting = true; base.particleSystems.Add("Engine", engine); }
public static void AddEmitter(BaseEmitter emitter) { system.AddEmitter(emitter, Time.FromSeconds(emitter.EmitterDuration)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { ScreenSize = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); screenWidth = GraphicsDevice.Viewport.Width; screenHeight = GraphicsDevice.Viewport.Height; BulletDir = Vector2.Zero; noOfClues = 5; // List of cases #region caseList Sprite CaseItem = new Sprite(Content.Load<Texture2D>("case"), new Rectangle(0, 0, Content.Load<Texture2D>("case").Width, Content.Load<Texture2D>("case").Height), 0.0f, SpriteEffects.None, Color.White); for (int i = 0; i < noOfClues; i++) { caseList.Add("Case" + i.ToString(), new CaseFile(Content.Load<Texture2D>("popUp"), new Rectangle(10, 10, 150, 200), new Rectangle(0, 0, 3200, 2400), 0.0f, SpriteEffects.None, Color.White, CaseItem.Copy(), "lol", "hehe", Vector2.Zero)); } #endregion #region MenuSetup mainMenu = new Menu(new Rectangle(0, -5, screenWidth*8/10, screenHeight / 8), Content.Load<Texture2D>("MainMenuTitle")); mainMenu.Add(new Rectangle(0, 0, screenWidth / 10, screenHeight / 10), Content.Load<Texture2D>("MainMenuPlay")); mainMenu.Add(new Rectangle(0, 0, screenWidth / 5, screenHeight / 9), Content.Load<Texture2D>("MainMenuSettings")); mainMenu.Add(new Rectangle(0, 0, screenWidth / 12, screenHeight / 9), Content.Load<Texture2D>("MainMenuExit")); Alignment align = Alignment.Left; mainMenu.Setup(align, screenHeight, screenWidth); mainMenu.backgroundRectangle = new Rectangle(0, 0, screenWidth, screenHeight); mainMenu.backgroundTexture = Content.Load<Texture2D>("MainMenuBackground"); #endregion // Creates the user player = new Player( Content.Load<Texture2D>("Tron_Charcter2"), 8, 3); player.Load(); // Creates the enemy enemy = new Enemy( Content.Load<Texture2D>("Tron_Charcter2"), 8, 3); enemy.Load(); CaseFont = Content.Load<SpriteFont>("cFont"); splashScreen = new Sprite(Content.Load<Texture2D>("betaJester1"), new Rectangle(0, 0, screenWidth, screenHeight), 0.0f, SpriteEffects.None, Color.White); //ixjingle = Content.Load<SoundEffect>("ixjingle"); //heartBeatIntro = Content.Load<SoundEffect>("GGJ13_Theme"); background = new Background(Content.Load<Texture2D>("gamebackground"), Content.Load<Texture2D>("gamebackgroundback"), Content.Load<Texture2D>("gamebackgroundmiddle"), Content.Load<Texture2D>("gamebackgroundfront"), 200 * 32, screenWidth, screenHeight); playerData = PlayerData.Load(); //heartBeatTracker = new HeartBeatTracker(Content.Load<SoundEffect>("heartBeat")); ParticleEffects = new ParticleSystem(Vector2.Zero); ParticleEffects.AddEmitter(new Vector2(0.001f, 0.6f), new Vector2(0, 1), new Vector2(0.0f * MathHelper.Pi, 0.0f * -MathHelper.Pi), new Vector2(1f, 1f), new Vector2(60, 70), new Vector2(15, 15f), Color.White, Color.White, Color.White, Color.White, new Vector2(0, 700), new Vector2(0, 120), 500, new Vector2(100, 100), Content.Load<Texture2D>("raindrop"), 0, (int)ScreenSize.X); if (playerData == null) { playerData = new PlayerData(100, 0.0f, 0, 0); } enemyGun = new Gun(new Vector2(enemy.enemyRectangle.X + enemy.enemyRectangle.Width, enemy.enemyRectangle.Y), Content.Load<Texture2D>("bullet"), new Rectangle(0, 0, Content.Load<Texture2D>("bullet").Width, Content.Load<Texture2D>("bullet").Height), 5, 0.0f, SpriteEffects.None, Color.White, 1, null, null, false); playerGun = new Gun(new Vector2(player.playerRectangle.X + player.playerRectangle.Width, player.playerRectangle.Y), Content.Load<Texture2D>("bullet"), new Rectangle(0, 0, Content.Load<Texture2D>("bullet").Width, Content.Load<Texture2D>("bullet").Height), 5, 0.0f, SpriteEffects.None, Color.White, 1, null, null, false); spriteBatch = new SpriteBatch(GraphicsDevice); Tile.TileSetTexture = Content.Load<Texture2D>("TileSet"); background = new Background(Content.Load<Texture2D>("gameBackground"), Content.Load<Texture2D>("gameBackgroundBack"), Content.Load<Texture2D>("gameBackgroundMiddle"), Content.Load<Texture2D>("gameBackgroundFront"), (200 * 32), GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); }
static public ParticleSystem LoadParticleFromTemplate(string templateId, float x, float y, ObjectsLayer layer, bool flip = false) { try { var res = new ParticleSystem(templateId); XmlNode template = GameFactory.xdoc.SelectSingleNode("//particle[@id='" + templateId + "']"); if (XmlUtilities.GetString(template, "flip", "true") == "false") { flip = false; } var xCoeff = flip ? -1f : 1f; var angleCoeff = flip ? 3.1415f : 0f; res.TTL = XmlUtilities.GetInt(template, "ttl"); if (res.TTL < 0) { res.TTL = int.MaxValue; } res.Layer = layer; res.Position = new Vector2f(x, y); var emitters = template.SelectNodes("./emitter"); for (int e = 0; e < emitters.Count; e++) { Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New emitter: " + emitters [e].ToString()); var startDelay = XmlUtilities.GetInt(emitters [e], "startDelay"); var emitter = new Emitter(res, startDelay); emitter.Offset = new Vector2f( XmlUtilities.GetFloat(emitters [e], "offsetX") * xCoeff, XmlUtilities.GetFloat(emitters [e], "offsetY") ); emitter.ParticleTTL = XmlUtilities.GetInt(emitters [e], "particleTtl"); emitter.SpawnCount = XmlUtilities.GetInt(emitters [e], "spawnCount"); emitter.SpawnDeltaTime = XmlUtilities.GetInt(emitters [e], "spawnDeltaTime"); emitter.TTL = XmlUtilities.GetInt(emitters [e], "ttl"); if (emitter.TTL < 0) { emitter.TTL = int.MaxValue; } emitter.ZIndex = XmlUtilities.GetInt(emitters [e], "zIndex", 0); var children = emitters [e].ChildNodes; for (var c = 0; c < children.Count; c++) { switch (children [c].Name) { case "boxSpawner": emitter.AddVariator(new BoxSpawner( XmlUtilities.GetFloat(children [c], "width"), XmlUtilities.GetFloat(children [c], "height") )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BoxSpawner: " + children [c].ToString()); break; case "burstSpawner": emitter.AddVariator(new BurstSpawner( XmlUtilities.GetFloat(children [c], "maxForce"), XmlUtilities.GetFloat(children [c], "minForce"), XmlUtilities.GetFloat(children [c], "maxAngle") + angleCoeff, XmlUtilities.GetFloat(children [c], "minAngle") + angleCoeff )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BurstSpawner: " + children [c].ToString()); break; case "burstInSpawner": emitter.AddVariator(new BurstInSpawner( XmlUtilities.GetFloat(children [c], "maxRadius"), XmlUtilities.GetFloat(children [c], "minRadius"), XmlUtilities.GetFloat(children [c], "maxForce"), XmlUtilities.GetFloat(children [c], "minForce"), XmlUtilities.GetFloat(children [c], "maxAngle") + angleCoeff, XmlUtilities.GetFloat(children [c], "minAngle") + angleCoeff )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BurstInSpawner: " + children [c].ToString()); break; case "colorAnimation": var buff = XmlUtilities.GetIntArray(children [c], "startColor"); var startColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]); if (buff.Length > 3) { startColor.A = (byte)buff [3]; } buff = XmlUtilities.GetIntArray(children [c], "endColor"); var endColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]); if (buff.Length > 3) { endColor.A = (byte)buff [3]; } emitter.AddAnimator(new ColorAnimation(startColor, endColor, XmlUtilities.GetInt(children [c], "duration"))); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ColorAnimator: " + children [c].ToString()); break; case "colorPicker": var cps = new ColorPickerSpawner(); var colors = children [c].SelectNodes("./color"); for (int i = 0; i < colors.Count; i++) { var color = XmlUtilities.GetIntArray(colors [i], "select"); switch (color.Length) { case 3: cps.AddColor(new Color((byte)color [0], (byte)color [1], (byte)color [2])); break; case 4: cps.AddColor(new Color((byte)color [0], (byte)color [1], (byte)color [2], (byte)color [3])); break; default: break; } } emitter.AddVariator(cps); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ColorPickerSpawner: " + children [c].ToString()); break; case "fade": emitter.AddAnimator(new FadeAnimation( XmlUtilities.GetInt(children [c], "fadeInDuration"), XmlUtilities.GetInt(children [c], "duration"), XmlUtilities.GetInt(children [c], "fadeOutDuration") )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New FadeAnimator: " + children [c].ToString()); break; case "gravity": emitter.AddAnimator(new GravityAnimation(new Vector2f( XmlUtilities.GetFloat(children [c], "forceX") * xCoeff, XmlUtilities.GetFloat(children [c], "forceY") ))); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New GravityAnimation: " + children [c].ToString()); break; case "gridSpawner": emitter.AddVariator(new GridSpawner( XmlUtilities.GetInt(children [c], "gridWidth"), XmlUtilities.GetInt(children [c], "gridHeight"), XmlUtilities.GetFloat(children [c], "cellWidth") * xCoeff, XmlUtilities.GetFloat(children [c], "cellHeight"), XmlUtilities.GetFloat(children [c], "deltaX", 0f), XmlUtilities.GetFloat(children [c], "deltaY", 0f) )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New GridSpawner: " + children [c].ToString()); break; case "lightSpawner": buff = XmlUtilities.GetIntArray(children [c], "color"); var lightColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]); if (buff.Length > 3) { lightColor.A = (byte)buff [3]; } emitter.AddVariator(new LightSpawner(lightColor, XmlUtilities.GetInt(children [c], "radius"))); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New LightSpawner: " + children [c].ToString()); break; case "particleTemplate": if (children [c].HasChildNodes) { emitter.AddParticleTemplate( XmlUtilities.GetString(children [c], "texture"), XmlUtilities.GetInt(children [c], "x"), XmlUtilities.GetInt(children [c], "y"), XmlUtilities.GetInt(children [c], "width"), XmlUtilities.GetInt(children [c], "height"), XmlUtilities.GetFloat(children [c], "scale", 1f), LoadAnimationDefinition(children [c]) ); } else { emitter.AddParticleTemplate( XmlUtilities.GetString(children [c], "texture"), XmlUtilities.GetInt(children [c], "x"), XmlUtilities.GetInt(children [c], "y"), XmlUtilities.GetInt(children [c], "width"), XmlUtilities.GetInt(children [c], "height"), XmlUtilities.GetFloat(children [c], "scale", 1f) ); } Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New particle: " + children [c].ToString()); break; case "scaleAnimation": emitter.AddAnimator(new ScaleAnimation( XmlUtilities.GetInt(children [c], "duration"), XmlUtilities.GetFloat(children [c], "start"), XmlUtilities.GetFloat(children [c], "end") )); break; case "sfxSpawner": emitter.AddVariator(new SfxSpawner( XmlUtilities.GetString(children [c], "sfx") )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New SfxSpawner: " + children [c].ToString()); break; case "zAnimation": emitter.AddAnimator(new ZAnimation( XmlUtilities.GetInt(children [c], "duration"), XmlUtilities.GetInt(children [c], "start"), XmlUtilities.GetInt(children [c], "end") )); Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ZAnimation: " + children [c].ToString()); break; default: break; } } res.AddEmitter(emitter); } Logger.Debug("GameFactory", "LoadParticleFromTemplate", "Built particle system " + templateId); return(res); } catch (Exception ex) { Logger.Warning("GameFactory", "LoadParticleFromTemplate", ex.ToString()); return(null); } }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <param name="system"></param> private void ParseEmitter(string type, TextReader script, ParticleSystem system) { ParticleEmitter emitter = system.AddEmitter(type); string line = ""; while(line != null) { line = ParseHelper.ReadLine(script); if(!(line.Length == 0 || line.StartsWith("//"))) { if(line == "}") { // finished with this emitter break; } else { ParseEmitterAttrib(line.ToLower(), emitter); } } // if } // while }
/// <summary> /// Default constructor. /// </summary> /// <param name="system">ParticleSystem that this Emitter will add itself to.</param> /// <param name="budget">Number of Particles available to this Emitter.</param> public Emitter(ParticleSystem system, int budget) { _budget = budget; _active = new LinkedList<Particle>(); _idle = new Queue<Particle>(_budget); _modifiers = new List<Modifier>(); _controllers = new List<Controller>(); _snapCache = new Queue<Snapshot>(1024); _snapshots = new Queue<Snapshot>(1024); _sleeping = true; _dischargeQuantity = 1; _lifespan = 1000; _color = Color.White; _opacity = 1f; _scale = 1f; _speed = 0f; _speedRange = 0f; _strip = system.DefaultImageStrip; _frame = 1; _blend = SpriteBlendMode.Additive; Position = Vector2.Zero; //Fill the idle Particles queue with Particles... for (int i = 0; i < _budget; i++) { _idle.Enqueue(new Particle()); } //Fill the Snapshot cache with empty Snapshots... for (int i = 0; i < 1024; i++) { _snapCache.Enqueue(GenerateSnapshot()); } system.AddEmitter(this); }
public ParticleEmitter(ParticleSystem system) { this.system = system; system.AddEmitter(this); }