public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { if (cycleInception == 0f) cycleInception = (float)totalMilliseconds; float age = (float)(totalMilliseconds - cycleInception); if (age < particle.Lifespan) { if (age >= CycleLength) { ScaleUp = !ScaleUp; cycleInception = (float) totalMilliseconds; } float cycleStage = age/CycleLength; if (!ScaleUp) { currentScale.X = MathHelper.Lerp(MaximumScale.X, MinimumScale.X, cycleStage); currentScale.Y = MathHelper.Lerp(MaximumScale.Y, MinimumScale.Y, cycleStage); } else { currentScale.X = MathHelper.Lerp(MinimumScale.X, MaximumScale.X, cycleStage); currentScale.Y = MathHelper.Lerp(MinimumScale.Y, MaximumScale.Y, cycleStage); } } particle.Scale = currentScale; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { if (ColorList.Count > 1) { if (cycleInception == 0f) cycleInception = (float) totalMilliseconds; var age = (float) (totalMilliseconds - cycleInception); if (age >= CycleLength) { SetColorIndices(); cycleInception = (float) totalMilliseconds; } var cycleAge = age/CycleLength; var r = (int) MathHelper.Lerp(ColorList[currentColorIndex].R, ColorList[nextColorIndex].R, cycleAge); var g = (int) MathHelper.Lerp(ColorList[currentColorIndex].G, ColorList[nextColorIndex].G, cycleAge); var b = (int) MathHelper.Lerp(ColorList[currentColorIndex].B, ColorList[nextColorIndex].B, cycleAge); particle.Color = new Microsoft.Xna.Framework.Color((byte) r, (byte) g, (byte) b); } else particle.Color = ColorList[0]; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { int r = (int)MathHelper.Lerp(StartColor.R, EndColor.R, particleAge); int g = (int)MathHelper.Lerp(StartColor.G, EndColor.G, particleAge); int b = (int)MathHelper.Lerp(StartColor.B, EndColor.B, particleAge); particle.Color = new Microsoft.Xna.Framework.Color((byte)r, (byte)g, (byte)b); }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { GravityPoint.Update(particleAge, totalMilliseconds, elapsedSeconds, particle); Vector2 distance = Vector2.Subtract(GravityPoint.Position, particle.Position); if (distance.LengthSquared() < RemovalRadius * RemovalRadius) particle.IsAlive = false; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { Vector2 particleVelocity = particle.Velocity; if (particle.ProjectedPosition.Y < Container.Top || particle.ProjectedPosition.Y > Container.Bottom) particleVelocity.Y *= -bounce; else if (particle.ProjectedPosition.X < Container.Left || particle.ProjectedPosition.X > Container.Right) particleVelocity.X *= -bounce; particle.Velocity = particleVelocity; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { Vector2 distance = Vector2.Subtract(Position, particle.Position); if (distance.LengthSquared() < Radius * Radius) { Vector2 force = Vector2.Normalize(distance); force = Vector2.Multiply(force, Strength); force = Vector2.Multiply(force, (float) elapsedSeconds); particle.Affect(ref force); } }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { float age = (float)(totalMilliseconds - particle.InceptionTime); if (age < particle.Lifespan) { currentScale.X = MathHelper.Lerp(StartScale.X, EndScale.X, age / particle.Lifespan); currentScale.Y = MathHelper.Lerp(StartScale.Y, EndScale.Y, age / particle.Lifespan); } else currentScale = EndScale; particle.Scale = currentScale; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { if (cycleInception == 0f) cycleInception = (float) totalMilliseconds; var age = (float) (totalMilliseconds - cycleInception); if (age >= CycleLength) { FadeIn = !FadeIn; cycleInception = (float) totalMilliseconds; } var cycleAge = age/CycleLength; particle.Alpha = FadeIn ? MathHelper.Lerp(0f, 1f, cycleAge) : MathHelper.Lerp(1f, 0f, cycleAge); }
public void resolveInterpenetration(float dt) { Particle2D firstParticle = firstContact.GetComponent <Particle2D>(); Particle2D secondParticle = secondContact.GetComponent <Particle2D>(); if (penetration <= 0.0f) { return; } float totalInverseMass = firstParticle.getInverseMass(); if (secondParticle) { totalInverseMass += secondParticle.getInverseMass(); } if (totalInverseMass <= 0) //infinite mass objects { return; } Vector3 movePerIMass = contactNormal * (penetration / totalInverseMass); firstMove = movePerIMass * firstParticle.getInverseMass(); if (secondParticle) { secondMove = movePerIMass * -secondParticle.getInverseMass(); } else { secondMove = Vector3.zero; } Vector3 newPos = firstContact.transform.position + firstMove; firstContact.transform.position = newPos; if (secondParticle) { newPos = secondContact.transform.position + secondMove; secondContact.transform.position = newPos; } }
void Integrate(GameObject physicsObject, float dt) { Particle2D ParticleData = physicsObject.GetComponent <Particle2D>(); physicsObject.transform.position += new Vector3((ParticleData.Velocity.x * dt), (ParticleData.Velocity.y * dt), 0.0f); Vector2 resultingAcc = ParticleData.Acceleration; if (!ParticleData.shouldIgnoreForces) { resultingAcc += ParticleData.AccumulatedForces * (float)(ParticleData.Mass / 1.0); } ParticleData.Velocity += (resultingAcc * dt); float damping = Mathf.Pow((float)ParticleData.DampingConstant, dt); ParticleData.Velocity *= damping; ParticleData.AccumulatedForces = Vector2.zero; }
//Integrate Particle2D public void integrate(GameObject particleObj, double dt) { //Variables particle = particleObj.GetComponent <Particle2D>(); particleObj.transform.position += new Vector3((particle.velocity.x * (float)dt), (particle.velocity.y * (float)dt), 0.0f); Vector2 resultingAcc = particle.acceleration; //Calculate if (!particle.ignoreForces) { resultingAcc += (particle.accumulatedForces * (float)(particle.mass / 1.0)); } particle.velocity += (resultingAcc * (float)dt); float damping = (float)Math.Pow((float)particle.dampingCost, (float)dt); particle.velocity *= damping; particle.accumulatedForces = Vector2.zero; }
static public void Create(float rotation, Vector3 position) { GameObject particle = new GameObject(); particle.name = "Particle2D"; Particle2D p = particle.AddComponent <Particle2D>(); p.speed = 0.1f; p.rotation = rotation; particle.transform.localScale = new Vector3(Random.Range(5, 15), Random.Range(5, 15f), 1); particle.transform.rotation = Quaternion.Euler(new Vector3(0, 0, rotation)); particle.transform.position = position; SpriteRenderer spriteRenderer = particle.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = Resources.Load <Sprite>("Sprites/Flare"); spriteRenderer.material = new Material(Shader.Find("Particles/Additive")); }
public static HullCollision CircleCircleCollision(CircleHull circleHull1, CircleHull circleHull2) { // *IMPORTANT* for circle and square the collision only wirks with obejct1 - object 2 and not viceversa, must be a prob in clollision resolution Vector3 c1Offset = circleHull1.offset; Vector3 c2Offset = circleHull2.offset; Vector3 range = (circleHull2.transform.position + c2Offset) - (circleHull1.transform.position + c1Offset); // make sure offsets arent screwing things up float overlap = (circleHull2.radius + circleHull1.radius) - range.magnitude; HullCollision col = new HullCollision(); col.a = circleHull1; col.b = circleHull2; col.penetration = range * overlap; HullCollision.Contact con0 = new HullCollision.Contact(); con0.point = (range.normalized * circleHull1.radius); con0.point += new Vector3(circleHull1.transform.position.x, circleHull1.transform.position.y); con0.normal = range.normalized; con0.restitution = Mathf.Min(circleHull1.restitution, circleHull2.restitution); col.contacts[0] = con0; Particle2D c1 = circleHull1.GetComponentInParent <Particle2D>(); Particle2D c2 = circleHull2.GetComponentInParent <Particle2D>(); Vector3 closingVel = c2.velocity - c1.velocity; // started as c1 -c2 col.closingVelocity = closingVel; if (overlap > 0) { col.status = true; return(col); } else { col.status = false; return(col); } }
public override void UpdatePND() { Collider2D[] colliders = Physics2D.OverlapCircleAll(Pos(), ReGra); nearbyParticles = new Particle2D[colliders.Length]; WEIGHTS = new double[colliders.Length]; nearbyParticles[0] = this; PND = 0; for (int i = 0, j = 1; j < nearbyParticles.Length; i++) { if (colliders[i].gameObject.name.Equals(this.gameObject.name)) { continue; } nearbyParticles[j] = colliders[i].GetComponent <Particle2D>(); WEIGHTS[j] = weightKernel((nearbyParticles[j].Pos() - this.Pos()).magnitude, ReGra); PND += WEIGHTS[j]; j++; } }
public void Integrate(GameObject particleGameObj, float dt) { Particle2D objectData = particleGameObj.GetComponent <Particle2D>(); Vector3 positionChange = objectData.velocity * dt; objectData.transform.position += positionChange; Vector2 resultingAcc = objectData.acceleration; if (!objectData.shouldIgnoreForces) { resultingAcc += objectData.accumulatedForces * objectData.inverseMass; } objectData.velocity += (resultingAcc * dt); //Debug.Log(objectData.velocity); float damping = Mathf.Pow(objectData.dampingConstant, dt); objectData.velocity *= damping; objectData.accumulatedForces = new Vector2(0.0f, 0.0f); }
public Vector2 Integrate(Vector2 loc, GameObject obj, bool shouldIgnoreForces) { Particle2D particle = obj.GetComponent <Particle2D>(); Vector2 newLoc = loc; newLoc += (particle.Velocity * Time.deltaTime); Vector2 resultingAcc = particle.Acceleration; if (!shouldIgnoreForces)//accumulate forces here { resultingAcc += particle.AccumulatedForces * (1.0f / particle.Mass); } particle.Velocity += (resultingAcc * Time.deltaTime); float damping = Mathf.Pow(particle.DampingConstant, Time.deltaTime); particle.Velocity *= damping; clearAccumulatedForces(particle); return(newLoc); }
void HandlePlanetaryCollision(Particle2D obj1, Particle2D obj2) { Vector2 normal = (obj1.mpPhysicsData.pos - obj2.mpPhysicsData.pos).normalized; float seperationVelocity = coeffiientOfRestitution * Vector2.Dot(obj1.mpPhysicsData.vel - obj2.mpPhysicsData.vel, normal); if (seperationVelocity > 0) { return; } float newSepVel = -seperationVelocity * coeffiientOfRestitution; float deltaVel = newSepVel - seperationVelocity; float totalInverseMass = obj1.mpPhysicsData.inverseMass + obj2.mpPhysicsData.inverseMass; float impulse = deltaVel / totalInverseMass; Vector2 impulsePerIMass = normal * impulse; obj1.mpPhysicsData.vel += impulsePerIMass * obj1.mpPhysicsData.inverseMass; obj2.mpPhysicsData.vel += impulsePerIMass * -obj2.mpPhysicsData.inverseMass; }
void Update() { for (int i = 0; i < ParticlesCount; i++) { Particle2D particle = particles[i]; Vector3 position = particle.position; int x = Mathf.FloorToInt(position.x * (resolution - 1)); int y = Mathf.FloorToInt(position.y * (resolution - 1)); particle.ApplyForce(field[x, y] * 0.1f); particle.Update(); if (particle.position.x <= 0 || particle.position.x >= 1f || particle.position.y <= 0 || particle.position.y >= 1f) { particle.position = NewPosition(); } x = Mathf.FloorToInt(particle.position.x * (width - 1)); y = Mathf.FloorToInt(particle.position.y * (height - 1)); texture.SetPixel(x, y, Color.white); } texture.Apply(); // UpdateFlowField(); }
void shootSpring() { float speed = 10.0f; Vector2 gravity = new Vector2(0.0f, -6.0f); GameObject proj = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation); Particle2D temp = proj.GetComponent <Particle2D>(); temp.Velocity = transform.right * speed; temp.Acceleration = gravity; temp.Mass = 1.0f; GameManager.Instance.mObjects.Add(temp); GameObject proj1 = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation); temp = proj1.GetComponent <Particle2D>(); temp.Velocity = transform.right * speed; temp.Acceleration = gravity; temp.Mass = 3.0f; GameManager.Instance.mObjects.Add(temp); SpringForceGenerator springGenerator = new SpringForceGenerator(proj, proj1, 1.0f, 50.0f, true); GameManager.Instance.mForceManager.addForceGenerator(springGenerator); }
void SliceEvent(Slice2D slice) { Slicer2DParticlesManager.Instantiate(); foreach (List <Vector2D> pointList in slice.slices) { foreach (Pair2D p in Pair2D.GetList(pointList)) { Particle2D firstParticle = Particle2D.Create(Random.Range(0, 360), new Vector3((float)p.A.x, (float)p.A.y, posZ)); Slicer2DParticlesManager.particlesList.Add(firstParticle); Particle2D lastParticle = Particle2D.Create(Random.Range(0, 360), new Vector3((float)p.B.x, (float)p.B.y, posZ)); Slicer2DParticlesManager.particlesList.Add(lastParticle); Vector2 pos = p.A.ToVector2(); while (Vector2.Distance(pos, p.B.ToVector2()) > 0.5f) { pos = Vector2.MoveTowards(pos, p.B.ToVector2(), 0.35f); Particle2D particle = Particle2D.Create(Random.Range(0, 360), new Vector3(pos.x, pos.y, posZ)); Slicer2DParticlesManager.particlesList.Add(particle); } } } }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { var amount = Strength*(totalMilliseconds/1000); particle.Rotation = (float) amount; }
public abstract void applyForce(Particle2D particle, float dt);
public static bool DetectCollition(Particle2D obj0, Particle2D obj1) { float distance = (obj0.data.position - obj1.data.position).magnitude; return(distance <= 1); }
public void DeleteParticle(Particle2D par) { particlesToDelete.Add(par); ClearOutDeadParticles(); }
void Start() { P2D = GetComponent <Particle2D>(); }
// Import simulation state - consider special Particle2D constructor // TODO separate into smaller functions for readability public void Import(string state) { // Parse state; add particles/load scenario t_ = 0; particles_.Clear(); string[] tokens = state.Split(); int i = 0; while (i < tokens.Length) { switch (tokens[i]) { // TODO check for particles with missing/invalid position, velocity, mass, color // also check for other forms of bad input case "NEW_P": int j = i + 1; bool ok = true; Particle2D particle = new Particle2D(); while (ok) { switch (tokens[j]) { case "POS": particle.pos_ = new Vector2(float.Parse(tokens[j + 1]), float.Parse(tokens[j + 2])); j++; break; case "V": particle.v_ = new Vector2(float.Parse(tokens[j + 1]), float.Parse(tokens[j + 2])); j++; break; case "M": particle.m_ = float.Parse(tokens[j + 1]); j++; break; case "D": particle.d_ = float.Parse(tokens[j + 1]); j++; break; case "P": particle.p_ = float.Parse(tokens[j + 1]); j++; break; case "F": particle.f_ = new Vector2(float.Parse(tokens[j + 1]), float.Parse(tokens[j + 2])); j++; break; case "RGB": particle.color_ = new Color(float.Parse(tokens[j + 1]), float.Parse(tokens[j + 2]), float.Parse(tokens[j + 3])); j++; break; case "END_P": ok = false; j++; break; default: j++; break; } } particles_.AddLast(particle); i++; break; case "TIME": t_ = float.Parse(tokens[i + 1]); i++; break; case "SMOOTHING_DISTANCE": h_ = float.Parse(tokens[i + 1]); UpdateKernelFactors(h_); i++; break; case "GRAVITY": g_ = float.Parse(tokens[i + 1]); i++; break; case "SCENARIO": //TODO additional presets i++; break; case "DAMBREAK": case "RECT_FILL": // demo scenario generator int x = int.Parse(tokens[i + 1]); int y = int.Parse(tokens[i + 2]); int w = int.Parse(tokens[i + 3]); int h = int.Parse(tokens[i + 4]); int seed = int.Parse(tokens[i + 5]); Random.InitState(seed); Color water_color = new Color(1f, 1f, 1f); int spacing = Mathf.Max(Mathf.RoundToInt(h_ / 2), 1); for (int n = 0; n < w; n += spacing) { for (int m = 0; m < h; m += spacing) { Particle2D particle_d = new Particle2D(); particle_d.pos_ = new Vector2(x + n + Random.Range(-0.3f, 0.3f), y + m + Random.Range(-0.3f, 0.3f)); particle_d.v_ = new Vector2(Random.Range(-1, 1f), Random.Range(-1f, 0.5f)); particle_d.m_ = 5000; particle_d.color_ = water_color; particles_.AddLast(particle_d); } } i++; break; default: i++; break; } } }
public void InstantiateVariables(Particle2D obj1, Particle2D obj2, float length) { mObject1 = obj1; mObject2 = obj2; mLength = length; }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { particle.Alpha = FadeIn ? MathHelper.Lerp(0f, 1f, particleAge) : MathHelper.Lerp(1f, 0f, particleAge); }
internal abstract void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle);
void Start() { particle = GetComponent <Particle2D>(); }
public void AddParticle(Particle2D particle) { particles.Add(particle); }
void Start() { stageDimensions = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0)); particle = GetComponent <Particle2D>(); }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { particle.Velocity *= friction; }
// Start is called before the first frame update void Start() { particle = gameObject.GetComponent <Particle2D>(); particle.velocity = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)); }
public void Update(float particleAge, double totalMilliseconds, double elapsedSeconds, Particle2D particle) { var deltaGrav = Vector2.Multiply(Gravity, (float) elapsedSeconds); particle.Affect(ref deltaGrav); }
public void AddParticle(Particle2D p) { particles_.AddLast(p); }
void Start() { mObj0 = GetComponent <Particle2D>(); }
public PlanetaryForceGenerator(Particle2D object1) { universalGavitationalConstant = 6.6740f * Mathf.Pow(10.0f, powerOfConstant); mPlanet = object1; }
private void CommandSentEventHandler(object Sender, string Command) { if (Tools.RegEx.QuickTest(Command, "^(quit|exit)$") == true) { Exit(); } else if (Tools.RegEx.QuickTest(Command, "^ship *stop$") == true) { cPlayerShip.cSpeedX = 0; cPlayerShip.cSpeedY = 0; cDevConsole.AddText("Ship speed set to 0"); } else if (Tools.RegEx.QuickTest(Command, "^ship *center$") == true) { cPlayerShip.Top = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height) / 2 - (cPlayerShip.Height / 2); cPlayerShip.Left = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width) / 2 - (cPlayerShip.Width / 2); cDevConsole.AddText("Ship position set to [X=" + cPlayerShip.Left + ", Y=" + cPlayerShip.Width + "]"); } else if (Tools.RegEx.QuickTest(Command, "^ship *state$") == true) { cDevConsole.AddText("Ship Position [X=" + cPlayerShip.Top + ", Y=" + cPlayerShip.Left + "]"); cDevConsole.AddText(" Speed X=" + cPlayerShip.cSpeedX + " Y=" + cPlayerShip.cSpeedY); cDevConsole.AddText(" Size Width=" + cPlayerShip.Width + " Height=" + cPlayerShip.Height); } else if (Tools.RegEx.QuickTest(Command, "^fire *spread$") == true) { cDevConsole.AddText("Firing Spread"); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.628f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.314f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.314f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.628f, 10, Color.White); } else if (Tools.RegEx.QuickTest(Command, "^fire *multi-?(ple|shot)$") == true) { cDevConsole.AddText("Firing Multi-Shot"); Vector2 BulletOrigin, BulletOffset; BulletOrigin = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation, cPlayerShip.Width / 4); BulletOffset = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation + 1.570796f, cPlayerShip.Width / 5); //Adjust it so that it's relative to the top left screen corner BulletOrigin.Y += cPlayerShip.Top + (cPlayerShip.Height / 2); BulletOrigin.X += cPlayerShip.Left + (cPlayerShip.Height / 2); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + (BulletOffset.Y * 2) - 10, BulletOrigin.X + (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + BulletOffset.Y - 10, BulletOrigin.X + BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - 10, BulletOrigin.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - BulletOffset.Y - 10, BulletOrigin.X - BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - (BulletOffset.Y * 2) - 10, BulletOrigin.X - (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); } else if (Tools.RegEx.QuickTest(Command, "^new *asteroid$") == true) { cDevConsole.AddText("Spawning Asteroid"); cAsteroids.AddParticle(cTextureDict[Textures.Asteroid], cPlayerShip.Top + (cPlayerShip.Height / 2) - 50, cPlayerShip.Left + (cPlayerShip.Height / 2) - 50, 100, 100, cPlayerShip.cRotation - 0.628f, 2, Color.White); } else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*count\s*?$") == true) { cDevConsole.AddText("Current Asteroid Count: " + cAsteroids.ParticleList.Count); } else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*clear$") == true) { cDevConsole.AddText("Destroying all asteroids"); cAsteroids.ParticleList.Clear(); } else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(on|true|enable|1)\s*$") == true) { cDevConsole.AddText("Using mouse position to rotate ship"); cPlayerShip.MouseRotate = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(off|false|disable|0)\s*$") == true) { cDevConsole.AddText("Using arrow keys to rotate ship"); cPlayerShip.MouseRotate = false; } else if (Tools.RegEx.QuickTest(Command, @"^\s*(spawn|new)\s*hunter\s*$") == true) { cDevConsole.AddText("Spawning new hunter UFO"); Vector2 StartPos = new Vector2(-50, -50); CreateNewHunter(100, StartPos); } else if (Tools.RegEx.QuickTest(Command, @"^\s*(sparkles|particles)\s*$") == true) { Particle2D NewSparkle; Vector2 Speed; cDevConsole.AddText("Particle burst on player ship"); for (int Ctr = 0; Ctr < 25; Ctr++) { NewSparkle = new Particle2D(cGraphDevMgr.GraphicsDevice); NewSparkle.AlphaFade = true; NewSparkle.TimeToLive = 100 + (cRandom.NextDouble() * 1000); NewSparkle.Height = 10; NewSparkle.Width = 10; NewSparkle.TopLeft.X = cPlayerShip.Left + (cPlayerShip.Width / 2); NewSparkle.TopLeft.Y = cPlayerShip.Top + (cPlayerShip.Height / 2); NewSparkle.Image = cTextureDict[Textures.Bullet]; NewSparkle.Rotation = (float)(cRandom.NextDouble() * 6.2f); Speed = MGMath.CalculateXYMagnitude(NewSparkle.Rotation, (float)(cRandom.NextDouble() * 5)); NewSparkle.SpeedX = Speed.X; NewSparkle.SpeedY = Speed.Y; NewSparkle.Tint = Color.White; cSparkles.AddParticle(NewSparkle); } } else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(1|true|enable)\s*$") == true) { cDevConsole.AddText("Headlight mode enabled."); cHeadlightMode = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(0|false|disable)\s*$") == true) { cDevConsole.AddText("Headlight mode disabled."); cHeadlightMode = false; } else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(1|true|enable|on)\s*$") == true) { cDevConsole.AddText("Stats enabled."); cShowStats = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(0|false|disable|off)\s*$") == true) { cDevConsole.AddText("Stats disabled."); cShowStats = false; } else { cDevConsole.AddText("Unrecognized command: " + Command); } }
public void DeleteParticle(Particle2D particle) { particles.Remove(particle); }
void AddStyleToCollision(Particle2D obj1, Particle2D obj2) { bool obj1Smaller = obj1.mpPhysicsData.inverseMass > obj2.mpPhysicsData.inverseMass; Particle2D lesserObj = obj1Smaller ? obj1 : obj2; Particle2D greaterObj = obj1Smaller ? obj2 : obj1; float greaterMass = greaterObj.GetMass(); float lesserMass = lesserObj.GetMass(); if (lesserMass * ratioToIgnoreBreakage <= greaterMass) { greaterObj.AddMass(lesserMass); particlesToDelete.Add(lesserObj); } else if (1 - lesserMass / greaterMass < 1 / ratioToIgnoreBreakage) { greaterObj.AddMass(lesserMass); particlesToDelete.Add(lesserObj); greaterObj.mpPhysicsData.vel = (greaterObj.mpPhysicsData.vel + lesserObj.mpPhysicsData.vel).normalized * greaterObj.mpPhysicsData.vel.magnitude; Vector2 diff = greaterObj.mpPhysicsData.pos - lesserObj.mpPhysicsData.pos; Vector2 offset = -diff.normalized * greaterObj.radius / diff.magnitude; greaterObj.mpPhysicsData.pos += offset; return; } else { float proportion = (lesserMass / greaterMass); greaterObj.AddMass(lesserMass * (1 - proportion)); lesserObj.AddMass(-lesserMass * (1 - proportion)); if (piecesPlanetsBreakInto > 1) { GameObject[] newParts = new GameObject[piecesPlanetsBreakInto]; lesserMass = lesserObj.GetMass(); for (int i = 0; i < piecesPlanetsBreakInto; i++) { newParts[i] = Instantiate(lesserObj.gameObject, lesserObj.transform.position, lesserObj.transform.rotation); } float angleSpread = 180.0f / (piecesPlanetsBreakInto + 1); Vector2 oldVec = lesserObj.mpPhysicsData.vel; Vector2 newVel = new Vector2(Mathf.Cos(180) * oldVec.x - Mathf.Sin(180) * oldVec.y, Mathf.Sin(180) * oldVec.x + Mathf.Cos(180) * oldVec.y); for (int i = 0; i < piecesPlanetsBreakInto; i++) { Particle2D par = newParts[i].GetComponent <Particle2D>(); par.AddMass(-(lesserMass * (1 - 1.0f / piecesPlanetsBreakInto))); newVel = new Vector2(Mathf.Cos(angleSpread) * newVel.x - Mathf.Sin(angleSpread) * newVel.y, Mathf.Sin(angleSpread) * newVel.x + Mathf.Cos(angleSpread) * newVel.y); par.mpPhysicsData.vel = newVel; //* piecesPlanetsBreakInto; par.mpPhysicsData.pos += newVel.normalized * (1.0f / (Mathf.Cos(90 - (angleSpread / 2.0f)) / par.radius)); // par.radius/2); newParts[i].transform.position = par.mpPhysicsData.pos; newParts[i].GetComponent <Particle2D>().mpPhysicsData = par.mpPhysicsData; AddParticle(newParts[i].GetComponent <Particle2D>()); ForceManager.AddForceGenerator(new PlanetaryForceGenerator(newParts[i].GetComponent <Particle2D>())); } particlesToDelete.Add(lesserObj); } } }
// Start is called before the first frame update void Start() { thrust = GetComponent <Particle2D>(); hull = GetComponent <OBBHull>(); bulletPrefab = Resources.Load("Bullet") as GameObject; }
public Particle2DLink(GameObject obj1, GameObject obj2, float length) { particle1 = obj1.GetComponent <Particle2D>(); particle2 = obj2.GetComponent <Particle2D>(); mLength = length; }