//------------------------------------------------------------------------- public void init() { mTransform = transform; mParticleSystem = GetComponent <ParticleSystem>(); mBaseParticle = gameObject.GetComponent <BaseParticle>(); if (mBaseParticle == null) { mBaseParticle = gameObject.AddComponent <NullParticle>(); } }
//GeneratePopParticles(pOwner, state, iterate); private void GeneratePopParticles(IStateOwner pOwner, GameplayGameState gstate, SKPointI pt) { var rgen = TetrisGame.rgen; var popItem = gstate.PlayField.Contents[pt.Y][pt.X]; BCColor[] useColor = YellowColors; if (popItem is LineSeriesBlock lsb) { switch (lsb.CombiningIndex) { case LineSeriesBlock.CombiningTypes.Red: useColor = RedColors; break; case LineSeriesBlock.CombiningTypes.Blue: useColor = BlueColors; break; case LineSeriesBlock.CombiningTypes.Yellow: useColor = YellowColors; break; case LineSeriesBlock.CombiningTypes.Orange: useColor = OrangeColors; break; case LineSeriesBlock.CombiningTypes.Magenta: useColor = MagentaColors; break; case LineSeriesBlock.CombiningTypes.Green: useColor = GreenColors; break; } for (int i = 0; i < ParticlesPerPop; i++) { PointF Offset = new PointF((float)rgen.NextDouble(), (float)rgen.NextDouble()); BCColor selColor = TetrisGame.Choose(useColor); BCPoint Velocity = TetrisGame.Choose(CardinalOptions); float Speed = (float)rgen.NextDouble() * (MAX_SPEED - MIN_SPEED) + MIN_SPEED; float Sign = TetrisGame.Choose(new float[] { -1f, 1f }); BCPoint VelocityUse = new BCPoint(Velocity.X * Speed * Sign, Velocity.Y * Speed * Sign); BaseParticle bp = new BaseParticle(new BCPoint(pt.X + Offset.X, pt.Y + Offset.Y), VelocityUse, selColor); gstate.Particles.Add(bp); } } /*for (int i=0;i<ParticlesPerPop;i++) * { * * }*/ }
private void AddParticles(IStateOwner pOwner, int BlockX, int BlockY, int DirectionMultiplier, int RowsCleared) { //the actual block we are clearing... var ClearingBlock = _BaseState.PlayField.Contents[BlockY][BlockX]; SKColor baseColor = TetrisGame.Choose(ClearLineParticleColours); Bitmap sourcebitmap = null; if (ClearingBlock != null && ClearingBlock is ImageBlock ib) { sourcebitmap = new Bitmap(ib._RotationImages[MathHelper.mod(ib.Rotation, ib._RotationImages.Length)]); } var blockWidth = _BaseState.PlayField.GetBlockWidth((SKRect)pOwner.LastDrawBounds); var blockHeight = _BaseState.PlayField.GetBlockHeight((SKRect)pOwner.LastDrawBounds); var CoordPos = new BCPoint(BlockX, BlockY - 2); lock (_BaseState.Particles) { List <BaseParticle> ToAdd = new List <BaseParticle>(ParticleCountPerBlock); for (int i = 0; i < ParticleCountPerBlock; i++) { BCPoint ParticlePos = new BCPoint((float)TetrisGame.rgen.NextDouble(), (float)TetrisGame.rgen.NextDouble()); //choose a new random position within the block. BCPoint NewParticlePoint = new BCPoint(CoordPos.X + ParticlePos.X, CoordPos.Y + ParticlePos.Y); BCPoint Velocity = new BCPoint( (float)(DirectionMultiplier * (TetrisGame.rgen.NextDouble() * 1 + (Math.Abs(BlockX - (_BaseState.PlayField.ColCount / 2)) / 5))), 0 ); BCColor ChosenColor = baseColor; if (sourcebitmap != null) { Point TargetPixel = new Point((int)(ParticlePos.X * sourcebitmap.Width), (int)(ParticlePos.Y * sourcebitmap.Height)); ChosenColor = sourcebitmap.GetPixel(TargetPixel.X, TargetPixel.Y); } BaseParticle p = new BaseParticle(NewParticlePoint, Velocity, ChosenColor); if (RowsCleared >= 4) { if (TetrisGame.rgen.NextDouble() > 0.25d) { p.ColorCalculatorFunction = BaseParticle.GetRainbowColorFunc(pOwner, 500); } } p.TTL = (uint)ClearParticleTTL; ToAdd.Add(p); } _BaseState.Particles.AddRange(ToAdd); } }
public void SpawnParticle(ParticleType type, Transform parent) { if (!m_particles.ContainsKey(type)) { return; } BaseParticle baseParticles = Instantiate(m_particles[type], parent); baseParticles.transform.localPosition = Vector3.zero; baseParticles.Activate(); }
//------------------------------------------------------------------------- public void destroy() { if (mBaseParticle != null) { mBaseParticle.destroy(); mBaseParticle = null; } if (gameObject != null) { Destroy(gameObject); } }
//------------------------------------------------------------------------- public void destroy() { if (mBaseParticle != null) { mBaseParticle.destroy(); mBaseParticle = null; } if (gameObject != null) { Destroy(gameObject); } }
private void GenerateDropParticles(BCPoint Location, int NumGenerate, Func <BCPoint> VelocityGenerator, Func <float, float, BCColor> ColorFunc) { lock (Particles) { for (int i = 0; i < NumGenerate; i++) { var genX = (float)rgen.NextDouble(); var genY = (float)rgen.NextDouble(); BCPoint Genpos = new BCPoint(Location.X + genX, Location.Y + genY); BCColor ChosenColor = ColorFunc(genX, genY); BaseParticle MakeParticle = new BaseParticle(Genpos, VelocityGenerator(), ChosenColor); Particles.Add(MakeParticle); } } }
/// <summary> /// Updates the particle emitter. /// </summary> /// <returns>True if it's still alive, false if not.</returns> public override bool Update() { if (m_Emitting) { m_FrequencyCounter = m_FrequencyCounter + (m_Frequency / 1000.0); while (m_FrequencyCounter >= 1) { BaseParticle p = SetParticleBaseAttributes(CreateParticle()); if (p != null) { m_Target.Add(p); } m_FrequencyCounter -= 1f; } } return(base.Update()); }
/// <summary> /// A private method that will change the attributes of the passed in particle to fit the emitter's description. /// </summary> /// <param name="particle">The particle to change.</param> /// <remarks>Use this method when overriding the CreateParticle method.</remarks> /// <returns>The particle with the changed properties.</returns> private BaseParticle SetParticleBaseAttributes(BaseParticle particle) { if (particle == null) { return(null); } particle.Life = Random.Next(m_LifeMin, m_LifeMax); particle.LifeFull = Random.Next(m_LifeFullMin, m_LifeFullMax); particle.Velocity = new Vector(GetRange(m_DirectionMin, m_DirectionMax)); Vector vel = particle.Velocity; vel.Length = GetRange(m_SpeedMin, m_SpeedMax); particle.Velocity = vel; //particle.Velocity.Length = GetRange(m_SpeedMin, m_SpeedMax); particle.X = GetRange(this.X, this.X + m_Width); particle.Y = GetRange(this.Y, this.Y + m_Height); return(particle); }
public override void Render(IStateOwner pOwner, SKCanvas pRenderTarget, BaseParticle Source, GameStateSkiaDrawParameters Element) { Render(pOwner, pRenderTarget, (CharParticle)Source, Element); }
private void AddParticles_Row(IStateOwner pOwner, BCRect RowBounds, int Lines = 1) { String UseText = RowClearText?[Lines] ?? $"{Lines}LINE"; Func <BaseParticle, BCColor> TetrisColorFunc = BaseParticle.GetRainbowColorFunc(pOwner); Func <BaseParticle, BCColor> SingleLineColorFunc = (o) => { int timebase = 2000; double DarknessValue = (Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000) / 2) + 1; BCColor usecolor = (Color) new HSLColor(0, 120, DarknessValue * 120); return(usecolor); }; Func <BaseParticle, BCColor> DoubleLineColorFunc = (o) => { int timebase = 2000; double DarknessValue = Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000); BCColor usecolor = (Color) new HSLColor(75, 120, DarknessValue * 120); return(usecolor); }; Func <BaseParticle, BCColor> TripleLineColorFunc = (o) => { int timebase = 2000; double DarknessValue = Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000); BCColor usecolor = (Color) new HSLColor(150, 120, DarknessValue * 120); return(usecolor); }; Func <BaseParticle, BCColor>[] LineFuncs = new Func <BaseParticle, BCColor>[] { SingleLineColorFunc, DoubleLineColorFunc, TripleLineColorFunc, TetrisColorFunc }; //split the text into characters... char[] CharsToShow = UseText.ToCharArray(); float XOffset = (int)((float)RowBounds.Width / 2 - ((float)CharsToShow.Length / 2)); //one character per block, ideally. List <CharParticle> MakeParticles = new List <CharParticle>(); for (int x = 0; x < CharsToShow.Length; x++) { int i = x % CharsToShow.Length; CharParticle makeparticle = new CharParticle(new BCPoint(RowBounds.Left + XOffset + x, RowBounds.Top + RowBounds.Height / 2), new BCPoint(0, -0.05f), Color.Red, CharsToShow[i].ToString()); makeparticle.TTL = 1500; //makeparticle.Decay = new BCPoint(0.5f, 0.5f); MakeParticles.Add(makeparticle); Lines = Lines > 4 ? Lines = 4:Lines; if (Lines >= 4) { makeparticle.ColorCalculatorFunction = LineFuncs[Lines - 1]; } else { makeparticle.Color = new Color[] { Color.Red, Color.Green, Color.Yellow }[Lines - 1]; } lock (_BaseState.TopParticles) { _BaseState.TopParticles.AddRange(MakeParticles); } } }
void HandleOnParticleCompletedEvent(BaseParticle particle) { baseParticlePool.Remove(particle); Destroy(particle.gameObject); }
//------------------------------------------------------------------------- public void init() { mTransform = transform; mParticleSystem = GetComponent<ParticleSystem>(); mBaseParticle = gameObject.GetComponent<BaseParticle>(); if (mBaseParticle == null) { mBaseParticle = gameObject.AddComponent<NullParticle>(); } }