/// <summary> /// Gets the angle of a Launcher in radians. /// </summary> /// <param name="tile"></param> /// <returns>The angle in radians of the Tile.</returns> public static Single getRotationInRadians(Tile tile) { Single rotationInRadians; float rotationInDegrees = getAngleInDegrees(tile) - 90; // It's negative so it points the correct direction. // Now that the center point has been set, set the Tile's rotation to the angle specified by its representation. rotationInRadians = MathHelper.ToRadians(rotationInDegrees); return rotationInRadians; }
/// <summary> /// Gets the angle of a Tile in degrees. /// </summary> /// <param name="tile"></param> /// <returns>The angle at which the Launcher should launch the Guy/Shoes, depending on which Launcher is passed in.</returns> public static int getAngleInDegrees(Tile tile) { if (tile.TileRepresentation == '1' || tile.TileRepresentation == '!' || tile.TileRepresentation == 'z') return 315; // Down Left else if (tile.TileRepresentation == '2' || tile.TileRepresentation == '@' || tile.TileRepresentation == 'x') return 270; // Down else if (tile.TileRepresentation == '3' || tile.TileRepresentation == '#' || tile.TileRepresentation == 'c') return 225; // Down Right else if (tile.TileRepresentation == '4' || tile.TileRepresentation == '$' || tile.TileRepresentation == 'a') return 0; // Left else if (tile.TileRepresentation == '6' || tile.TileRepresentation == '^' || tile.TileRepresentation == 'd') return 180; // Right else if (tile.TileRepresentation == '7' || tile.TileRepresentation == '&' || tile.TileRepresentation == 'q') return 45; // Up Left else if (tile.TileRepresentation == '8' || tile.TileRepresentation == '*' || tile.TileRepresentation == 'w') return 90; // Up else if (tile.TileRepresentation == '9' || tile.TileRepresentation == '(' || tile.TileRepresentation == 'e') return 135; // Up Right else return -1; }
/// <summary> /// Loads the next Level. /// </summary> public void LoadLevel() { impassableTileRecs = new List<Rectangle>(); impassableTilePos = new List<Vector2>(); if (currentLevel + 1 <= totalLevels) { currentLevel++; } else { currentLevel = 1; } // This array will store a level. Each element in the array will be // a line of tiles. // 0 - **** // 1 - **** // 2 - **** // ... // The problem is lines is only getting 45 // Only goes to 65 lines = System.IO.File.ReadAllLines("Content/Levels/" + currentLevel.ToString() + ".txt"); int length = lines.Length; debug = numberOfTilesInRow.ToString(); // The outer loop goes through the columns. for (int column = 0; column < numberOfTileColumns; column++) { // The inner loop goes through the rows. for (int row = 0; row < numberOfTilesInRow; row++) { // The first position of the block is (0, 0), followed by (64, 0), (128, 0), etc. // Going up the y axis works the same way. (0, 0), (0, 64), (0, 128), etc. // Create a new tile in each position of the grid. We give Tile() the character in the string 'lines'. tiles[column, row] = new Tile(lines[column][row], ref contentManager); // Set the position of the tile in the Level array. tiles[column, row].PositionInArray = new Vector2(column, row); // Set the position of a new tile. tiles[column, row].Position = new Vector2((row * 16), (column * 16)); // Draw a rectangle around the tile. We need this for collision detection. tiles[column, row].SourceRect = new Rectangle((int)tiles[column, row].Position.X, (int)tiles[column, row].Position.Y, 16, 16); // Set the rotation and center for the tile. if (tiles[column, row].IsLauncher || tiles[column, row].IsAirCannon) { tiles[column, row].Center = new Vector2(16 / 2, 16 / 2); tiles[column, row].Rotation = Tile.getRotationInRadians(tiles[column, row]); } else { tiles[column, row].Center = new Vector2(0, 0); } // We are going to store all the impassable tiles rectangles in a list. We will use this for collision detection. if (tiles[column, row].CollProperties == Tile.CollisionProperty.Impassable) { impassableTileRecs.Add(tiles[column, row].SourceRect); impassableTilePos.Add(tiles[column, row].Position); } if (tiles[column, row].TileRepresentation == 'G') { goalRectangle = tiles[column, row].SourceRect; } if (tiles[column, row].TileRepresentation == 'P') { playerStartingPosition = tiles[column, row].Position; } } } }