Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            UpdateKeys();

            Animation animation = charDef.GetAnimation(selAnim);
            KeyFrame  keyframe  = animation.GetKeyFrame(curKey);

            if (playing)
            {
                curFrame += (float)gameTime.ElapsedGameTime.TotalSeconds * 30.0f;

                if (curFrame > (float)keyframe.duration)
                {
                    curFrame -= (float)keyframe.duration;
                    curKey++;
                    keyframe = animation.GetKeyFrame(curKey);

                    if (curKey >=
                        animation.getKeyFrameArray().Length)
                    {
                        curKey = 0;
                    }
                }
            }
            else
            {
                curKey = selKeyFrame;
            }

            if (keyframe.frameRef < 0)
            {
                curKey = 0;
            }


            mouseState = Mouse.GetState();


            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                if (preState.LeftButton == ButtonState.Released)
                {
                }
                else
                {
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        charDef.GetFrame(selFrame).GetPart(selPart).location +=
                            new Vector2((float)xM / 2.0f, (float)yM / 2.0f);
                    }
                }
            }
            else
            {
                if (preState.LeftButton == ButtonState.Pressed)
                {
                    mouseClick = true;
                }
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                if (preState.RightButton == ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int yM = mouseState.Y - preState.Y;

                        charDef.GetFrame(selFrame).GetPart(selPart).rotation +=
                            (float)yM / 100.0f;
                    }
                }
            }

            if (mouseState.MiddleButton == ButtonState.Pressed)
            {
                if (preState.MiddleButton == ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        charDef.GetFrame(selFrame).GetPart(selPart).scaling +=
                            new Vector2((float)xM * 0.01f, (float)yM * 0.01f);
                    }
                }
            }

            preState = mouseState;

            base.Update(gameTime);
        }