// True if the player actually moved public bool MovePlayer(GeneratedLevel generatedLevel, ref Constants constants, List <ObjectWithPosition> objects, bool[] moveWorker, out bool wasJump) { wasJump = false; int x = pos.X; int y = pos.Y; bool triedMove = false; bool moveSucceeded = false; if (Input.GetButtonDown("Horizontal")) { x += (Input.GetAxisRaw("Horizontal") < 0) ? -1 : 1; triedMove = true; } else if (Input.GetButtonDown("Vertical")) { int upDown = (Input.GetAxisRaw("Vertical") > 0) ? -1 : 1; y += upDown; if (upDown < 0) // Direction only when going up? Actually let's make water reset direction { wasJump = true; x += pos.Direction; } triedMove = true; } else if (Input.GetButtonDown("Jump")) { y -= 1; x += pos.Direction; triedMove = true; wasJump = true; } if (triedMove) { if (MoveHelper.CanMove_AndMaybePush(pos, x - pos.X, y - pos.Y, generatedLevel, objects, moveWorker)) { moveSucceeded = true; } else { if ((x != pos.X) && (y != pos.Y)) // We failed a diagonal jump. Try just straight up. { x = pos.X; if (MoveHelper.CanMove_AndMaybePush(pos, x - pos.X, y - pos.Y, generatedLevel, objects, moveWorker)) { moveSucceeded = true; } } } if (moveSucceeded) { pos.Direction = x - pos.X; // Set a left/right direction! pos.X = x; pos.Y = y; } else { // If you didn't succeed in moving, but you tried to go left/right, change your direction and count as a move int direction = x - pos.X; if (direction != 0) { pos.Direction = direction; // ACTUALLY NO... for the second create puzzle this is needed. //moveSucceeded = true; } } } return(moveSucceeded); }
// Handles falling. private MoveResult ProcessMoveResultsImmediately(PlayerController pc) { MoveResult result = MoveResult.None; // Add a new state frame levelState.AddFrame(); // Can we descend the camera? DescendCamera(levelState.Current); // Player falls, maybe - unless they hit water? // This is a bit tricky, because we also need to push things down. ObjectWithPosition thePlayer = pc.GetComponent <ObjectWithPosition>(); bool somethingMoved = true; bool bail = false; foreach (ObjectWithPosition pos in levelState.Objects) { // Store the transitionary states so we can do nice lerping. pos.XIntermediate = pos.X; pos.YIntermediate = pos.Y; } int fallAmount = 0; while (somethingMoved && !bail) { somethingMoved = false; ClearMoveWorker(); for (int i = 0; i < levelState.Objects.Count; i++) { ObjectWithPosition pos = levelState.Objects[i]; Gravity gravity = pos.GetComponent <Gravity>(); int direction = gravity ? gravity.Direction : 0; bool isWater = generatedLevel.IsWater(pos.X, pos.Y); if ((!isWater) && direction != 0) // Things float in water. { int x = pos.X; int y = pos.Y + direction; //if (generatedLevel.IsBlocked(x, y)) if (MoveHelper.CanMove_AndMaybePush(pos, 0, 1, generatedLevel, levelState.Objects, moveWorker)) { pos.Y = y; somethingMoved = true; } } if (isWater) { pos.Direction = 0; // Resets direction } if (thePlayer == pos) { if ((GetBottomDeathRow() == pos.Y) || (pos.Y <= levelState.Current.YCamera)) { result = MoveResult.Death; bail = true; break; // They're gonna die. } if (Constants.Exit == generatedLevel.GetWorldPieceAt(pos.X, pos.Y)) { result = MoveResult.Exit; bail = true; break; } if (somethingMoved) { fallAmount++; if (fallAmount > 3) { FallSound.Play(); } } } } } levelState.SaveStates(); // Does that for the objects only, camera is already updated. return(result); }