Beispiel #1
0
 public void ActivateSpell()
 {
     spellManager.ActivateSpell(this, Spell);
 }
Beispiel #2
0
        protected Spell Shot(
            Vector2 direction, Func <bool> castCheck   = null,
            Func <Spell, Vector2> recalculateDirection = null, bool simulate = false
            )
        {
            direction.Normalize();
            var spell = SpellManager.ActivateSpell(castCheck: castCheck, simulate: simulate);

            if (spell == null)
            {
                return(null);
            }

            bool verticalDirection;
            var  xMod = (direction.X + 1f) / 2f;
            var  yMod = (direction.Y + 1f) / 2f;

            if (Math.Abs(direction.X) / Math.Abs(direction.Y) > Width / Height)
            {
                xMod = direction.X > 0 ? 1f : 0f;
                verticalDirection = true;
            }
            else
            {
                yMod = direction.Y > 0 ? 1f : 0f;
                verticalDirection = false;
            }
            spell.XOffset = (int)(Width * xMod);
            spell.YOffset = (int)(Height * yMod);
            if (verticalDirection)
            {
                spell.YOffset -= Level.SpellSize / 2;
                if (direction.X < 0)
                {
                    spell.XOffset -= Level.SpellSize;
                }
            }
            else
            {
                spell.XOffset -= Level.SpellSize / 2;
                if (direction.Y < 0)
                {
                    spell.YOffset -= Level.SpellSize;
                }
            }
            if (recalculateDirection != null)
            {
                direction = recalculateDirection(spell);
            }
            direction.Normalize();

            Debug.WriteLine("{0} is shotting to Direction: {1}", Name, direction);
            spell.Direction = direction;

            if (!simulate)
            {
                Engine.SpawnObject(spell);
            }

            return(spell);
        }