コード例 #1
0
        public override void OnUpdate()
        {
            base.OnUpdate();
            _renderer.rotation += 180f*world.delta;

            _glimpseTime -= world.delta;
            if(_glimpseTime < 0)
            {
                _glimpseTime = 0;
            }

            Vector2f avatarPos = world.avatar.body.position;
            Vector2f pos = entity.body.position;
            float distanceToAvatar = pos.DistanceTo(avatarPos);
            if (distanceToAvatar < entity.body.hitbox.Width/2)
            {

                if (!_trigger)
                {
                    OnAvatarReach();
                    _trigger = true;
                }
            }
            else
                _trigger = false;


            _renderer.color = new Color(255, 255, 255, (byte)(255f * System.Math.Max(Mathf.Clamp01(_glimpseTime), Mathf.Clamp01(1f-distanceToAvatar/4f))));

        }
コード例 #2
0
        public float CalculateCompassAngle()
        {
            Vector2f avatarPos = world.avatar.body.position;

            IEnumerable <Entity> portals = world.taggedEntities["Portal"];
            float    smallestDistance    = 999999f;
            Vector2f nearestPortalPos    = new Vector2f(0, 0);

            foreach (Entity p in portals)
            {
                Vector2f ppos = p.body.position;
                float    d    = ppos.DistanceTo(avatarPos);
                if (d < smallestDistance)
                {
                    smallestDistance = d;
                    nearestPortalPos = ppos;
                }
            }

            return(Mathf.RAD2DEG * ((nearestPortalPos - avatarPos).Angle()));
        }
コード例 #3
0
 public static float DistanceTo(this Vector2f origin, Vector2i destination)
 {
     return(origin.DistanceTo((Vector2f)destination));
 }
コード例 #4
0
        public override void OnUpdate()
        {
            base.OnUpdate();

            // AI ----------------------

            Vector2f avatarPos = world.avatar.body.position;
            Vector2f pos       = entity.body.position;

            float distanceToTarget = avatarPos.DistanceTo(pos);
            float targetBias       = Mathf.Clamp(distanceToTarget / 2f, 2f, 10f);

            float time = ((float)world.timeMs) / 1000f;
            float roff = time + noiseOffset;

            Vector2f bias = targetBias * new Vector2f(
                2f * Noise.GetPerlin(roff, 10, 6568, 2, 0.5f, 1f) - 1f,
                2f * Noise.GetPerlin(roff, 100, 5468, 2, 0.5f, 1f) - 1f
                );

            Vector2f dir = (avatarPos + bias) - pos;

            //float v = 3f + 3f*Noise.GetPerlin(roff, 0, 123456, 2, 0.5f, 1f);

            float speed = 1.5f;

            if (dimension == 1 && distanceToTarget < 8f)
            {
                speed = 3f;
            }

            entity.body.velocity = dir.Normalized() * speed;

            // Lightening and rendering -----------------------------

            if (dimension == 0)
            {
                if (IsLightedByPlayer())
                {
                    lightedTime += world.delta;
                }
                else
                {
                    lightedTime = 0;
                }
                alphaByLighting = Mathf.Clamp01(System.Math.Max(lightedTime - APPEAR_BY_LIGHT_TIME, alphaByLighting - world.delta));

                float dt = world.delta;
                if (_alpha > 0)
                {
                    _alpha -= dt;
                    if (_alpha <= 0)
                    {
                        _alpha = 0;
                    }
                }
                float contactAlpha = 1f - Mathf.Clamp01(distanceToTarget);
                float instantAlpha = System.Math.Max(contactAlpha, _alpha);
                instantAlpha          = System.Math.Max(instantAlpha, alphaByLighting);
                _renderer.color       = new Color(255, 255, 255, (byte)(instantAlpha * 255f));
                _renderer.textureRect = new IntRect(
                    0,
                    0,
                    64,
                    64
                    );
            }
            else
            {
                _renderer.color       = _flicker <= 0 ? Color.White : new Color(128, 128, 128, 128);
                _renderer.textureRect = new IntRect(
                    64 * ((world.timeMs / 64) % 4),
                    0,
                    64,
                    64
                    );
            }

            --_flicker;

            // Sound -----------------------------------

            timeBeforeSound -= world.delta;
            if (timeBeforeSound <= 0)
            {
                timeBeforeSound = soundTime.Random();
                entity.audio.Play("enemy" + Random.Range(1, 7 + 1), 1f, Random.Range(0.9f, 1.1f), false, AudioCategories.ENEMIES);
            }
        }