Beispiel #1
0
        /// <summary>
        /// Constructor for bullet class
        /// </summary>
        /// <param name="player">The object that fired the bullet</param>
        /// <param name="fireAngle">2D vector to travel towards</param>
        /// <param name="bulletSpeed">Speed of bullet</param>
        /// <param name="bulletDamage">Damage on hit</param>
        public Bullet(Sprite player, Vector2 fireAngle, float bulletSpeed, int bulletDamage)
        {
            damage = bulletDamage;

            this.player = player;
            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            SX = 4;
            SY = 24;

            //Sound effects
            GM.audioM.PlayEffect("shoot");

            //get player attributes
            Wash = player.Wash;

            //set postion of bullet and give velocity
            X = player.Centre.X;
            Y = player.Centre.Y;

            //Set rotation at player
            Position2D = RotationHelper.RotateAround(player.Centre2D, player.Centre2D, 0);

            //Create direction vector and normalise
            Vector2 direction = fireAngle - Position2D;

            direction = Vector2.Normalize(direction);

            //Face direction vector
            RotationHelper.FaceDirection(this, direction, DirectionAccuracy.free, 0);
            RotationHelper.VelocityInCurrentDirection(this, bulletSpeed, 0);
            Position += RotationHelper.MyDirection(this, 0) * 32;

            //collision setup
            CollisionActive   = true;
            CollisionPrimary  = true;
            PrologueCallBack += Hit;
            EpilogueCallBack += AfterHit;
            Moving            = true;

            //kill after 5 seconds
            TimerInitialise();
            Timer.KillAfter(5f);
        }