public EntityMagicWeapon(Vector pnt, Tile[] obj, byte[,,] chips, EntityList par)
        {
            Location = pnt;
            Mpts     = obj;
            Map      = chips;
            Parent   = par;
            Size     = new Size(8, 8);
            SetGraphic(2);

            // ウェポンは同時に3つまでしか打てない
            if (Parent.FindEntitiesByType <EntityMagicWeapon>().Count() > 3)
            {
                Kill();
            }

            // 対象を探す
            // 条件は、プレイヤーに最も近い生きているエネミー
            Entity?target = Parent
                            .Where(e => e.MyGroup == EntityGroup.Enemy)
                            .Where(e => !(e is EntityLiving l) || !l.IsDying)
                            .OrderBy(e => MathF.Abs(e.Location.Distance(Location)))
                            .FirstOrDefault();

            // 対象がいればその方向へ、いなければランダムに射出
            var r = target != null
                                ? MathF.Atan2(Location.Y - target.Location.Y, Location.X - target.Location.X)
                                : DFMath.ToRadian(Core.GetRand(360));

            Velocity = new Vector(MathF.Cos(r), MathF.Sin(r)) * -5;
        }
Beispiel #2
0
        public virtual void OnDyingAnimation(ElementBase el)
        {
            if (DyingMax == 0)
            {
                return;
            }
            var lerp = DFMath.Lerp((DyingMax - DyingTick) / (float)DyingMax, 1, 0);

            if (el is Sprite s)
            {
                s.TintColor = Color.FromArgb(255, (int)(lerp * 255), (int)(lerp * 255));
                Location   += Vector.Right * lerp;
            }
        }
Beispiel #3
0
        private IEnumerator Intro(GameBase game)
        {
            var duration = 1.5f;
            var tick     = 0f;
            var initial  = cursor;
            var target   = new VectorInt(game.Width, game.Height) / 4;

            while (tick < duration)
            {
                cursor = DFMath.EaseOut(tick / duration, initial, target);
                yield return(null);

                tick += Time.DeltaTime;
            }
            cursor    = target;
            introDone = true;
        }
Beispiel #4
0
        /// <summary>
        /// ノイズを生成します。
        /// </summary>
        /// <param name="x">X座標。</param>
        public float Generate(float x)
        {
            x = MathF.Abs(x);
            int   xi = (int)x;
            float f  = x - xi;

            float g0 = GetGradient(xi);
            float g1 = GetGradient(xi + 1);

            float p0 = f;
            float p1 = f - 1f;

            float v0 = g0 * p0;
            float v1 = g1 * p1;

            return(DFMath.EaseInOut(f, v0, v1));
        }
Beispiel #5
0
        private IEnumerator DisplayTextParticleCoroutine(string text, Vector position)
        {
            var drawable = new TextDrawable(text)
            {
                Location = position
            };

            Root.Add(drawable);

            var time = 0f;

            while (time < 2)
            {
                drawable.Location += Vector.Up * 16 * Time.DeltaTime;
                drawable.Color     = Color.FromArgb((int)DFMath.Lerp(time / 2, 255, 0), 255, 255, 255);
                time += Time.DeltaTime;
                yield return(null);
            }
            Root.Remove(drawable);
        }
Beispiel #6
0
        private void HandleKey()
        {
            var w = DFKeyboard.W;
            var a = DFKeyboard.A;
            var s = DFKeyboard.S;
            var d = DFKeyboard.D;

            var target =
                w && a ? 225 :
                w && d ? 315 :
                s && a ? 135 :
                s && d ? 45 :
                w ? 270 :
                a ? 180 :
                s ? 90 :
                d ? 0 : -1;

            if (w || a || s || d)
            {
                currentDegree = DFMath.Lerp(0.3f, currentDegree, target);
                cursor       += Forward * 128 * Time.DeltaTime;
            }
        }