Beispiel #1
0
        public override void OnUpdate(QTime time)
        {
            var s = Speed;

            if (Health < 1)
            {
                Scene.Destroy(this);
            }
            damageAccum += time.Delta;
            if (damageAccum > 0.5f)
            {
                CanTakeDamage = true;
                damageAccum   = 0;
            }
            if (Health < MaxHealth)
            {
                s = Speed * 2;
            }
            if (Health == 1)
            {
                s = Speed * 3;
            }
            if (QVec.Distance(p.Transform.Position, Transform.Position) < 200)
            {
                //				if(p.Transform.Position.X > Transform.Position.X)
                //					Sprite.Effect = SpriteEffects.FlipHorizontally;
                //				else
                //					Sprite.Effect = SpriteEffects.Non
                Transform.Position = QVec.MoveTowards(Transform.Position, p.Transform.Position) * time.Delta * s;
                Sprite.Source      = BatFlap.Play(time.Delta);
            }
            else if (QVec.Distance(p.Transform.Position, Transform.Position) < 800 && p.Transform.Position.Y > Transform.Position.Y)
            {
                //				if(p.Transform.Position.X > Transform.Position.X)
                //					Sprite.Effect = SpriteEffects.FlipHorizontally;
                //				else
                //					Sprite.Effect = SpriteEffects.None;
                Transform.Position += QVec.MoveTowards(Transform.Position, p.Transform.Position) * time.Delta * s;
                Sprite.Source       = BatFlap.Play(time.Delta);
            }
            else
            {
                if (QVec.Distance(Transform.Position, spawnerPosition) > 1)
                {
                    //					if(spawnerPosition.X > Transform.Position.X)
                    //						Sprite.Effect = SpriteEffects.FlipHorizontally;
                    //					else
                    //						Sprite.Effect = SpriteEffects.None;
                    Transform.Position += QVec.MoveTowards(Transform.Position, spawnerPosition) * time.Delta * Speed;
                    Sprite.Source       = BatFlap.Play(time.Delta);
                }
                else
                {
                    //					Sprite.Effect = SpriteEffects.FlipVertically;
                    Sprite.Source = Frames[30];
                }
            }
        }
        public override void OnUpdate(QTime time)
        {
            var s = Speed;

            if (Health < 1)
            {
                Scene.Destroy(this);
            }
            if (!CanTakeDamage && Accumulator.CheckAccum("BatCanTakeDamage", 0.2f, time))
            {
                CanTakeDamage = true;
            }
            if (Health < MaxHealth)
            {
                s = Speed * 2;
            }
            if (Health == 1)
            {
                s = Speed * 3;
            }
            var distanceFromPlayer = QVec.Distance(player.Transform.Position, Transform.Position);

            if (player.Position.Y > Position.Y)
            {
                WillAttack = true;
            }
            if (!WillAttack)
            {
                return;
            }
            //flies to player
            if (distanceFromPlayer < 800)            // && player.Transform.Position.Y > Transform.Position.Y)
            {
                if (player.Position.X > Position.X)
                {
                    Sprite.Effect = QRenderEffects.FlipHorizontally;
                }
                else
                {
                    Sprite.Effect = QRenderEffects.None;
                }
                Position     += QVec.MoveTowards(Position, player.Position) * time.Delta * s;
                Sprite.Source = BatFlap.Play(time.Delta);
            }
            else
            {
                //runs back to spawn
                if (QVec.Distance(Transform.Position, spawnerPosition) > 1)
                {
                    if (spawnerPosition.X > Position.X)
                    {
                        Sprite.Effect = QRenderEffects.FlipHorizontally;
                    }
                    else
                    {
                        Sprite.Effect = QRenderEffects.None;
                    }
                    Position     += QVec.MoveTowards(Position, spawnerPosition) * time.Delta * Speed;
                    Sprite.Source = BatFlap.Play(time.Delta);
                }
                else if (distanceFromPlayer > 1000)
                {
                    //closes eyes
                    Sprite.Effect = QRenderEffects.FlipVertically;
                    Sprite.Source = Frames[30];
                }
                else if (distanceFromPlayer < 1000)
                {
                    //opens eyes
                    Sprite.Effect = QRenderEffects.FlipVertically;
                    Sprite.Source = Frames[28];
                }
            }
        }