Esempio n. 1
0
        public void HandlePositionChanged(object sender, EventArgs args)
        {
            LostSoul entity = (LostSoul)((BodyBehavior)sender).Entity;
            var      pos    = entity.BodyBehavior.Position;

            if (!entity.Game.World.PlayField.Contains((int)pos.X, (int)pos.Y))
            {
                if (wasInPlayfield)
                {
                    entity.Game.Audio.PlaySound(entity.Game.ContentLoader.SkullEscapeSound);
                    entity.Game.World.AddLives(-1);
                    entity.Expired = true;
                }
            }
            else
            {
                wasInPlayfield = true;
            }
        }
Esempio n. 2
0
        private Vector2 PickVelocity(LostSoulGame game, LostSoul soul)
        {
            float speed = soul.Klass.Speed;

            if (random.NextDouble() < ChanceOfFasterSpeed)
            {
                speed *= 2.0f;
            }

            var     playField = game.World.PlayField;
            var     position  = soul.BodyBehavior.Position;
            Vector2 diff      = new Vector2(playField.Center.X, playField.Center.Y) - position;

            diff = Vector2.Normalize(diff);

            float   angle   = MathHelper.ToRadians(22.5f - (45.0f * (float)random.NextDouble()));
            Vector2 rotated = new Vector2()
            {
                X = (float)(diff.X * Math.Cos(angle) - diff.Y * Math.Sin(angle)),
                Y = (float)(diff.Y * Math.Cos(angle) + diff.X * Math.Sin(angle))
            };

            return(rotated * speed);
        }
Esempio n. 3
0
 public LostSoulPositionObserver(LostSoul entity)
 {
     entity.BodyBehavior.PositionChanged += HandlePositionChanged;
 }