Пример #1
0
        public Bullet(Texture2D[] inputTexture, Vector2 gunPosition)
        {
            // Initial bullet state should be "in-flight."
            state = Bulletstate.Traversing;
            // x/y velocity; pixels per frame.
            velocity = 16;
            scale = 1;
            // Textures.
            bulletTexture = inputTexture[1];
            borderTexture = inputTexture[2];
            // Effects and colour.
            effects = SpriteEffects.None;
            color = Color.White;
            // Animation frame.
            bullet = new Rectangle(0, 0, 55, 11);
            // Gun vector.
            bulletPosition.X = gunPosition.X;
            bulletPosition.Y = gunPosition.Y - bulletTexture.Height / 2;
            // Offset, used for animatng rotation.
            rotationOffset = new Vector2(27.5F, 10.5F);
            // Mouse.
            mousePosition = new Vector2(Game.MOUSE.X, Game.MOUSE.Y);

            // If mouse is left of bullet.
            if (mousePosition.X < bulletPosition.X)
            {
                // Animation frame.
                bullet.X = 59;
                // Reverse velocity.
                velocity = -velocity;
                // The path the bullet will travel after firing.
                bulletPath = mousePosition - bulletPosition;
            }

            // If mouse is right of bullet.
            if (mousePosition.X >= bulletPosition.X)
            {
                bullet.X = 0;
                bulletPath = bulletPosition - mousePosition;
            }

            // Rotation is set once.
            rotation = (float)(Math.Atan2(bulletPath.Y, bulletPath.X));
        }
Пример #2
0
        private void Traversing()
        {
            if (bulletPath != Vector2.Zero)
                bulletPath.Normalize();

            bulletPosition -= bulletPath * velocity;

            if (!Rectangle().Intersects(Game.BOUNDS))
                state = Bulletstate.Expired;
        }
Пример #3
0
 public void State(int newState)
 {
     if (newState == 1)
         state = Bulletstate.Traversing;
     if (newState == 2)
         state = Bulletstate.Detonating;
     if (newState == 3)
         state = Bulletstate.Expired;
 }