// Move over a distance. protected bool Move(int direction, int distance, float movementSpeed) { if (isMoving) { return(false); } int newLayer; if (IsMoveObstructed(direction, out newLayer)) { return(false); } this.movementSpeed = movementSpeed; this.moveDistance = distance; this.moveDirection = Directions.ToPoint(direction); this.isMoving = true; this.hasMoved = true; this.currentMoveDistance = 0; // Move the tile one step forward. Point2I oldLocation = location; RoomControl.MoveTile(this, location + moveDirection, newLayer); offset = -Directions.ToVector(direction) * GameSettings.TILE_SIZE; // Fire the OnMove event. GameControl.ExecuteScript(properties.GetString("on_move", "")); return(true); }
private void UpdateMovement() { // Update movement. if (isMoving) { velocity = (Vector2F)moveDirection * movementSpeed; if (offset.Dot(moveDirection) >= 0.0f) { currentMoveDistance++; offset -= (Vector2F)(moveDirection * GameSettings.TILE_SIZE); if (currentMoveDistance >= moveDistance) { offset = Vector2F.Zero; velocity = Vector2F.Zero; moveDirection = Point2I.Zero; isMoving = false; CheckSurfaceTile(); if (IsDestroyed) { return; } OnCompleteMovement(); } else { roomControl.MoveTile(this, location + moveDirection, layer); } } else if (currentMoveDistance + 1 >= moveDistance) { // Don't overshoot the destination. float overshoot = (offset + velocity).Dot(moveDirection); if (overshoot >= 0.0f) { velocity -= overshoot * (Vector2F)moveDirection; } } } // Update path following. else if (path != null) { TilePathMove move = path.Moves[pathMoveIndex]; // Begin the next move in the path after the delay has been passed. if (pathTimer >= move.Delay) { Move(move.Direction, move.Distance, move.Speed); pathTimer = 0; pathMoveIndex++; if (pathMoveIndex >= path.Moves.Count) { if (path.Repeats) { pathMoveIndex = 0; } else { path = null; } } } pathTimer++; } // Integrate velocity. if (isMoving) { offset += velocity; } else { velocity = Vector2F.Zero; } }