private Room LoadRoom(string path) { StreamReader reader = new StreamReader(path); int width, height; Int32.TryParse(reader.ReadLine(), out width); Int32.TryParse(reader.ReadLine(), out height); Room room = new Room(width, height); for (int y = 0; y < height; y++) { string row = reader.ReadLine(); for (int x = 0; x < width; x++) { char tile = row[x]; switch (tile) { case '1': room.AddEntity(new Wall(x, y)); break; case '@': Player p = new Player(); p.X = x; p.Y = y; //p.Sprite.X -= 0.5f; //p.Sprite.Y -= 0.5f; room.AddEntity(p); break; case 'e': Enemy e = new Enemy(); e.X = x; e.Y = y; room.AddEntity(e); break; } } } return(room); }
private void Travel(Room destination) { if (destination == null) { return; } MyScene.RemoveEntity(this); destination.AddEntity(this); Game.CurrentScene = destination; }
//Move the Player to the destination Room and change the Scene private void Travel(Room destination) { //Ensure destination is not null if (destination == null) { return; } //Remove the Player from its current Room CurrentScene.RemoveEntity(this); //Add the Player to the destination Room destination.AddEntity(this); //Change the Game's active Scene to the destination Game.CurrentScene = destination; }
//private void Exit() //{ // Game.gameOver = true; //} //Move the Player to the destination room and change the Scene private void Travel(Room destination) { if (destination == null) { return; } //If the Player is holding the sword if (_sword.Parent == this) { //Remove the sword from the current Room TheScene.RemoveEntity(_sword); //Add the sword to the current Room TheScene.AddEntity(_sword); } TheScene.RemoveEntity(this); destination.AddEntity(this); Game.CurrentScene = destination; }
private void Init() { Room startingRoom = new Room(10, 10); Room otherRoom = new Room(10, 10); Enemy enemy = new Enemy('e', "imges/ezgif/tile196.png"); enemy.x = 3; enemy.y = 3; startingRoom.North = otherRoom; CurrentScene = startingRoom; //otherRoom.South = otherRoom; //startingRoom.South = otherRoom; //startingRoom.West = otherRoom; //startingRoom.East = otherRoom; startingRoom.AddEntity(new Wall(0, 0, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(1, 4, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(2, 4, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(3, 2, "imges/ezgif/tile012.png")); //add a border for (int i = 0; i < otherRoom.SizeX; i++) { if (i != 2) { otherRoom.AddEntity(new Wall(i, otherRoom.SizeY, "imges/ezgif/tile012.png")); } } for (int i = 0; i < startingRoom.SizeX; i++) { otherRoom.AddEntity(new Wall(i, startingRoom.SizeY - 1, "imges/ezgif/tile012.png")); } for (int i = 0; i < otherRoom.SizeX; i++) { if (i != 2) { otherRoom.AddEntity(new Wall(i, 0, "imges/ezgif/tile012.png")); } } for (int i = 0; i < otherRoom.SizeY; i++) { if (i != 2) { otherRoom.AddEntity(new Wall(0, i, "imges/ezgif/tile012.png")); } } for (int i = 0; i < otherRoom.SizeY; i++) { if (i != 2) { otherRoom.AddEntity(new Wall(otherRoom.SizeX - 1, i, "imges/ezgif/tile012.png")); } } startingRoom.AddEntity(new Wall(3, 2, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(3, 2, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(3, 2, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(4, 3, "imges/ezgif/tile012.png")); startingRoom.AddEntity(new Wall(5, 3, "imges/ezgif/tile012.png")); player = new Player("imges/ezgif/tile195.png"); otherRoom.AddEntity(enemy); startingRoom.AddEntity(player); player.x = 1; player.y = 1; //player.Sprite.x -= 0.5f; //player.Sprite.y -= 0.5f; // Entity sword = new Entity('/', "imges/ezgif/tile137.png"); }
private void Init() { Room startingRoom = new Room(8, 6); Room otherRoom1 = new Room(12, 6); Room otherRoom2 = new Room(18, 22); Room otherRoom3 = new Room(6, 6); Room otherRoom4 = new Room(4, 18); Enemy enemy = new Enemy("tile191.png"); void OtherRoomStart1() { enemy.X = 4; enemy.Y = 4; } Chests chest = new Chests("tile084.png"); void OtherRoomStart2() { chest.X = 2; chest.Y = 2; } otherRoom1.OnStart += OtherRoomStart1; otherRoom3.OnStart += OtherRoomStart2; startingRoom.North = otherRoom1; startingRoom.South = otherRoom2; startingRoom.East = otherRoom3; startingRoom.West = otherRoom4; //Add Walls to the startingRoom startingRoom.AddEntity(new Wall(2, 2)); //north walls for (int i = 0; i < startingRoom.SizeX; i++) { if (i != 2) { startingRoom.AddEntity(new Wall(i, 0)); } } //south walls for (int i = 0; i < startingRoom.SizeX; i++) { if (i != 6) { startingRoom.AddEntity(new Wall(i, startingRoom.SizeY - 1)); } } //east walls for (int i = 1; i < startingRoom.SizeY - 1; i++) { if (i != 1) { startingRoom.AddEntity(new Wall(startingRoom.SizeX - 1, i)); } } //west walls for (int i = 1; i < startingRoom.SizeY - 1; i++) { if (i != 2) { startingRoom.AddEntity(new Wall(0, i)); } } //ROOM 1 //Add Walls to the otherRoom //north walls for (int i = 0; i < otherRoom1.SizeX; i++) { otherRoom1.AddEntity(new Wall(i, 0)); } //south walls for (int i = 0; i < otherRoom1.SizeX; i++) { if (i != 2) { otherRoom1.AddEntity(new Wall(i, otherRoom1.SizeY - 1)); } } //east walls for (int i = 1; i < otherRoom1.SizeY - 1; i++) { otherRoom1.AddEntity(new Wall(otherRoom1.SizeX - 1, i)); } //west walls for (int i = 1; i < otherRoom1.SizeY - 1; i++) { otherRoom1.AddEntity(new Wall(0, i)); } //ROOM 2 //north walls for (int i = 0; i < otherRoom2.SizeX; i++) { if (i != 6) { otherRoom2.AddEntity(new Wall(i, 0)); } } //south walls for (int i = 0; i < otherRoom2.SizeX; i++) { otherRoom2.AddEntity(new Wall(i, otherRoom2.SizeY - 1)); } //east walls for (int i = 1; i < otherRoom2.SizeY - 1; i++) { otherRoom2.AddEntity(new Wall(otherRoom2.SizeX - 1, i)); } //west walls for (int i = 1; i < otherRoom2.SizeY - 1; i++) { otherRoom2.AddEntity(new Wall(0, i)); } //ROOM 3 //north walls for (int i = 0; i < otherRoom3.SizeX; i++) { otherRoom3.AddEntity(new Wall(i, 0)); } //south walls for (int i = 0; i < otherRoom3.SizeX; i++) { otherRoom3.AddEntity(new Wall(i, otherRoom3.SizeY - 1)); } //east walls for (int i = 1; i < otherRoom3.SizeY - 1; i++) { otherRoom3.AddEntity(new Wall(otherRoom3.SizeX - 1, i)); } //west walls for (int i = 1; i < otherRoom3.SizeY - 1; i++) { if (i != 1) { otherRoom3.AddEntity(new Wall(0, i)); } } //ROOM 4 //north walls for (int i = 0; i < otherRoom4.SizeX; i++) { otherRoom4.AddEntity(new Wall(i, 0)); } //south walls for (int i = 0; i < otherRoom4.SizeX; i++) { otherRoom4.AddEntity(new Wall(i, otherRoom4.SizeY - 1)); } //east walls for (int i = 1; i < otherRoom4.SizeY - 1; i++) { if (i != 2) { otherRoom4.AddEntity(new Wall(otherRoom4.SizeX - 1, i)); } } //west walls for (int i = 1; i < otherRoom4.SizeY - 1; i++) { otherRoom4.AddEntity(new Wall(0, i)); } //Create a Player, position it, and add it to startingRoom Player player = new Player("tile190.png"); player.X = 4; player.Y = 3; startingRoom.AddEntity(player); //Add enemy to otherRoom otherRoom1.AddEntity(enemy); otherRoom3.AddEntity(chest); CurrentScene = startingRoom; }
private void Init() { Room startingRoom = new Room(8, 6); Room otherRoom = new Room(12, 6); Enemy enemy = new Enemy(); void OtherRoomStart() { enemy.X = 4; enemy.Y = 4; } otherRoom.OnStart += OtherRoomStart; startingRoom.North = otherRoom; //Add Walls to the startingRoom startingRoom.AddEntity(new Wall(2, 2)); //north walls for (int i = 0; i < startingRoom.SizeX; i++) { if (i != 2) { startingRoom.AddEntity(new Wall(i, 0)); } } //south walls for (int i = 0; i < startingRoom.SizeX; i++) { startingRoom.AddEntity(new Wall(i, startingRoom.SizeY - 1)); } //east walls for (int i = 1; i < startingRoom.SizeY - 1; i++) { startingRoom.AddEntity(new Wall(startingRoom.SizeX - 1, i)); } //west walls for (int i = 1; i < startingRoom.SizeY - 1; i++) { startingRoom.AddEntity(new Wall(0, i)); } //Add Walls to the otherRoom //north walls for (int i = 0; i < otherRoom.SizeX; i++) { otherRoom.AddEntity(new Wall(i, 0)); } //south walls for (int i = 0; i < otherRoom.SizeX; i++) { if (i != 2) { otherRoom.AddEntity(new Wall(i, otherRoom.SizeY - 1)); } } //east walls for (int i = 1; i < otherRoom.SizeY - 1; i++) { otherRoom.AddEntity(new Wall(otherRoom.SizeX - 1, i)); } //west walls for (int i = 1; i < otherRoom.SizeY - 1; i++) { otherRoom.AddEntity(new Wall(0, i)); } //Create a Player, position it, and add it to startingRoom Player player = new Player("circle_game-1.jpg"); player.X = 4; player.Y = 3; startingRoom.AddEntity(player); //Add enemy to otherRoom otherRoom.AddEntity(enemy); CurrentScene = startingRoom; }