Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Controller != null)
            {
                Controller.Update(gameTime);
            }

            if (!movedLastFrame && MovementState == MovementState.None)
            {
                Face(Facing);
            }

            if (movement != Vector2.Zero)
            {
                Vector2 facing  = Facing.ToVector2();
                float   speed   = this.MovementSpeed.GetSpeed();
                float   elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

                this.movement += facing * speed * elapsed;

                if (this.movement.X < 0 && this.Facing == Facing.Left)
                {
                    this.movement.X = 0;
                }
                if (this.movement.X > 0 && this.Facing == Facing.Right)
                {
                    this.movement.X = 0;
                }
                if (this.movement.Y < 0 && this.Facing == Facing.Up)
                {
                    this.movement.Y = 0;
                }
                if (this.movement.Y > 0 && this.Facing == Facing.Down)
                {
                    this.movement.Y = 0;
                }

                movedLastFrame = true;
                this.Moving.SafeInvoke(this, EventArgs.Empty);

                if (movement == Vector2.Zero)
                {
                    movedLastFrame     = false;
                    this.MovementState = MovementState.None;
                    EndMoving.SafeInvoke(this, EventArgs.Empty);
                }
            }

            for (int i = 0; i < Effects.Count; i++)
            {
                IEffect effect = Effects[i];
                if (!effect.Alive)
                {
                    Effects.RemoveAt(i--);
                }
                effect.Update(gameTime);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finishes dragging, and invokes the EndMoving event.
        /// </summary>
        /// <param name="args">Mouse event arguments.</param>
        protected override void OnMouseUp(MouseEventArgs args)
        {
            if (args.Button == MouseButtons.Left)
            {
                this.isDragging = false;

                if (EndMoving != null)
                {
                    EndMoving.Invoke(this);
                }
            }
        }
Esempio n. 3
0
        protected virtual void OnEndUpdating(IntPtr handle)
        {
            switch (_state)
            {
            case State.Moving:
                System.Diagnostics.Debug.WriteLine($"End moving");
                EndMoving?.Invoke(this, handle);
                break;

            case State.Resizing:
                System.Diagnostics.Debug.WriteLine($"End resizing");
                EndResizing?.Invoke(this, handle);
                break;

            default: break;
            }
            _state = State.None;
        }