private void FixedUpdate() { if (Container == null) { return; } if (behaviour != null) { behaviour.Update(); if (oldDir != behaviour.GetDirection()) { oldDir = behaviour.GetDirection(); Rotat(oldDir); } } }
public override void Update(GameTime gameTime) { if (_behaviour != null) { _behaviour.Update(gameTime); } if (_isMoving && _distSinceMove < MAX_MOVE_DIST) { // Calculate movement speed based on terrain float moveSpeed = (_currentTerrain == TileTerrain.Grass) ? MAX_MOVE_DIST / 500.0f : MAX_MOVE_DIST / 320.0f; // Calculate how far to move this frame float distanceThisFrame = moveSpeed * (float)gameTime.ElapsedGameTime.TotalMilliseconds; // Advance the total distance moved _distSinceMove += distanceThisFrame; // Check if we reached the target tile if (_distSinceMove > MAX_MOVE_DIST) { _isMoving = false; _distSinceMove = MAX_MOVE_DIST; } // Update the position based on previous position +/- total distance moved switch (_direction) { case Direction.dRight: _position.X = (int)(_previousPosition.X + _distSinceMove); break; case Direction.dLeft: _position.X = (int)(_previousPosition.X - _distSinceMove); break; case Direction.dDown: _position.Y = (int)(_previousPosition.Y + _distSinceMove); break; case Direction.dUp: _position.Y = (int)(_previousPosition.Y - _distSinceMove); break; } } }