public void SetupGib(Vector Position, Vector Velocity) { this.velocity = Velocity; this.SetPosition(Position); this.dieTime = OwningWorld.CurrentTime() + (float)CMath.Rand.NextDouble() * 5f + 2; this.startTime = OwningWorld.CurrentTime(); }
public void SetupNoise(float startNoiseAmt, float falloffTime) { startNoise = startNoiseAmt; falloff = falloffTime; this.startTime = OwningWorld.CurrentTime(); }
private void OnShoot() { Vector bulletVel = new Vector(0, 1f).Rotate(rotation - (float)Math.PI / 2f) * 2000f; this.OwningWorld.Create <Bullet>().SetupBullet(this.Position, bulletVel); lastShoot = OwningWorld.CurrentTick(); }
public void SetupBullet(Vector Position, Vector Velocity) { this.velocity = Velocity; this.SetPosition(Position); this.spawnTime = OwningWorld.CurrentTime(); this.lifeTime = 5f; }
public override void Think(float curTime, float deltaTime) { SetPosition(this.Position.X + velocity.X, this.Position.Y + velocity.Y); if (dieTime < OwningWorld.CurrentTime()) { this.Destroy(); } }
public override Vector[] Draw(float curTime, out int length) { int numPoints = (int)(15 * (1 - (OwningWorld.CurrentTime() - spawnTime) / lifeTime)); numPoints = Math.Max(numPoints, 0); Vector[] p = Render.DrawLine(this.Position, this.Position - this.velocity * 0.05f, numPoints); length = p.Length; return(p); }
public void Explode() { for (int i = 0; i < 8; i++) { Vector away = new Vector(1, 0).Rotate((float)((i / 4f - 1f) * Math.PI * 2 + CMath.Rand.NextDouble() * 2f)); AsteroidGibs gib = OwningWorld.Create <AsteroidGibs>(); gib.SetupGib(this.Position, away * (float)(CMath.Rand.NextDouble() * 2 + 0.1f)); } OwningWorld.Create <Noise>().SetupNoise(200, 0.2f); explodeTime = OwningWorld.CurrentTime(); //this.Destroy(); }
public override void Think(float curTime, float deltaTime) { float noiseLeft = CMath.Lerp(1 - (startTime + falloff - OwningWorld.CurrentTime()) / falloff, startNoise, 0); Console.WriteLine(noiseLeft); noiseLeft = Math.Max(noiseLeft, 0); OwningWorld.SetNoise(noiseLeft); if (noiseLeft <= 0) { this.Destroy(); } }
public override void Think(float curTime, float deltaTime) { SetPosition(this.Position + velocity * deltaTime); Asteroid[] asses = OwningWorld.GetByType <Asteroid>(); foreach (Asteroid ass in asses) { if (ass.Within(this.Position) && !ass.MarkedForDelete && !ass.Exploding) { ass.Explode(); this.Destroy(); break; } } if (OwningWorld.CurrentTime() - spawnTime > lifeTime) { this.Destroy(); } }
public override Vector[] Draw(float curTime, out int length) { Vector front, backUp, backDown; front = backUp = backDown = Vector.Zero; getRotatedPoints(out front, out backUp, out backDown); length = 0; if (OwningWorld.CurrentTick() % 2 == 0) { Array.Copy(Render.DrawCircle(this.Position, 20, 20), 0, samplePointBuffer, length, 20); length += 20; } //else if { Vector[] points = Render.DrawTri(front, backUp, backDown, 60); //60 Array.Copy(points, 0, samplePointBuffer, 0, points.Length); length = points.Length; } if (IsBoosting()) { Vector Booster = (backUp + backDown) * 0.5f; Vector[] points = Render.DrawLine(Booster, Booster - new Vector(1, 0).Rotate(rotation) * 30f, 10); for (int i = 0; i < points.Length; i++) { points[i] += new Vector(-((float)CMath.Rand.NextDouble() * 100f - 40f), (float)CMath.Rand.NextDouble() * 20 - 10f).Rotate(rotation); } Array.Copy(points, 0, samplePointBuffer, length, points.Length); length += points.Length; } return(samplePointBuffer); }
private float getRadius() { return((OwningWorld.CurrentTime() - startTime / (dieTime - startTime)) * 25); }
public override void Think(float curTime, float deltaTime) { if (Interop.IsKeyDown(Keys.Space)) { if (!wasPressed) { OnShoot(); } wasPressed = true; } else { wasPressed = false; } float thrust = 0; if (Interop.IsKeyDown(Keys.Up) || Interop.IsKeyDown(Keys.W)) { thrust += 1; } if (Interop.IsKeyDown(Keys.Down) || Interop.IsKeyDown(Keys.S)) { thrust -= 1; } thrust *= 7; if (IsBoosting()) { thrust += 20; } else if (velocity.Length() > 1500f) { thrust = 0f; } float spin = 0; if (Interop.IsKeyDown(Keys.Left) || Interop.IsKeyDown(Keys.A)) { spin += 1; } if (Interop.IsKeyDown(Keys.Right) || Interop.IsKeyDown(Keys.D)) { spin -= 1; } spin *= 5; rotationVelocity += spin * deltaTime; rotation = (rotation + rotationVelocity * deltaTime) % 360; velocity += new Vector(0, thrust).Rotate(rotation - (float)Math.PI / 2f); //Apply dampening float dampen = thrust != 0 ? 0.9999f : 0.994f; if (IsBoosting()) { dampen = 1f; } velocity = velocity * (thrust != 0 ? 0.9999f : 0.994f); rotationVelocity = rotationVelocity * 0.99f; SetPosition(this.Position + velocity * deltaTime); long tickDiff = OwningWorld.CurrentTick() - lastShoot; if (tickDiff > 100 || tickDiff % 16 == 0) { OwningWorld.SetTone((int)(this.velocity.Length() / 8 + 90)); } else { OwningWorld.SetTone(1000 - (int)tickDiff * 2); } OwningWorld.SetNoise(IsBoosting() ? 20f + this.velocity.Length() / 64 : 0f); if (this.velocity.Length() > 10000) { OwningWorld.SetNoise(0); } }