/** * Changes the alpaca's coordinates depending on the click location, and * the surrounding blocks. */ void MoveOnClick() { // change facing direction before walking in that direction if (lastClickedWhere != clickedWhere) { // Debug.Log("lastClickedWhere " + lastClickedWhere + " clickedWhere " + clickedWhere); alpaca.SetFacingDirection(clickedWhere); lastClickedWhere = clickedWhere; return; } Vector3 curr = alpaca.GetCurrAlpacaLocation(); Vector3 dest = alpaca.GetCurrAlpacaDest(clickedWhere); if (GetBlockAt(dest) != null) // Is there a block right in front? --> climb mode { if (GetBlockAbove(curr) != null) // Is there a block above alpaca? { return; } else { if (GetBlockAbove(dest) != null) // Is there a block above the block right in front of alpaca? { return; } else if (GetBlockAt(dest).b_type != Block.BlockType.WALL) // Does the block NOT ban walking / is not a wall? { jumpSound.Play(); dest.y++; alpaca.Move(dest); scoreboardController.incrementNumMoves(); } } } else { if (GetBlockBelow(dest) != null) // Is there a block that can walk on straight? { if (GetBlockBelow(dest).b_type != Block.BlockType.WALL) // Is it a block we can walk on? { alpaca.Move(dest); scoreboardController.incrementNumMoves(); } } else { Block top = map.GetHighestBlockBelow(dest); if (top != null && top.b_type != Block.BlockType.WALL) // Is there a block alpaca can fall on? { dest = top.getCoords(); dest.y++; alpaca.Move(dest); scoreboardController.incrementNumMoves(); } } } }
/** * Changes the alpaca's coordinates depending on the click location, and * the surrounding blocks. */ void MoveOnClick() { // change facing direction before walking in that direction if (lastClickedWhere != clickedWhere) { alpaca.SetFacingDirection(clickedWhere); alpaca.UpdateWalk(); lastClickedWhere = clickedWhere; return; } Vector3 curr = alpaca.GetCurrAlpacaLocation(); Vector3 dest = alpaca.GetCurrAlpacaDest(clickedWhere); // Check that where we're trying to move is acceptable if (GetBlockAt(dest) != null) // Is there a block right in front? --> climb mode { if (GetBlockAbove(curr) != null) // Is there a block above alpaca? { return; } else { if (GetBlockAbove(dest) != null) // Is there a block above the block right in front of alpaca? { return; } else if (GetBlockAt(dest).b_type != Block.BlockType.WALL && GetBlockAt(dest).b_type != Block.BlockType.NPC) // Does the block NOT ban walking / is not a wall or NPC? // jumpSound.Play(); { dest.y++; alpaca.Move(dest); } } } else { if (GetBlockBelow(dest) != null) // Is there a block that can walk on straight? { if (GetBlockBelow(dest).b_type != Block.BlockType.WALL) // Is it a block we can walk on? { alpaca.Move(dest); } } else // Should we fall onto a block below and in front of alpaca? { Block top = map.GetHighestBlockBelow(dest); if (top != null && top.b_type != Block.BlockType.WALL && top.b_type != Block.BlockType.NPC) // Is there a block alpaca can fall on? { dest = top.getCoords(); dest.y++; alpaca.Move(dest); } } } }