예제 #1
0
        /// <summary>
        /// This is a Sprite with four animations for the four
        /// directions, up, down, left and right
        /// </summary>
        private void SetupAnimatedPlayer()
        {
            Texture2D playerSheet = Content.Load <Texture2D>
                                        ("Actors/rsc-sprite-sheet1");

            playerSprite = playerController.CreatePlayer
                               (graphicsDevice, playerSheet);


            playerSprite.Boundary = new Rectangle(0, 0, HD_Width, HD_Height);
        }
예제 #2
0
        public void HasCollided(AnimatedPlayer player)
        {
            foreach (AnimatedSprite coin in Coins)
            {
                if (coin.HasCollided(player) && coin.IsAlive)
                {
                    coinEffect.Play();

                    coin.IsActive  = false;
                    coin.IsAlive   = false;
                    coin.IsVisible = false;
                }
            }
        }
        /// <summary>
        /// Clones the bullet when the player fires their
        /// weapon by holding down the space bar.
        /// </summary>
        public void AddBullet(AnimatedPlayer player)
        {
            Bullet bullet = new Bullet(BulletTexture);

            bullet.Direction = player.Direction;

            bullet.Position = new Vector2(
                player.Position.X + 60, player.Position.Y + 40);

            bullet.LifeSpan = 2f; // seconds
            bullet.Parent   = player;

            Bullets.Add(bullet);
        }
예제 #4
0
        /// <summary>
        /// This is a Sprite with four animations for the four
        /// directions, up, down, left and right
        /// </summary>
        private void SetupAnimatedPlayer()
        {
            Texture2D playerSheet = Content.Load <Texture2D>
                                        ("Actors/rsc-sprite-sheet1");

            playerSprite = playerController.CreatePlayer
                               (graphicsDevice, playerSheet);

            Texture2D bulletTexture = Content.Load <Texture2D>("Actors/bullet");

            bulletController            = new BulletController(bulletTexture);
            bulletController.killEffect = flameEffect;

            playerSprite.BulletController = bulletController;

            playerSprite.Boundary = new Rectangle(0, 0, HD_Width, HD_Height);
        }
        /// <summary>
        /// Checks if a coin has collided with a player (i.e. the
        /// player walks over it to pick it up) and if it has,
        /// a sound effect will play and the coin will disappear
        /// from the screen.
        /// </summary>
        /// <returns>
        /// The value of the coin to add onto the player's current
        /// score.
        /// </returns>
        public int HasCollided(AnimatedPlayer player)
        {
            foreach (AnimatedSprite coin in Coins)
            {
                if (coin.HasCollided(player) && coin.IsAlive)
                {
                    coinEffect.Play();

                    coin.IsActive  = false;
                    coin.IsAlive   = false;
                    coin.IsVisible = false;

                    return(coinValue);
                }
            }

            return(0);
        }
예제 #6
0
        /// <summary>
        /// If the enemy collides with the player (hitting them), the
        /// player will lose 10% of their health. If their health
        /// drops to 0, they will lose the game and disappear.
        /// </summary>
        public void HasCollided(AnimatedPlayer player)
        {
            if (Enemy.HasCollided(player))
            {
                if (player.Health > 10)
                {
                    player.Health -= 10;
                    StartEnemy();
                }
                else
                {
                    player.Health = 0;

                    player.IsActive  = false;
                    player.IsAlive   = false;
                    player.IsVisible = false;
                }
            }
        }
예제 #7
0
        public AnimatedPlayer CreatePlayer(GraphicsDevice graphics,
                                           Texture2D playerSheet)
        {
            AnimationController controller = new
                                             AnimationController(graphics, playerSheet, 4, 3);

            string[] keys = new string[] { "Down", "Left", "Right", "Up" };
            controller.CreateAnimationGroup(keys);

            Player = new AnimatedPlayer()
            {
                CanWalk = true,
                Scale   = 2.0f,

                Rotation      = MathHelper.ToRadians(0),
                RotationSpeed = 0f,
            };

            controller.AppendAnimationsTo(Player);

            StartPlayer();
            return(Player);
        }
예제 #8
0
        /// <summary>
        /// This is a Sprite with four animations for the four
        /// directions, up, down, left and right
        /// </summary>
        private void SetupAnimatedPlayer()
        {
            Texture2D sheet4x3 = Content.Load <Texture2D>("images/rsc-sprite-sheet1");

            AnimationController contoller = new AnimationController(graphicsDevice, sheet4x3, 4, 3);

            string[] keys = new string[] { "Down", "Left", "Right", "Up" };
            contoller.CreateAnimationGroup(keys);

            playerSprite = new AnimatedPlayer()
            {
                CanWalk = true,
                Scale   = 2.0f,

                Position  = new Vector2(200, 200),
                Speed     = 200,
                Direction = new Vector2(1, 0),

                Rotation      = MathHelper.ToRadians(0),
                RotationSpeed = 0f
            };

            contoller.AppendAnimationsTo(playerSprite);
        }