Пример #1
0
        public void Update(GameTime gameTime, TileMap map)
        {
            Vector2 motion = Vector2.Zero;

            if (Xin.IsKeyDown(Keys.Left))
            {
                motion.X = -speed;
            }
            else if (Xin.IsKeyDown(Keys.Right))
            {
                motion.X = speed;
            }

            if (Xin.IsKeyDown(Keys.Up))
            {
                motion.Y = -speed;
            }
            else if (Xin.IsKeyDown(Keys.Down))
            {
                motion.Y = speed;
            }

            if (motion != Vector2.Zero && map != null)
            {
                motion.Normalize();
                position += motion * speed;
                LockCamera(map);
            }
        }
Пример #2
0
        public override void Update(GameTime gameTime)
        {
            camera.Update(gameTime, world.CurrentMap);
            camera.LockCamera(world.CurrentMap);

            Vector2 motion = Vector2.Zero;

            if (Xin.IsKeyDown(Keys.S))
            {
                motion.Y = 1;
                player.Sprite.IsAnimating      = true;
                player.Sprite.CurrentAnimation = AnimationKey.WalkUp;
            }

            if (Xin.IsKeyDown(Keys.W))
            {
                motion.Y = -1;
                player.Sprite.IsAnimating      = true;
                player.Sprite.CurrentAnimation = AnimationKey.WalkDown;
            }

            if (Xin.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                player.Sprite.IsAnimating      = true;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }

            if (Xin.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                player.Sprite.IsAnimating      = true;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }

            if (motion != Vector2.Zero)
            {
                motion.Normalize();
                player.Sprite.Position += motion * player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                player.Sprite.LockToMap(new Point(world.CurrentMap.WidthInPixels, world.CurrentMap.HeightInPixels));
                camera.LockToSprite(player.Sprite, world.CurrentMap);
            }
            else
            {
                player.Sprite.IsAnimating = false;
            }


            base.Update(gameTime);
        }
Пример #3
0
        private void CheckKeys()
        {
            string newChar = "";

            if (Xin.CheckKeyPress(Keys.A))
            {
                newChar += "a";
            }
            if (Xin.CheckKeyPress(Keys.B))
            {
                newChar += "b";
            }
            if (Xin.CheckKeyPress(Keys.C))
            {
                newChar += "c";
            }
            if (Xin.CheckKeyPress(Keys.D))
            {
                newChar += "d";
            }
            if (Xin.CheckKeyPress(Keys.E))
            {
                newChar += "e";
            }
            if (Xin.CheckKeyPress(Keys.F))
            {
                newChar += "f";
            }
            if (Xin.CheckKeyPress(Keys.G))
            {
                newChar += "g";
            }
            if (Xin.CheckKeyPress(Keys.H))
            {
                newChar += "h";
            }
            if (Xin.CheckKeyPress(Keys.I))
            {
                newChar += "i";
            }
            if (Xin.CheckKeyPress(Keys.J))
            {
                newChar += "j";
            }
            if (Xin.CheckKeyPress(Keys.K))
            {
                newChar += "k";
            }
            if (Xin.CheckKeyPress(Keys.L))
            {
                newChar += "l";
            }
            if (Xin.CheckKeyPress(Keys.M))
            {
                newChar += "m";
            }
            if (Xin.CheckKeyPress(Keys.N))
            {
                newChar += "n";
            }
            if (Xin.CheckKeyPress(Keys.O))
            {
                newChar += "o";
            }
            if (Xin.CheckKeyPress(Keys.P))
            {
                newChar += "p";
            }
            if (Xin.CheckKeyPress(Keys.Q))
            {
                newChar += "q";
            }
            if (Xin.CheckKeyPress(Keys.R))
            {
                newChar += "r";
            }
            if (Xin.CheckKeyPress(Keys.S))
            {
                newChar += "s";
            }
            if (Xin.CheckKeyPress(Keys.T))
            {
                newChar += "t";
            }
            if (Xin.CheckKeyPress(Keys.U))
            {
                newChar += "u";
            }
            if (Xin.CheckKeyPress(Keys.V))
            {
                newChar += "v";
            }
            if (Xin.CheckKeyPress(Keys.W))
            {
                newChar += "w";
            }
            if (Xin.CheckKeyPress(Keys.X))
            {
                newChar += "x";
            }
            if (Xin.CheckKeyPress(Keys.Y))
            {
                newChar += "y";
            }
            if (Xin.CheckKeyPress(Keys.Z))
            {
                newChar += "z";
            }
            if (Xin.CheckKeyPress(Keys.Back))
            {
                if (text.Length != 0)
                {
                    text = text.Remove(text.Length - 1);
                }
            }
            if (Xin.IsKeyDown(Keys.RightShift) ||
                Xin.IsKeyDown(Keys.LeftShift))
            {
                newChar = newChar.ToUpper();
            }
            if (Xin.CheckKeyPress(Keys.Enter))
            {
                canType = false;
            }

            text += newChar;
        }