Beispiel #1
0
        public void Initialize()
        {
            Level testLevel = new Level();
            levelList.Add(testLevel);

            playerSprite = new AnimatedSprite(Globals.content.Load<Texture2D>("Sprites/Player/man1"));

            FrameAnimation up = new FrameAnimation(2, 32, 32, 0, 0);
            up.FramesPerSecond = 10;
            playerSprite.Animations.Add("Up", up);

            FrameAnimation down = new FrameAnimation(2, 32, 32, 64, 0);
            down.FramesPerSecond = 10;
            playerSprite.Animations.Add("Down", down);

            FrameAnimation left = new FrameAnimation(2, 32, 32, 128, 0);
            left.FramesPerSecond = 10;
            playerSprite.Animations.Add("Left", left);

            FrameAnimation right = new FrameAnimation(2, 32, 32, 192, 0);
            right.FramesPerSecond = 10;
            playerSprite.Animations.Add("Right", right);

            playerSprite.CurrentAnimationName = "Down";

            spell.Initialize();
        }
Beispiel #2
0
 public void LockToTarget(AnimatedSprite sprite, int screenWidth, int screenHeight)
 {
     Position.X =
         sprite.Position.X +
         ((sprite.CurrentAnimation.CurrentRect.Width * ZOOM) / 2) -
         (screenWidth / 2) / ZOOM;
     Position.Y =
         sprite.Position.Y +
         ((sprite.CurrentAnimation.CurrentRect.Height * ZOOM) / 2) -
         (screenHeight / 2) / ZOOM;
 }
        /// <summary>
        /// Optimized PerPixelCollision. Written by Matt Senn
        /// </summary>
        private static bool PerPixelCollision(AnimatedSprite A, AnimatedSprite B)
        {
            //reference found at http://forums.create.msdn.com/forums/p/23774/138877.aspx
            int bottom = Math.Min(A.Bounds.Bottom, B.Bounds.Bottom);
            int right = Math.Min(A.Bounds.Right, B.Bounds.Right);

            for (int y = Math.Max(A.Bounds.Top, B.Bounds.Top); y < bottom; y++)
                for (int x = Math.Max(A.Bounds.Left, B.Bounds.Left); x < right; x++)
                    if (A.data[(x - A.Bounds.Left) + (y - A.Bounds.Top) * A.Bounds.Width].A != 0 &&
                        B.data[(x - B.Bounds.Left) + (y - B.Bounds.Top) * B.Bounds.Width].A != 0)
                        return true;
            return false;
        }
Beispiel #4
0
        public void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();
            Vector2 motion = Vector2.Zero;

            if (keyState.IsKeyDown(Keys.W) || keyState.IsKeyDown(Keys.Up))
                motion.Y--;
            if (keyState.IsKeyDown(Keys.S) || keyState.IsKeyDown(Keys.Down))
                motion.Y++;
            if (keyState.IsKeyDown(Keys.A) || keyState.IsKeyDown(Keys.Left))
                motion.X--;
            if (keyState.IsKeyDown(Keys.D) || keyState.IsKeyDown(Keys.Right))
                motion.X++;

            if (motion != Vector2.Zero)
            {
                motion.Normalize();
                //Add Check here for motion effects(i.e. ice)
                //motion =

                playerSprite.Position += motion * playerSprite.Speed;
                UpdateSpriteAnimation(motion);
                playerSprite.IsAnimating = true;

                playerSprite = levelList[currentLevel].CollisionCheck(playerSprite);
            }
            else
                playerSprite.IsAnimating = false;

            playerSprite.ClampToArea(
                levelList[currentLevel].MapWidthInPixels,
                levelList[currentLevel].MapHeightInPixels);

            playerSprite.Update(gameTime);

            Globals.camera.LockToTarget(playerSprite, Globals.ScreenWidth, Globals.ScreenHeight);

            Globals.camera.ClampToArea(
                levelList[currentLevel].MapWidthInPixels - Globals.ScreenWidth,
                levelList[currentLevel].MapHeightInPixels - Globals.ScreenHeight);

            // calclate where the spell animation should be drawn
            Vector2 spellOffset = Vector2.Zero;
            if (playerSprite.CurrentAnimationName == "Up")
            {
                spellOffset = new Vector2(8, -16);
            }
            else if (playerSprite.CurrentAnimationName == "Down")
            {
                spellOffset = new Vector2(8, 32);
            }
            else if (playerSprite.CurrentAnimationName == "Left")
            {
                spellOffset = new Vector2(-8, 16);
            }
            else
            {
                spellOffset = new Vector2(24, 16);
            }

            // press 1 for fire attack, 3 for wind attack
            if (keyState.IsKeyDown(Keys.D1))
                spell.selectedSpell = Spell.SpellType.Fire;
            if (keyState.IsKeyDown(Keys.D3))
                spell.selectedSpell = Spell.SpellType.Wind;
            spell.Update(gameTime, playerSprite.Position + spellOffset);
        }