private IEnumerator ScrollSpeedFader(float to, float duration, FadingType type) { float start = _scrollingSpeed; float t = 0; while (t < duration) { float tn = t / duration; switch (type) { case FadingType.LINEAR: _scrollingSpeed = Maths.Lerp(start, to, tn); break; case FadingType.SMOOTH_STEP: _scrollingSpeed = Maths.Lerp(start, to, Maths.SmoothStep(0, 1, tn)); break; case FadingType.FADE_IN: _scrollingSpeed = Maths.Lerp(start, to, Maths.EaseIn(tn)); break; case FadingType.FADE_OUT: _scrollingSpeed = Maths.Lerp(start, to, Maths.EaseOut(tn)); break; } t += Program.UpdateTime.DeltaTime; yield return(null); } _scrollingSpeed = to; _fade = null; }
public void Update(float delta) { _fade?.MoveNext(); delta *= _scrollingSpeed; _offsetPosHills1 += delta * 25; _offsetPosHills2 += delta * 20; _offsetPosStars += delta * 10; _offsetPosMoon += delta * 9; float plrPos = Maths.InverseLerp(Player.MIN_Y, Player.MAX_Y, Program.Player.Position.y); _yPosHills1 = Maths.Lerp(11, 4, plrPos); _yPosHills2 = Maths.Lerp(7, 1, plrPos); _yPosStars = Maths.Lerp(-5, -20, plrPos); if (_offsetPosHills1 >= SIZE_HILL) { _offsetPosHills1 -= SIZE_HILL; } if (_offsetPosHills2 >= SIZE_HILL) { _offsetPosHills2 -= SIZE_HILL; } if (_offsetPosStars >= SIZE_HILL) { _offsetPosStars -= SIZE_HILL; } if (_offsetPosMoon >= 200) { _offsetPosMoon -= 200; } for (int i = 0; i < BG_COUNT; i++) { float rel = -SIZE_HILL + i * SIZE_HILL; _hills1[i].SetPosition(new Vector2(rel - _offsetPosHills1, _yPosHills1)); _hills2[i].SetPosition(new Vector2(rel - _offsetPosHills2 + _offset2, _yPosHills2)); _stars[i].SetPosition(new Vector2(rel - _offsetPosStars, _yPosStars)); if (i == 0) { _moon[i].Spawn(new Vector2(90 - _offsetPosMoon, _yPosStars - 12), Vector2.zero); } } }
protected override IEnumerator DyingSequence() { for (int i = 0; i < _lasers.Length; i++) { _lasers[i].Despawn(true); } StopCoroutine(_bulletPatterns); CanCollide = false; Player.MAX_X = 77; int maxExplosions = 48; int explosionsPerTickMin = 4; int explosionsPerTickMax = 16; float explosionInterval = 0.125f; float explosionIntervalTo = 0.0015f; Vector2 min = Collider.bounds.min - Vector2.one * 10f; Vector2 max = Collider.bounds.max + Vector2.one * 10f; Random rng = new Random(); for (int i = 0; i < maxExplosions; i++) { for (int j = 0; j < rng.Next(explosionsPerTickMin, explosionsPerTickMax + 1); j++) { Effect fx = _deathFX.Get() as Effect; fx.Spawn(new Vector2(Maths.Lerp(min.x, max.x, (float)rng.NextDouble()), Maths.Lerp(min.y, max.y, (float)rng.NextDouble())), Vector2.zero); fx.Setup(0, 1000 + i + j, 1.5f, true); } yield return(Program.UpdateTime.WaitForSeconds(Maths.Lerp(explosionInterval, explosionIntervalTo, Maths.EaseIn(i / (maxExplosions - 1.0f))))); } for (int j = 0; j < 48; j++) { Effect fx = _deathFX.Get() as Effect; fx.Spawn(new Vector2(Maths.Lerp(min.x, max.x, (float)rng.NextDouble()), Maths.Lerp(min.y, max.y, (float)rng.NextDouble())), Vector2.zero); fx.Setup(0, 1500 + j, 1.25f, true); } _isVisible = false; yield return(Program.UpdateTime.WaitForSeconds(2.0f)); bool newHigh = Player.ValidateScore(Program.Difficulty, Program.Player.Score); yield return(WarningScreen(newHigh ? _animWonHI : _animWon)); yield return(Program.UpdateTime.WaitForSeconds(2.0f)); Despawn(true); }
public override void Update(float deltaTime) { base.Update(deltaTime); if (_isDying) { return; } if (followPlayer) { float plrPos = Maths.InverseLerp(Player.MIN_Y, Player.MAX_Y, Program.Player.Position.y); Position = Vector2.SmoothDamp(Position, new Vector2(55, Maths.Lerp(-6, 6, plrPos)), ref _velocity, _smoothTime, deltaTime); } Player.MAX_X = CanCollide ? Position.x - 20.0f : 77; UpdateLasers(deltaTime); }
public BulletPattern(int layers, int[] points, int[] bulletCounts, float[] arcs, float[][] radii, bool[][] activeBullets, float[][] anglePerBullet, float[][] baseSpds, float[][] tgtSpeeds, float[][] layerOffset, bool close = true, float[] angleOffset = null) { if (angleOffset == null || angleOffset.Length < 1) { angleOffset = new float[] { 0 }; } _layers = Math.Max(layers, 1); _bulletCount = 0; if (points == null | points.Length < 1) { points = new int[1] { 2 }; } else { for (int i = 0; i < points.Length; i++) { points[i] = Math.Max(points[i], 2); } } _bulletEnabled = activeBullets; _positions = new Vector2[_layers][]; _directions = new Vector2[_layers][]; _speeds = new float[_layers][]; _bulletsPerLayer = new int[_layers]; float layerL = _layers < 3 ? 1.0f : _layers - 1.0f; _layers = Math.Max(layers, 1); for (int i = 0; i < _layers; i++) { float ln = i / layerL; int pointCount = points[i % points.Length]; float arc = arcs[i % arcs.Length]; float halfArc = arc == 360 ? 0 : arc * 0.5f; float anglePerB = arc / pointCount; Vector2 dir = new Vector2(0, 1).Rotate(halfArc - (arc == 360 ? 0 : anglePerB * 0.5f) + angleOffset[i % angleOffset.Length]); Vector2[] verts = new Vector2[pointCount]; Vector2[] vertDirs = new Vector2[pointCount]; float[] vertSpeeds = new float[pointCount]; float[] _radii = radii[i % radii.Length]; float[] _spds = baseSpds[i % baseSpds.Length]; float[] _tgtSpds = tgtSpeeds[i % tgtSpeeds.Length]; float[] _lrOffsets = layerOffset[i % layerOffset.Length]; float[] _angles = anglePerBullet[i % anglePerBullet.Length]; for (int j = 0; j < pointCount; j++) { float offset = _lrOffsets[j % _lrOffsets.Length]; float spd = _spds[j % _spds.Length]; float tgtSpd = _tgtSpds[j % _tgtSpds.Length]; Vector2 point = dir.Rotate(-anglePerB * j + (_angles[j % _angles.Length] * i)); vertDirs[j] = point; verts[j] = point * (_radii[j % _radii.Length] + Maths.Lerp(0.0f, offset, ln)); vertSpeeds[j] = Maths.Lerp(spd, tgtSpd, ln); } int bulletCountsLayer = bulletCounts[i % bulletCounts.Length]; int ii = 0; for (int j = 0; j < pointCount; j++) { ii++; if (j == 1 & (pointCount == 2 | !close)) { break; } for (int k = 1; k < bulletCountsLayer; k++) { ii++; } } _bulletsPerLayer[i] = ii; _positions[i] = new Vector2[ii]; _directions[i] = new Vector2[ii]; _speeds[i] = new float[ii]; ii = 0; for (int j = 0; j < pointCount; j++) { _directions[i][ii] = vertDirs[j]; _positions[i][ii] = verts[j]; _speeds[i][ii] = vertSpeeds[j]; ii++; if (j == 1 & (pointCount == 2 | !close)) { break; } int nextI = j == pointCount - 1 ? 0 : j + 1; for (int k = 1; k < bulletCountsLayer; k++) { float n = k / (float)bulletCountsLayer; _directions[i][ii] = Vector2.Lerp(vertDirs[j], vertDirs[nextI], n); _positions[i][ii] = Vector2.Lerp(verts[j], verts[nextI], n); _speeds[i][ii] = Maths.Lerp(vertSpeeds[j], vertSpeeds[nextI], n); ii++; } } _bulletCount += ii; } }
public BulletPattern(int layers, int[] bulletCounts, float[] arcs, float[][] radii, bool[][] activeBullets, float[][] anglePerBullet, float[][] baseSpds, float[][] tgtSpeeds, float[][] layerOffset, float[] angleOffset = null) { if (angleOffset == null || angleOffset.Length < 1) { angleOffset = new float[] { 0 }; } _layers = Math.Max(layers, 1); _bulletsPerLayer = bulletCounts; int l = _bulletsPerLayer.Length; if (l < layers) { Array.Resize(ref _bulletsPerLayer, layers); for (int i = l; i < layers; i++) { _bulletsPerLayer[i] = _bulletsPerLayer[l - 1]; } } float layerL = _layers < 3 ? 1.0f : _layers - 1.0f; _bulletEnabled = activeBullets; _positions = new Vector2[_layers][]; _directions = new Vector2[_layers][]; _speeds = new float[_layers][]; _bulletCount = 0; bool[] enabled; for (int i = 0; i < _layers; i++) { enabled = _bulletEnabled[i % _bulletEnabled.Length]; float ln = i / layerL; int bulletCount = _bulletsPerLayer[i]; float arc = arcs[i % arcs.Length]; float halfArc = arc == 360 ? 0 : arc * 0.5f; float anglePerB = arc / bulletCount; Vector2 dir = new Vector2(0, 1).Rotate(halfArc - (arc == 360 ? 0 : anglePerB * 0.5f) + angleOffset[i % angleOffset.Length]); int bulletCountOne = bulletCount; _positions[i] = new Vector2[bulletCountOne]; _directions[i] = new Vector2[bulletCountOne]; _speeds[i] = new float[bulletCountOne]; float[] _radii = radii[i % radii.Length]; float[] _spds = baseSpds[i % baseSpds.Length]; float[] _tgtSpds = tgtSpeeds[i % tgtSpeeds.Length]; float[] _lrOffsets = layerOffset[i % layerOffset.Length]; float[] _angles = anglePerBullet[i % anglePerBullet.Length]; for (int j = 0; j < bulletCountOne; j++) { if (enabled[j % enabled.Length]) { _bulletCount++; } float offset = _lrOffsets[j % _lrOffsets.Length]; float spd = _spds[j % _spds.Length]; float tgtSpd = _tgtSpds[j % _tgtSpds.Length]; _directions[i][j] = dir.Rotate(-anglePerB * j + (_angles[j % _angles.Length] * i)); _positions[i][j] = _directions[i][j] * (_radii[j % _radii.Length] + Maths.Lerp(0.0f, offset, ln)); _speeds[i][j] = Maths.Lerp(spd, tgtSpd, ln); } } }
private IEnumerator WarningScreen(Animation anim) { Vector2 startPos = new Vector2(0, -80); Vector2 endPos = new Vector2(0, -2); _warning.Animation = anim; _warning.Spawn(startPos, Vector2.zero); yield return(Program.UpdateTime.WaitForSeconds(2.0f)); float t = 0; float duration = 0.5f; float delta; while (t < duration) { delta = Program.UpdateTime.DeltaTime; float n = t / duration; _warning.Update(delta); _warning.Position = Vector2.Lerp(startPos, endPos, Maths.SmoothStep(0.0f, 1.0f, n)); t += delta; yield return(null); } startPos = endPos; _warning.Position = startPos; endPos = new Vector2(0, 10); duration = 2.5f; t = 0; while (t < duration) { delta = Program.UpdateTime.DeltaTime; float n = t / duration; _warning.Update(delta); _warning.Position = Vector2.Lerp(startPos, endPos, n); t += delta; yield return(null); } startPos = endPos; _warning.Position = startPos; endPos = new Vector2(0, 90); duration = 2.0f; t = 0; float multiplier = 1.0f; while (t < duration) { delta = Program.UpdateTime.DeltaTime; float n = t / duration; _warning.Update(delta); _warning.Position = Vector2.Lerp(startPos, endPos, n); t += delta * multiplier; multiplier = Maths.Lerp(1.0f, 5.0f, n); yield return(null); } _warning.Despawn(false); }