Exemplo n.º 1
0
        protected override void ExecuteImpl(EntityCollection entities)
        {
            var bulletP = new Entity("bullet") {
                Textured.Instance,
                Order2Update.Instance,

                new CustomOnEscape(new BoundingBox2(
                    new Vector2(0, 0),
                    new Vector2(640, 480)
                ), (e) => {
                    entities.EnqueueDestroy(e);
                }),

                { Textured.Texture, this.bulletTexture },
                { Properties.DestroysEnemies, true },
                { Properties.Damage, 10.0f },

                {
                    Collidable.Body,
                    new Body(new ShapePrimitive[] {
                        new CircleShape(Vector2.Zero, 8)
                    })
                },
            };

            var basicWeapon = new Entity {
                new CustomBulletEmitter((e, weaponOwner) => {
                    var bullet = bulletP.Create();
                    bullet.Set(Located.Position, e.Get(Located.Position) + weaponOwner.Get(Located.Position));
                    bullet.Set(Located.Velocity, e.Get(Located.Velocity));
                    bullet.Set(Properties.Owner, weaponOwner);
                    entities.EnqueueSpawn(bullet);
                })
            };

            var weapons = new[] {
                basicWeapon.Create("top").Configure((e) => {
                    e.Set(Located.Position, new Vector2(0, 0));
                    e.Set(Located.Velocity, new Vector2(7, 0));
                }),

                basicWeapon.Create("bottom").Configure((e) => {
                    e.Set(Located.Position, new Vector2(0, 30));
                    e.Set(Located.Velocity, new Vector2(7, 0));
                }),

                basicWeapon.Create("center").Configure((e) => {
                    e.Set(Located.Position, new Vector2(0, 15));
                    e.Set(Located.Velocity, new Vector2(7, 0));
                }),
            };

            this.weaponConfigs = new[] {
                new[] { weapons[2], },
                new[] { weapons[0], weapons[1], },
                new[] { weapons[0], weapons[1], weapons[2], },
            };
        }
Exemplo n.º 2
0
        protected override void ExecuteImpl(EntityCollection entities)
        {
            entities.EnqueueSpawn(new Entity("enemy") {
                Textured.Instance,

                new CustomUpdated((e, gt) => {
                    e.Update(Properties.Milliseconds, (t) => t + (uint) gt.ElapsedGameTime.TotalMilliseconds);

                    float d = (float) Math.Sin(e.Get(Properties.Milliseconds) / 1000.0f) * 50;
                    e.Set(Located.Position, new Vector2(0, d) + new Vector2(500, 100));
                }),

                new CustomCollidable((e, other) => {
                    if (other.Get(Properties.DestroysEnemies)) {
                        entities.EnqueueDestroy(other);

                        var ownerE = other.Get(Properties.Owner);
                        Healthed.Damage(e, other.Get(Properties.Damage), ownerE);
                    }
                }),

                new CustomKillable((e, killer) => {
                    entities.EnqueueDestroy(e);
                }),

                { Textured.Texture, this.enemyTexture },
                { Located.Position, new Vector2(500, 100) },
                { Healthed.Health, 30.0f },
                { Properties.Points, 50U },

                {
                    Collidable.Body,
                    new Body(new ShapePrimitive[] {
                        new CircleShape(Vector2.Zero, 16)
                    })
                },
            });
        }
Exemplo n.º 3
0
        protected override void ExecuteImpl(EntityCollection entities)
        {
            var shipBulletScript = ShipBulletScript.Instance;

            this.Ship = new Entity("ship proto") {
                Textured.Instance,
                Order2Update.Instance,
                VelocityInputed.Instance,
                Weaponized.Instance,

                new TimedEmitter((e) => {
                    e.ForEach<Weaponized>((c) => {
                        c.Emit(e);
                    });
                }),

                new CustomCollidable((e, other) => {
                    if (other.Get(Properties.IsPowerup)) {
                        entities.EnqueueDestroy(other);

                        var weaponConfig = e.Get(Weaponized.WeaponConfiguration);
                        var nextWeaponConfig = shipBulletScript.WeaponConfigs
                            .SkipWhile((wc) => wc != weaponConfig)
                            .Skip(1)
                            .FirstOrDefault();

                        if (nextWeaponConfig != null) {
                            e.Set(Weaponized.WeaponConfiguration, nextWeaponConfig);
                        }
                    }
                }),

                { Textured.Texture, this.shipTexture },
                { Located.Position, new Vector2(30, 30) },
                { Properties.Score, 0U },
                { Weaponized.WeaponConfiguration, shipBulletScript.WeaponConfigs[0] },

                {
                    Collidable.Body,
                    new Body(new ShapePrimitive[] {
                        new CircleShape(Vector2.Zero, 32)
                    })
                },
            };
        }