public Projectile(uint id, Backend.IHandleEvent parent, Backend.Coords current, Backend.Direction dir, ProjectileTile tile) { _dir = dir; _id = id; _tile = tile; _current = Mainmap._map2screen(current); _target = Mainmap._map2screen(current); // System.Diagnostics.Debug.WriteLine("Start at" + _current); _parent = parent; }
/// <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); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="parent">parentobject</param> /// <param name="dir">The direction in which the projectile will be shot</param> /// <param name="id"></param> public ProjectileTile(Backend.FloorTile parent, Backend.Direction dir, uint id = 0) : base(parent) { _direction = dir; _id = 0; }