Ejemplo n.º 1
0
Archivo: Enemy.cs Proyecto: MyEyes/BGJ5
        void Die(Player p)
        {
            _map.Objects.Remove(this);
            light.Radius = 0;
            Sounds.PlaySound("DeathFlash");
            for (int x = 0; x < 40; x++)
            {
                Vector2 dir = new Vector2((float)(2 * _rand.NextDouble() - 1), (float)(2 * _rand.NextDouble() - 1));
                dir.Normalize();
                dir *= 4.5f + (float)_rand.NextDouble();
                AntiLightParticle alp = new AntiLightParticle(Position, dir, null, _map, null);
                _map.Objects.Add(alp);
            }
            for (int x = 0; x < 20; x++)
            {
                Vector2 dir = new Vector2((float)(2 * _rand.NextDouble() - 1), (float)(2 * _rand.NextDouble() - 1));
                dir.Normalize();
                dir *= 1 + (float)_rand.NextDouble();
                LightParticle alp = new LightParticle(Position, dir, null, Color.White, _map, null);
                _map.Objects.Add(alp);
            }

            LightRefill refill = new LightRefill(Position, _map, null);

            refill.RefillLeft = 150;
            _map.Objects.Add(refill);
        }
Ejemplo n.º 2
0
Archivo: Enemy.cs Proyecto: MyEyes/BGJ5
        public override void Update(float seconds)
        {
            light.Position = Position;
            light.Radius   = Health / 5.0f;

            Health -= seconds;

            Player p = _map.Objects[0] as Player;

            if (Health <= 0)
            {
                Die(p);
            }

            if (p != null)
            {
                if ((p.Position - Position).Length() < light.Radius / 2.0f + p.Health / 4.0f)
                {
                    p.Attack(this);
                    Vector2 dir = new Vector2((float)(2 * _rand.NextDouble() - 1), (float)(2 * _rand.NextDouble() - 1));
                    dir.Normalize();
                    dir *= 5;
                    AntiLightParticle alp = new AntiLightParticle(Position, dir, p, _map, null, attackCounter % 8 == 0);
                    attackCounter++;
                    _map.Objects.Add(alp);
                    if (follow)
                    {
                        targetPos = p.Position;
                        countDown = 2 * (targetPos - Position).Length() / 60.0f;
                    }
                }
            }

            switch (mode)
            {
            case EnemyMode.RandomWalk:
                if ((targetPos - Position).Length() < Map.TileSize || countDown < 0)
                {
                    NewTargetPos();
                }
                else
                {
                    Vector2 dir = targetPos - Position;
                    dir.Normalize();
                    dir *= speed;
                    Move(new Vector2(dir.X, 0));
                    Move(new Vector2(0, dir.Y));
                    countDown -= seconds;
                }
                break;
            }
            base.Update(seconds);
        }