Exemple #1
0
 public void PlayNowOrAfterMove(Backend.Activity activity, bool locked = false)
 {
     if (this.isMoving)
     {
         _playAfterMove = activity;
     }
     if (locked)
     {
         _lock = true;
     }
 }
Exemple #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (!_blockUpdates)
            {
                Backend.Direction tmp = _actor.direction;
                if ((tmp != Backend.Direction.None) && ((int)tmp > -1) && (tmp != _prevDir)) _prevDir = tmp;
                if (_effect != null)
                {
                    if (_effect.finished)
                    {
                        _effect = null;
                    }
                    else
                    {
                        _effect.Update(gametime);
                    }

                }
                _elapsed += gametime.ElapsedGameTime.Milliseconds;

                if (_target != _position)
                {
                    if (_elapsed > _animationTime / _moveAccel)
                    {

                        if (!_nomove)
                        {
                            _nomove = true;
                            Animate(true);
                        }
                        else
                        {
                            _nomove = false;
                        }
                        //  System.Diagnostics.Debug.WriteLine("ENDED AT " + _textures[(int)_activity * 8 + (int)Math.Log((double)_direction,2)].animationID);

                        // System.Diagnostics.Debug.WriteLine(_textures[(int)_activity * 8 + (int)Math.Log((double)_direction,2)].animationID);

                        _elapsed -= _animationTime / _moveAccel;

                        if (_target.x > _position.x)
                        {
                            //   if (_id == 0) System.Diagnostics.Debug.Write(_xpertick.ToString());

                            _position.x += _xpertick;

                        }
                        else
                        {
                            if (_target.x < _position.x)
                            {
                                //     if (_id == 0) System.Diagnostics.Debug.Write(-_xpertick);

                                _position.x -= Math.Min(_xpertick, Math.Abs(_target.x - _position.x));

                            }
                            //else
                            //     if (_id == 0) System.Diagnostics.Debug.Write("0");
                        }

                        if (_target.y > _position.y)
                        {
                            //   if (_id == 0) System.Diagnostics.Debug.WriteLine("/" + _ypertick.ToString());
                            _position.y += _ypertick;
                        }
                        else
                            if (_target.y < _position.y)
                            {
                                // if (_id == 0) System.Diagnostics.Debug.WriteLine("/-" + _ypertick.ToString());

                                _position.y -= _ypertick;
                            }
                            else
                            {
                                //  if (_id == 0) System.Diagnostics.Debug.WriteLine("/0");
                            }
                        if (_focussed)
                            _camera.position = new Vector2(-38 - position.x, -30 - position.y);

                        if (_target == _position)
                        {
                            //                            _position = _target;
                            //                          _target = _cacheTarget;
                            _parent.HandleEvent(false, Backend.Events.TileEntered, _id, direction);

                        }
                    }
                }
                else
                {

                    if (_elapsed > _animationTime)
                    {
                        _elapsed -= _animationTime;
                        if (_playAfterMove != Backend.Activity.Walk)
                        {
                            this.activity = _playAfterMove;
                            _playAfterMove = Backend.Activity.Walk;
                        }
                        Animate(false);
                    }
                }
            }
        }
Exemple #3
0
        public void Animate(bool hasMoved)
        {
            if (_activity != Backend.Activity.Walk)
            {
                if (_textures[(int)_activity * 8 + (int)Math.Log((double)direction, 2)].NextAnimation())
                {
                    if (_activity != Backend.Activity.Die)
                    {
                        _parent.HandleEvent(false, Backend.Events.FinishedAnimation, _id, _activity);
                        this.activity = _playAfterMove;
                        if (_playAfterMove != Backend.Activity.Walk) _playAfterMove = Backend.Activity.Walk;
                        _lock = false;
                        _dead = false;
                    }
                    else
                    {
                        if (!_dead)
                        {
                            _parent.HandleEvent(false, Backend.Events.FinishedAnimation, _id, _activity);
                            _dead = true;
                            _lock = false;

                        }
                    }
                }
            }
            else
            {
                if (hasMoved)
                {
                    _textures[(int)_activity * 8 + (int)Math.Log((double)direction, 2)].NextAnimation();
                }
            }
        }