public Ledge builder(LedgeType type, Vector2 location) { factory = new SpriteFactory(); if (type == LedgeType.ledgeLeftCurve) { state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftCurve); } if (type == LedgeType.ledgeLeftEnd) { state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftEnd); } if (type == LedgeType.ledgeMiddle) { state = new LedgeTileState(SpriteFactory.sprites.ledgeMiddle); } if (type == LedgeType.ledgeRightCurve) { state = new LedgeTileState(SpriteFactory.sprites.ledgeRightCurve); } if (type == LedgeType.ledgeRightEnd) { state = new LedgeTileState(SpriteFactory.sprites.ledgeRightEnd); } Ledge product = new Ledge(state, location); return product; }
public void PlayerTileCollide(Player player, Ledge ledge) { Rectangle playerBox = player.state.GetBoundingBox(player.position); Rectangle ledgeBox = ledge.GetBoundingBox(); Rectangle intersection = Rectangle.Intersect(playerBox, ledgeBox); if (intersection.Height > intersection.Width) { if (playerBox.Right > ledgeBox.Left && playerBox.Right < ledgeBox.Right) { player.position.X -= intersection.Width; } else { player.position.X += intersection.Width; } } else if (intersection.Height < intersection.Width) { if (playerBox.Bottom > ledgeBox.Top && playerBox.Bottom < ledgeBox.Bottom) { if (intersection.Height > 1) { //player.position.Y -= intersection.Height; } } else { player.position.Y += intersection.Height; } } }
public Ledge builder(LedgeType type, Vector2 location) { factory = new SpriteFactory(); if (type == LedgeType.ledgeLeftCurve) { state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftCurve); } if (type == LedgeType.ledgeLeftEnd) { state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftEnd); } if (type == LedgeType.ledgeMiddle) { state = new LedgeTileState(SpriteFactory.sprites.ledgeMiddle); } if (type == LedgeType.ledgeRightCurve) { state = new LedgeTileState(SpriteFactory.sprites.ledgeRightCurve); } if (type == LedgeType.ledgeRightEnd) { state = new LedgeTileState(SpriteFactory.sprites.ledgeRightEnd); } Ledge product = new Ledge(state, location); return(product); }
public Player Build(string fileName) { float xCoord = 0, yCoord = 0; StreamReader sr; sr = File.OpenText(Game1.GetInstance().Content.RootDirectory + "\\" + fileName); string line; int reference = 0; // LEVEL DESTINATIONS int currDest = 0; List <string> destinations = new List <string>(); // LEVEL TILES List <TileFactory.TileType> tileChoices = new List <TileFactory.TileType>(); tileChoices.Add(TileFactory.TileType.grass); tileChoices.Add(TileFactory.TileType.pokePlainFloor); int tileNumber = 0; // LEVEL DATA line = sr.ReadLine(); string[] initialWords = line.Split(','); try { tileNumber = Int32.Parse(initialWords[0]); } catch { } for (int i = 0; i < initialWords.Length; i++) { if (initialWords[i].Contains("Levels")) { destinations.Add(initialWords[i]); } } // MAIN LEVEL while ((line = sr.ReadLine()) != null) { xCoord = 0; string[] words = line.Split(','); for (int i = 0; i < words.Length; i++) { if (words[i].Length > 1) { try { string tmp = words[i].Remove(1); reference = Int32.Parse(words[i][1].ToString()); words[i] = tmp; } catch { // exception here } } if (xCoord % 32 == 0 && yCoord % 32 == 0) { Tile tile = tileFactory.builder(tileChoices[tileNumber], new Vector2(xCoord, yCoord)); level.levelBackground.Add(tile); } if (words[i] == "P") { player = new Player(new Vector2(xCoord, yCoord)); } if (tileDictionary.ContainsKey(words[i])) { Tile tile = tileFactory.builder(tileDictionary[words[i]], new Vector2(xCoord, yCoord)); if (words[i] == "0" || words[i] == "q") { tile.collision = false; } if (words[i] == "q") { tile.position.X += 8f; tile.position.Y += 4f; } if (words[i] == "p") { tile.sign = true; tile.signTex = factory.builder(SpriteFactory.sprites.instructions); } level.levelTiles.Add(tile); } if (grassDictionary.ContainsKey(words[i])) { Grass grass = grassFactory.builder(grassDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelGrass.Add(grass); } if (ledgeDictionary.ContainsKey(words[i])) { Ledge ledge = ledgeFactory.builder(ledgeDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelLedges.Add(ledge); } if (buildingDictionary.ContainsKey(words[i])) { Building building = buildingFactory.builder(buildingDictionary[words[i]], new Vector2(xCoord, yCoord)); if (words[i] == "I") { building.isDoor = true; building.destination = destinations[currDest]; building.source = fileName; currDest++; } level.levelBuildings.Add(building); } if (exitDictionary.ContainsKey(words[i])) { Exit exit = new Exit(factory.builder(exitDictionary[words[i]]), new Vector2(xCoord, yCoord)); exit.destination = destinations[currDest]; currDest++; level.levelExits.Add(exit); } if (enemyDictionary.ContainsKey(words[i])) { Enemy enemy = enemyFactory.builder(enemyDictionary[words[i]], new Vector2(xCoord, yCoord), reference); level.levelEnemies.Add(enemy); } xCoord += spacingIncrement; } yCoord += spacingIncrement; } return(player); }