public static bool IsPushable(ObjectWithPosition obj) { return(obj.GetComponent <Draggable>()); }
// 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); }