public void PlayerTileCollide(Grass grass) { double value = RandomExtension.NextDouble(rnd, 0.01, 99.99); if (value <= veryCommon) { game.gameState = new EncounterGameState(game); } }
public Grass builder(GrassType type, Vector2 location) { factory = new SpriteFactory(); if (type == GrassType.shortGrass) { state = new GrassTileState(SpriteFactory.sprites.grass); } if (type == GrassType.tallGrass) { state = new GrassTileState(SpriteFactory.sprites.grass); } Grass product = new Grass(state, location); return product; }
public Grass builder(GrassType type, Vector2 location) { factory = new SpriteFactory(); if (type == GrassType.shortGrass) { state = new GrassTileState(SpriteFactory.sprites.grass); } if (type == GrassType.tallGrass) { state = new GrassTileState(SpriteFactory.sprites.grass); } Grass product = new Grass(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); }