override public bool PrepareMovement(MovementHelper.Direction playerDirection) { MovementHelper.Direction direction = MovementHelper.Direction.NONE; float rand = Random.value; if (rand < .3) { direction = MovementHelper.Direction.MOVE_FORWARD; } else if (rand > .3 && rand < .5) { direction = MovementHelper.Direction.STRAFE_RIGHT; } else if (rand > .5 && rand < .7) { direction = MovementHelper.Direction.STRAFE_LEFT; } else if (rand > .7) { direction = MovementHelper.Direction.MOVE_BACKWARD; } mv.PrepareMovement(posX, posY, direction); return(false); }
private void Update() { MovementHelper.Direction direction = MovementHelper.Direction.NONE; if (Input.GetKey(KeyCode.X)) { player.TakeDamage(1); } if (Input.GetKey(KeyCode.C)) { player.Heal(1); } if (Input.GetKey(KeyCode.UpArrow)) { direction = MovementHelper.Direction.MOVE_FORWARD; } else if (Input.GetKey(KeyCode.DownArrow)) { direction = MovementHelper.Direction.MOVE_BACKWARD; } else if (Input.GetKey(KeyCode.LeftArrow)) { direction = MovementHelper.Direction.TURN_LEFT; } else if (Input.GetKey(KeyCode.RightArrow)) { direction = MovementHelper.Direction.TURN_RIGHT; } else if (Input.GetKey(KeyCode.J)) { direction = MovementHelper.Direction.STRAFE_LEFT; } else if (Input.GetKey(KeyCode.K)) { direction = MovementHelper.Direction.STRAFE_RIGHT; } if (direction != MovementHelper.Direction.NONE) { bool playerIsMoving = player.PrepareMovement(direction); if (playerIsMoving) { foreach (MovableObject m in movableObjects) { m.PrepareMovement(direction); } } } }
/// <summary> /// Moves the active piece in the given direction. /// </summary> private void MovePiece(MovementHelper.Direction direction) { var defaultPanel = new BackgroundTile().Default().BackColor; var newPlacement = _movementHelper.CalculateMovement(direction, _piece.CurrentPlacement); // Clear the current piece from the game grid // so we don't interfere with collision detection DrawPlacement(_piece.CurrentPlacement, defaultPanel); // Ensure next placement is valid if (_movementHelper.CheckIfMoveIsValid(newPlacement, tlpGameGrid)) { // Paint piece in new location DrawPlacement(newPlacement, _piece.Color); // Piece moved successfully, so update the piece _piece.CurrentPlacement = newPlacement; } else { DrawPlacement(_piece.CurrentPlacement, _piece.Color); SpawnNewPiece(); } }
abstract public bool PrepareMovement(int posX, int posY, MovementHelper.Direction direction);
virtual public bool PrepareMovement(MovementHelper.Direction direction) { return(mv.PrepareMovement(posX, posY, direction)); }
override public bool PrepareMovement(int posX, int posY, MovementHelper.Direction direction) { if (isMoving) { return(false); } bool newMovement = false; Vector3 futureMovement = MovementHelper.noMovement; MovementHelper.Orientation orientation = MovementHelper.GetOrientation(entity.transform); if (direction == MovementHelper.Direction.TURN_RIGHT) { futureMovement = new Vector3(0, 90, 0); newMovement = true; isTranslate = false; } else if (direction == MovementHelper.Direction.TURN_LEFT) { futureMovement = new Vector3(0, -90, 0); newMovement = true; isTranslate = false; } else if (direction == MovementHelper.Direction.STRAFE_LEFT && MovementHelper.CanMoveInDirection(posX, posY, MovementHelper.Left(orientation))) { futureMovement = new Vector3(-1, 0.0f, 0); newMovement = true; isTranslate = true; entity.MoveOneTile(MovementHelper.Left(orientation)); } else if (direction == MovementHelper.Direction.STRAFE_RIGHT && MovementHelper.CanMoveInDirection(posX, posY, MovementHelper.Right(orientation))) { futureMovement = new Vector3(1, 0.0f, 0); newMovement = true; isTranslate = true; entity.MoveOneTile(MovementHelper.Right(orientation)); } else if (direction == MovementHelper.Direction.MOVE_FORWARD && MovementHelper.CanMoveInDirection(posX, posY, orientation)) { futureMovement = new Vector3(0, 0.0f, 1); newMovement = true; isTranslate = true; entity.MoveOneTile(orientation); } else { MovementHelper.Orientation oppositeOrientation = MovementHelper.Back(MovementHelper.GetOrientation(entity.transform)); if (direction == MovementHelper.Direction.MOVE_BACKWARD && MovementHelper.CanMoveInDirection(posX, posY, oppositeOrientation)) { futureMovement = new Vector3(0, 0.0f, -1); newMovement = true; isTranslate = true; entity.MoveOneTile(MovementHelper.Back(orientation)); } } if (newMovement) { isMoving = true; framesLeftToMove = Conf.moveTimer; pauseFrames = Conf.pauseTimer; } nextMove = futureMovement; return(newMovement && isTranslate); }