Exemplo n.º 1
0
        public override void Process(Entity e)
        {
            Damage d = e.GetComponent<Damage>();
            Health h = e.GetComponent<Health>();

            if (d.Seconds <= 0)
            {
                e.RemoveComponent<Damage>(d);
                e.Refresh();

                return;
            }

            d.Seconds -= (float)world.Delta / 1000;

            h.SetHealth(e, h.CurrentHealth - d.DamagePerSecond * (world.Delta / 1000));

            Sprite s = e.GetComponent<Sprite>();

            Vector2 offset;
            if (!e.Tag.Contains("Boss"))
            {
                double mes = Math.Sqrt(s.CurrentRectangle.Width * s.CurrentRectangle.Height / 4);
                offset = new Vector2((float)((r.NextDouble() * 2 - 1) * mes), (float)((r.NextDouble() * 2 - 1) * mes));
            }
            else
            {
                offset = new Vector2((float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Width / 2), (float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Height / 2));
            }
            world.CreateEntity("GREENFAIRY", e, ConvertUnits.ToSimUnits(offset)).Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attaches a control to an <see cref="Entity"/> instance, using the specified offset.
        /// </summary>
        /// <param name="control">Control instance being attached to the entity.</param>
        /// <param name="entity">Entity instance to which the control is being attached.</param>
        /// <param name="offset">Offset from the entity's position to display the control.</param>
        public static void AttachToEntity(this Control control, Entity entity, Vector2 offset)
        {
            ControlComponent controlComponent = new ControlComponent()
            {
                Control = control,
                Offset = offset
            };

            entity.AddComponent<ControlComponent>(controlComponent);
            entity.Refresh();
        }
Exemplo n.º 3
0
        public override void Process(Entity e)
        {
            Slow slow = slowMapper.Get(e);
            if (slow != null && slow != Slow.None) //If particle is slowing
            {
                slow.Elapsed--;
                if (slow.Elapsed <= 0)
                {
                    e.RemoveComponent<Slow>(slow);
                    IDamping d = dampingMapper.Get(e);
                    d.LinearDamping = 0;
                    d.AngularDamping = 0;
                    if (e.HasComponent<AI>())
                    {
                        AI a = e.GetComponent<AI>();
                        e.RemoveComponent<AI>(e.GetComponent<AI>());
                        a.Calculated = false;
                        e.AddComponent<AI>(a);
                    }

                    e.Refresh();
                    return;
                }
                IVelocity velocity = velocityMapper.Get(e);
                IDamping damping = dampingMapper.Get(e);

                //Slow particle angular speed
                if (velocity.AngularVelocity > slow.AngularTargetVelocity || damping.AngularDamping != slow.AngularSlowRate)
                    damping.AngularDamping = slow.AngularSlowRate;
                else
                    damping.AngularDamping = 0;

                //Slow particle linear speed
                if (velocity.LinearVelocity.Length() - slow.LinearTargetVelocity.Length() > 1 || damping.LinearDamping != slow.LinearSlowRate)
                    damping.LinearDamping = slow.LinearSlowRate;
                else
                    damping.LinearDamping = 0;

                SpawnFrostEffect(e);
            }
        }
Exemplo n.º 4
0
        public static Func<Body, bool> CreateShoot(Entity ent, float speed, float shootDistance, bool rotateTo)
        {
            return
                (target) =>
                {
                    Body b = ent.GetComponent<Body>();
                    float distance = Vector2.Distance(b.Position, target.Position);

                    Vector2 direction = target.Position - (b.Position + ent.GetComponent<Inventory>().CurrentGun.GunOffsets[0]);
                    direction.Normalize();
                    b.RotateTo(direction);
                    if (distance > shootDistance)
                    {
                        direction *= 5f;
                        b.LinearVelocity = direction;
                    }

                    else
                    {
                        b.LinearVelocity = new Vector2(MathHelper.SmoothStep(b.LinearVelocity.X, 0, 0.1f), MathHelper.SmoothStep(b.LinearVelocity.Y, 0, 0.1f));
                        ent.GetComponent<Inventory>().CurrentGun.BulletsToFire = true;
                    }
                    ent.Refresh();
                    return false;
                };
        }
Exemplo n.º 5
0
        public static Func<Body, bool> CreateCannon(Entity ent, bool rotateTo)
        {
            float shootDistance = ConvertUnits.ToSimUnits(700);

            return
                (target) =>
                {
                    Body b = ent.GetComponent<Body>();
                    float distance = Vector2.Distance(b.Position, target.Position);

                    if (distance < shootDistance)
                    {
                        Vector2 direction = target.Position - b.Position;
                        direction.Normalize();
                        if (rotateTo)
                        {
                            b.RotateTo(direction);
                            ent.GetComponent<Inventory>().CurrentGun.BulletsToFire = true;
                        }
                    }

                    b.LinearVelocity = ent.GetComponent<Origin>().Parent.GetComponent<Body>().LinearVelocity;

                    ent.Refresh();
                    return false;
                };
        }
Exemplo n.º 6
0
        protected override void ProcessEntities(Dictionary<int, Entity> entities)
        {
            base.ProcessEntities(entities);

            timesCalled++;
            elapsedSeconds += .333f;
            elapsedMinutes += .333f / 60f;

            difficulty = (int)(elapsedMinutes);

            #region Scoring

            Score s = Base.GetComponent<Score>();

            if (elapsedSeconds % 1 == 0)
                ScoreSystem.GivePoints(10 * difficulty);

            #endregion Scoring

            #region Spawning

            if (timesCalled == 1)
            {
                World.CreateEntity(BossTemplate, 1, Base.GetComponent<Body>()).Refresh();
            }

            //Every 5/3 seconds spawn

            if (timesCalled % 5 == 0)
            {
                int type;
                mooksToSpawn = (MookSpawnRate != -1) ? ((MookSpawnRate == 0) ? difficulty : MookSpawnRate) : 0;
                thugsToSpawn = (ThugSpawnRate != -1) ? ((ThugSpawnRate == 0) ? ((r.Next(1, 100) * difficulty > 90) ? 1 : 0) : ThugSpawnRate) : 0;
                gunnersToSpawn = (GunnerSpawnRate != -1) ? ((GunnerSpawnRate == 0) ? (int)(difficulty / 9) : GunnerSpawnRate) : 0;
                huntersToSpawn = (HunterSpawnRate != -1) ? ((HunterSpawnRate == 0) ? (int)(difficulty / 15) : HunterSpawnRate) : 0;
                destroyersToSpawn = (DestroyerSpawnRate != -1) ? ((DestroyerSpawnRate != 0) ? (int)(difficulty / 30) : DestroyerSpawnRate) : 0;

                type = r.Next(8);
                for (int i = 0; i < mooksToSpawn; i++)
                {
                    if (string.IsNullOrEmpty(MookSprite))
                        World.CreateEntity(MookTemplate, type, Base.GetComponent<Body>()).Refresh();
                    else
                        World.CreateEntity(MookTemplate, type, Base.GetComponent<Body>(), MookSprite).Refresh();
                }

                type = r.Next(4);
                for (int i = 0; i < thugsToSpawn; i++)
                {
                    if (string.IsNullOrEmpty(ThugSprite))
                        World.CreateEntity(ThugTemplate, type, Base.GetComponent<Body>()).Refresh();
                    else
                        World.CreateEntity(ThugTemplate, type, Base.GetComponent<Body>(), ThugSprite).Refresh();
                }

                for (int i = 0; i < gunnersToSpawn; i++)
                {
                }

                for (int i = 0; i < huntersToSpawn; i++)
                {
                }

                for (int i = 0; i < destroyersToSpawn; i++)
                {
                }
            }

            if ((int)(elapsedMinutes) >= lastBoss)
            {
                //Boss.
                int tier = Math.Min(difficulty, 3);
                Boss = World.CreateEntity(BossTemplate, tier, Base.GetComponent<Body>());
                Boss.Refresh();
                lastBoss++;
            }

            #endregion Spawning
        }