Example #1
0
        public override IEnumerator Begin(ProjectileSpawner projectileSpawner)
        {
            yield return(WaitYieldInstruction.Create(_delay));

            while (true)
            {
                var degreesPerSpawn = 360 / _count;
                for (int r = 0; r < _count; r++)
                {
                    var a = degreesPerSpawn * r;
                    projectileSpawner.Spawn(Vector2Helper.FromAngle(MathHelper.ToRadians(a)));
                    yield return(WaitYieldInstruction.Create(_sequenceFrequencyInMS));
                }
                yield return(WaitYieldInstruction.Create(_frequencyInMS));
            }
        }
Example #2
0
        private IEnumerator HandleKnockback()
        {
            _isKnockingBack           = true;
            _gs.Player.GotHit         = false;
            _gs.Player.IsInvulnerable = true;
            _verticalSpeed            = -2;
            _horizontalSpeed          = _gs.Player.FacingDirection == Models.FacingDirection.Right ? -1 : 1;
            _grounded = false;
            while (!_grounded)
            {
                yield return(null);
            }
            _horizontalSpeed = 0;
            _isKnockingBack  = false;
            yield return(WaitYieldInstruction.Create(RecoupTime));

            _gs.Player.IsInvulnerable = false;
        }
        private IEnumerator Spawn()
        {
            while (true)
            {
                var go = new GameObject()
                         .AddTag("enemy")
                         .SetPosition(900, _rand.Next(20, 700))
                         .SetRotationInDegrees(270)
                         .AddComponent(new BoxCollider(24))
                         .AddComponent(new Body()
                {
                    Velocity = new Vector2(-0.08f, 0)
                })
                         .AddComponent(new AudioSource("audio/explode"))
                         .AddComponent(new SpriteRenderer("Sprites/enemy"))
                         .AddComponent(new EnemyShipBehavior());

                Scene.AddElement(go);

                yield return(WaitYieldInstruction.Create(_spawnWait));
            }
        }
Example #4
0
        private IEnumerator Death()
        {
            var sm = Services.GetService <SceneManager>();

            Services.GetService <RenderingManager>().Layers.Where(l => l.Name != "Player").ToList().ForEach(l => l.Show = false);
            var e = new Entity();

            e.Transform.Position = Entity.Transform.Position + new Vector2(0, 200);
            e.AddComponent(new SpriteTextRenderer("GenericFont")
            {
                Text   = $"You have died.\n{_gs.Player.ReasonForDeath}\nPress [Enter] to play again...",
                Layer  = "Player",
                Center = true,
            });
            sm.ActiveScene.AddEntity(e);
            yield return(WaitYieldInstruction.Create(500));

            while (!Input.GetControl <Button>(Controls.Continue).IsDown())
            {
                yield return(null);
            }
            sm.Load(typeof(RoomScene), GameplayState.Create());
        }
Example #5
0
        private IEnumerator Fire()
        {
            _allowFire = false;

            this.GameObject.Components.OfType <AudioSource>().First().Play();

            Scene.AddElement(new GameObject()
                             .AddTag("bullet")
                             .SetPosition(this.Transform.Position.ShiftX(20))
                             .AddComponent(new SpriteRenderer("Sprites/flash")
            {
                Color = Color.WhiteSmoke
            })
                             .AddComponent(new Body()
            {
                Velocity = new Vector2(1f, _rand.Next(-60, 61) / 1000f),
            })
                             .AddComponent(new BoxCollider(18))
                             .AddComponent(new BulletBehavior()));

            yield return(WaitYieldInstruction.Create(_fireRate));

            _allowFire = true;
        }