public MoveToTargetPositionAction(GameObject toMove, StatefulActor charSelected, MovementStyle movementStyle, List <Vector2> positionsToMoveTo) { this.toMove = toMove; this.charSelected = charSelected; this.movementStyle = movementStyle; this.positionsToMoveTo = positionsToMoveTo; }
public void ChangeMovestyle(MovementStyle newMovementStyle) { _moveStyle = newMovementStyle; _navMeshAgent.acceleration = _moveStyle.Acceleration; _navMeshAgent.speed = _moveStyle.MoveSpeed; _navMeshAgent.angularSpeed = _moveStyle.AngularSpeed; }
public ShowMovementAvailableAction(MovementStyle movementStyle, Vector3 startPosition, StatefulActor charSelected, GameObject toMove, List <GridTile> tiles) { this.movementStyle = movementStyle; this.startPosition = startPosition; this.charSelected = charSelected; this.toMove = toMove; this.tiles = tiles; }
void Start() { inputController = FindObjectOfType <InputController>(); moveStyle = (MovementStyle)PlayerPrefs.GetInt("MovementStyle"); desiredPos = transform.position; desiredRotation = transform.rotation; oldPosition = transform.position; timeTracker = FindObjectOfType <TimeTracker>(); gameController = FindObjectOfType <GameController>(); }
//Similar to above, sets the movementStyle public void SetMovementStyle(MovementStyle movementType) { switch (movementType) { case MovementStyle.Standard: moveStyle = new StandardNormalizedMovement(); break; case MovementStyle.Constant: moveStyle = new ConstantNormalizedMovement(); break; } }
private void StartLevel(MovementStyle movementStyle) { controlsUI.SetActive(false); player.SetActive(true); Movement movement = player.GetComponent <Movement>(); if (movement != null) { movement.movementStyle = movementStyle; } levelUI.SetActive(true); enemySpawner.SetActive(true); }
public List <GridTile> GetTilesInCardinalDirections(GridTile start, MovementStyle style) { var toInstantiate = new List <GridTile>(); start.CurrentMovementValue = style.actionCost; tilesToReset.Add(start); foreach (Directions direction in System.Enum.GetValues(typeof(Directions))) { toInstantiate.AddRange(GetValidTilesInCardinalDirection(direction, start, style, new List <GridTile>())); } return(toInstantiate); }
public static void MouseRotateObject <T>(T objectToMove, MovementStyle movementStyle) where T : IRotatable { Cursor cursor = GuiManager.Cursor; if (cursor.YVelocity != 0) { cursor.StaticPosition = true; } float movementAmount = cursor.YVelocity / 8.0f; switch (movementStyle) { case MovementStyle.Group: objectToMove.RotationZ += movementAmount; break; case MovementStyle.Hierarchy: objectToMove.RotationZ += movementAmount; if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null) { (objectToMove as PositionedObject).SetRelativeFromAbsolute(); } break; case MovementStyle.IgnoreAttachments: objectToMove.RotationZ += movementAmount; if (objectToMove is PositionedObject) { PositionedObject asPositionedObject = objectToMove as PositionedObject; if (asPositionedObject.Parent != null) { asPositionedObject.SetRelativeFromAbsolute(); } foreach (PositionedObject child in asPositionedObject.Children) { //child.Position -= movementVector; if (mObjectsToIgnore.Contains(child) == false) { child.SetRelativeFromAbsolute(); } } } break; } }
private List <GridTile> GetValidTilesInChargeDirection(GridTile start, MovementStyle style) { var toInstantiate = new List <GridTile>(); //Can charge one additional tile past movement range start.CurrentMovementValue = style.actionCost + 1; tilesToReset.Add(start); foreach (Directions direction in System.Enum.GetValues(typeof(Directions))) { toInstantiate.AddRange(GetValidTilesInChargeDirection(direction, start, style, new List <GridTile>())); } return(toInstantiate); }
// Use this for initialization protected virtual void Start() { movementStyle = MovementStyle.VERTICAL; if (movementStyle != MovementStyle.NONE) { if (movementStyle == MovementStyle.HORIZONTAL) { moveAxes = new Vector3(1f, 0f, 0f); } else if (movementStyle == MovementStyle.VERTICAL) { moveAxes = new Vector3(0f, 1f, 0f); } moveAxes.Normalize(); } AddMessageHandlers(); }
private List <Vector3> GetTilesToCheckForShapeMove(GridTile start, MovementStyle movementStyle) { var offsetA = movementStyle.moveOffsetA; var offsetB = movementStyle.moveOffsetB; var startX = start.WorldLocation.x; var startY = start.WorldLocation.y; var offSets = GetOffsetsFromPosition(offsetA, offsetB); var tilesToCheck = new List <Vector3>(); foreach (KeyValuePair <int, int> offset in offSets) { tilesToCheck.Add(new Vector3(startX + offset.Key, startY + offset.Value)); } return(tilesToCheck); }
public List <GridTile> FloodFillTile(GridTile start, MovementStyle style) { var toInstantiate = new List <GridTile>(); start.CurrentMovementValue = style.actionCost; tilesToReset.Add(start); Queue <GridTile> queue = new Queue <GridTile>(); queue.Enqueue(start); while (queue.Count > 0) { var top = queue.Peek(); queue.Dequeue(); foreach (Directions direction in System.Enum.GetValues(typeof(Directions))) { GridTile shouldAdd; if (style.type == TypesOfMovement.FLYING_BY_REGION) { shouldAdd = CheckIfTileInRegion(top, direction, queue, style); } else if (style.type == TypesOfMovement.GROUND_BY_CHARGE_ATTACK) { //We need to find if a tile is elligble for a charge attack. The tile has to be occupied by an enemy and within an amount of moves = action points + 1 //If the tile is elligible for a charge attack it becomes the last elligible tile for a move in that direction. shouldAdd = null; } else { shouldAdd = CheckThenSetStateOfNeighborAtTile(top, direction, queue, style); } if (shouldAdd != null) { toInstantiate.Add(shouldAdd); } } } return(toInstantiate); }
public List <GridTile> GetTilesForShapeMove(GridTile start, MovementStyle movementStyle) { var tiles = new List <GridTile>(); var placesToCheck = GetTilesToCheckForShapeMove(start, movementStyle); foreach (Vector3 position in placesToCheck) { var tileAt = GridController.instance.GetTileAtPosition(position); if (tileAt != null) { if (movementStyle.elligibleStartingStates.Contains(tileAt.State)) { tileAt.UpdateState(movementStyle.targetState); tiles.Add(tileAt); } } } return(tiles); }
static Movement ParseMove(string[] tokens, MovementStyle style) { if (tokens.Length < 3) { return(null); } var res = new Movement(); res.Style = style; if (float.TryParse(tokens[1], out res.xCoord) && float.TryParse(tokens[2], out res.yCoord)) { return(res); } else { return(null); } }
public static void MouseMoveObjects <T>(PositionedObjectList <T> listToMove, MovementStyle movementStyle) where T : PositionedObject { if (movementStyle == MovementStyle.Group) { PositionedObjectList <T> topParents = listToMove.GetTopParents(); foreach (T positionedObject in topParents) { MouseMoveObject(positionedObject, movementStyle); } } else { foreach (PositionedObject positionedObject in listToMove) { MouseMoveObject(positionedObject, movementStyle); } } }
private void Awake() { myAnimator = GetComponent <Animator>(); moveTimer = new Timer(moveTime); moveTimer.OnComplete.AddListener(() => { FacePlayer(); travelDirection = Vector3.zero; pauseTimer.Start(); }); pauseTimer = new Timer(pauseTime); pauseTimer.OnComplete.AddListener(() => { FacePlayer(); FireProjectile(); moveStyle = (MovementStyle)(Random.Range(1, 3)); if (moveStyle == MovementStyle.Rotate) { rotationDirection = Random.Range(0, 1) * 2 - 1; travelDirection = Vector2.down.RotateDeg(Random.Range(-4, 3) * 45); myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(travelDirection)); } else { travelDirection = Vector2.down.RotateDeg(Random.Range(0, 4) * 90); myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(travelDirection)); } moveTimer.Start(); }); moveStyle = MovementStyle.Rotate; }
public List <GridTile> GetElligibleMovesFromPosition(GridTile start, MovementStyle style) { switch (style.type) { case TypesOfMovement.FLYING_BY_STRAIGHT_UNTIL_BARRIER: return(GetMovesInDirectionUntilBarrier(start, style)); case TypesOfMovement.FLYING_BY_REGION: case TypesOfMovement.GROUND_BY_FLOOD_FILL: return(FloodFillTile(start, style)); case TypesOfMovement.GROUND_BY_HOP: return(GetTilesForShapeMove(start, style)); case TypesOfMovement.GROUND_BY_SET_CARDINAL_DIRECTION: return(GetTilesInCardinalDirections(start, style)); case TypesOfMovement.GROUND_BY_CHARGE_ATTACK: return(GetValidTilesInChargeDirection(start, style)); default: return(new List <GridTile>()); } }
public List <GridTile> GetMovesInDirectionUntilBarrier(GridTile start, MovementStyle style) { var instantiated = new List <GridTile>(); var startX = start.WorldLocation.x; var startY = start.WorldLocation.y; var offsetsToTest = new List <KeyValuePair <int, int> > { new KeyValuePair <int, int>(0, 1), new KeyValuePair <int, int>(1, 1), new KeyValuePair <int, int>(1, 0), new KeyValuePair <int, int>(1, -1), new KeyValuePair <int, int>(0, -1), new KeyValuePair <int, int>(-1, -1), new KeyValuePair <int, int>(-1, 0), new KeyValuePair <int, int>(-1, 1) }; foreach (KeyValuePair <int, int> offset in offsetsToTest) { var currentOffset = 0; GridTile elligble = null; do { var testX = offset.Key; var testY = offset.Value; if (offset.Key > 0) { testX += currentOffset; } else if (offset.Key < 0) { testX -= currentOffset; } if (offset.Value > 0) { testY += currentOffset; } else if (offset.Value < 0) { testY -= currentOffset; } var location = new Vector3(startX + testX, startY + testY); var tileAt = GridController.instance.GetTileAtPosition(location); if (tileAt != null && style.elligibleStartingStates.Contains(tileAt.State)) { elligble = tileAt; currentOffset++; } else { break; } } while (true); if (elligble != null) { instantiated.Add(elligble); } } return(instantiated); }
private List <GridTile> GetValidTilesInChargeDirection(Directions direction, GridTile top, MovementStyle style, List <GridTile> accumulator) { var neighbor = GridController.instance.GetNeighborAt(direction, top.WorldLocation); if (neighbor != null && style.elligibleStartingStates.Contains(neighbor.State)) { var leftoverMovement = top.CurrentMovementValue - style.individualMoveCost; if (leftoverMovement >= 0 && leftoverMovement > neighbor.CurrentMovementValue) { if (leftoverMovement == 0 && neighbor.State != GridTile.MovementState.OCCUPIED) { //At the max charge distance and unoccupied, don't include this tile return(accumulator); } if (neighbor.State == GridTile.MovementState.OCCUPIED) { neighbor.CurrentMovementValue = 0; } else { neighbor.CurrentMovementValue = top.CurrentMovementValue - neighbor.Cost; } neighbor.UpdateState(style.targetState); accumulator.Add(neighbor); return(GetValidTilesInChargeDirection(direction, neighbor, style, accumulator)); } } return(accumulator); }
public Movement(MovementStyle s, float x, float y) { Style = s; xCoord = x; yCoord = y; }
private List <GridTile> GetValidTilesInCardinalDirection(Directions direction, GridTile top, MovementStyle style, List <GridTile> accumulator) { var neighbor = GridController.instance.GetNeighborAt(direction, top.WorldLocation); if (neighbor != null && style.elligibleStartingStates.Contains(neighbor.State)) { if (top.CurrentMovementValue - style.individualMoveCost >= 0 && top.CurrentMovementValue - style.individualMoveCost > neighbor.CurrentMovementValue) { neighbor.UpdateState(style.targetState); neighbor.CurrentMovementValue = top.CurrentMovementValue - neighbor.Cost; accumulator.Add(neighbor); return(GetValidTilesInCardinalDirection(direction, neighbor, style, accumulator)); } } return(accumulator); }
private GridTile CheckThenSetStateOfNeighborAtTile(GridTile top, Directions direction, Queue <GridTile> q, MovementStyle style) { var neighbor = GridController.instance.GetNeighborAt(direction, top.WorldLocation); if (neighbor != null && style.elligibleStartingStates.Contains(neighbor.State)) { if (top.CurrentMovementValue - style.individualMoveCost >= 0 && top.CurrentMovementValue - style.individualMoveCost > neighbor.CurrentMovementValue) { neighbor.UpdateState(style.targetState); neighbor.CurrentMovementValue = top.CurrentMovementValue - neighbor.Cost; q.Enqueue(neighbor); return(neighbor); } } return(null); }
public static void MouseMoveObject <T>(T objectToMove, MovementStyle movementStyle) where T : IStaticPositionable { Cursor cursor = GuiManager.Cursor; if (cursor.PrimaryPush) { return; } if (GuiManager.Cursor.ActualXVelocityAt(objectToMove.Z) == 0 && GuiManager.Cursor.ActualYVelocityAt(objectToMove.Z) == 0) { return; } #region Store the movement in the movementVector Vector3 movementVector = new Vector3(); #region If doing shift movement, then consider original position #if FRB_MDX bool isShiftDown = InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.LeftShift) || InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.RightShift); #elif FRB_XNA bool isShiftDown = InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) || InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift); #endif if (isShiftDown && HasValidStartPosition) { float xDistanceFromStart = Math.Abs((cursor.WorldXAt(0) - mGrabOffset.X) - mOriginalGrabPosition.X); float yDistanceFromStart = Math.Abs((cursor.WorldYAt(0) - mGrabOffset.Y) - mOriginalGrabPosition.Y); if (xDistanceFromStart > yDistanceFromStart) { movementVector.X = (cursor.WorldXAt(0) - mGrabOffset.X) - objectToMove.X; movementVector.Y = (mOriginalGrabPosition.Y) - objectToMove.Y; } else { movementVector.X = (mOriginalGrabPosition.X) - objectToMove.X; movementVector.Y = (cursor.WorldYAt(0) - mGrabOffset.Y) - objectToMove.Y; } } #endregion #region Else, just accumulate normally else { if (cursor.PrimaryDown) { movementVector.X = GuiManager.Cursor.WorldXChangeAt(objectToMove.Z); movementVector.Y = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z); } else if (cursor.SecondaryDown && mAllowZMovement) { movementVector.Z = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z); cursor.StaticPosition = true; } } #endregion #endregion #region Apply the movement vector according to the movementStyle switch (movementStyle) { case MovementStyle.Group: if (objectToMove is PositionedObject) { PositionedObject topParent = (objectToMove as PositionedObject).TopParent; topParent.X += movementVector.X; topParent.Y += movementVector.Y; topParent.Z += movementVector.Z; } else { objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; } break; case MovementStyle.Hierarchy: objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null) { (objectToMove as PositionedObject).SetRelativeFromAbsolute(); } break; case MovementStyle.IgnoreAttachments: objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; if (objectToMove is PositionedObject) { PositionedObject asPositionedObject = objectToMove as PositionedObject; if (asPositionedObject.Parent != null) { asPositionedObject.SetRelativeFromAbsolute(); } foreach (PositionedObject child in asPositionedObject.Children) { //child.Position -= movementVector; if (mObjectsToIgnore.Contains(child) == false) { child.SetRelativeFromAbsolute(); } } } break; } #endregion }
public void ChangeMovementStyle(int style) { moveStyle = (MovementStyle)style; }
private GridTile CheckIfTileInRegion(GridTile top, Directions direction, Queue <GridTile> q, MovementStyle style) { var neighbor = GridController.instance.GetNeighborAt(direction, top.WorldLocation); if (neighbor != null) { var moveNormallyEligible = top.CurrentMovementValue - style.individualMoveCost >= 0 && top.CurrentMovementValue - style.individualMoveCost > neighbor.CurrentMovementValue; var moveInExcludedRegion = moveNormallyEligible && (top.CurrentMovementValue - style.individualMoveCost > style.actionCost - style.regionFilter); if (moveNormallyEligible) { neighbor.CurrentMovementValue = top.CurrentMovementValue - neighbor.Cost; q.Enqueue(neighbor); if (!moveInExcludedRegion && style.elligibleStartingStates.Contains(neighbor.State)) { neighbor.UpdateState(style.targetState); return(neighbor); } else { neighbor.UpdateState(style.targetState); tilesToReset.Add(neighbor); } } } return(null); }