Ejemplo n.º 1
0
        public static MapTile[,] readTileMap(String inputFile, PlayableMainGameScreen owner)
        {
            StreamReader reader = new StreamReader(inputFile);
            int width = Int32.Parse(reader.ReadLine());
            int height = Int32.Parse(reader.ReadLine());
            MapTile[,] mapArr = new MapTile[height,width];
            char[,] tileArr = new char[height,width];
            String temp = reader.ReadLine();
            String[] tempArr;
            int i = 0;
            int j = 0;
            while (temp != null && i < height)
            {
                tempArr = temp.Split(' ');
                for (j = 0; j < width; j++)
                {
                    char[] tempChar = tempArr[j].ToCharArray();
                    tileArr[i,j] = tempChar[0];
                }
                i++;
                temp = reader.ReadLine();
            }

            mapTiles(tileArr, mapArr, width, height, owner);

            return mapArr;
        }
Ejemplo n.º 2
0
        /**
         * This method should be called by the constructor for PlayableGameScreen ONLY.
         * All other game entities that require a text parser have their own (ie, TileMapParser).
         * So, first line of the method should be to create the Screen, then add stuff
         * as the script file declares it.
         *
         * */
        public static void LoadScriptFile(String filename, PlayableMainGameScreen PGS)
        {
            StreamReader reader = new StreamReader(filename);
            String line = reader.ReadLine();

            // Regex patterns
            String playerPattern = "^player:.*";
            String NPentityPattern = "^NPentity:.*";
            String friend = "^friend:.*";
            String enemy = "^enemy:.*";
            String tilePattern = "^tilemap:.*";
            String transferPattern = "^transferPoint:.*";
            String songsPattern = "^songs:.*";
            while (line != null)
            {
                // use System.Text.RegularExpressions.Regex.IsMatch(String s, String pattern)
                if (System.Text.RegularExpressions.Regex.IsMatch(line, playerPattern))
                    LoadPlayer(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, NPentityPattern))
                    LoadNPEntity(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, friend))
                    LoadFriend(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, enemy))
                    LoadEnemy(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, tilePattern))
                    LoadTileMap(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, transferPattern))
                    LoadTransferPoints(line, PGS);
                else if (System.Text.RegularExpressions.Regex.IsMatch(line, songsPattern))
                    LoadSongs(line, PGS);
                line = reader.ReadLine();
            }
        }
Ejemplo n.º 3
0
 public MapTile(String textureKey, Vector2 pos, MapTileCollisionType collision, PlayableMainGameScreen owner)
 {
     this.textureKey = textureKey;
     position = pos;
     this.collision = collision;
     this.owner = owner;
     this.drawbox = new Rectangle((int)pos.X, (int)pos.Y, GetWidth, GetHeight);
     CreateBoundary();
 }
Ejemplo n.º 4
0
 private static void LoadNPEntity(String entity, PlayableMainGameScreen PGS)
 {
     char[] delims = { '<', '>' };
     String[] tokens = entity.Substring(8).Split(delims);
     String texture = tokens[1];
     float posX = float.Parse(tokens[3]);
     float posY = float.Parse(tokens[5]);
     NonPlayerEntity npEntity = new NonPlayerEntity(texture, new Vector2(posX, posY));
     PGS.AddEntity(npEntity);
 }
Ejemplo n.º 5
0
 private static void LoadFriend(String entity, PlayableMainGameScreen PGS)
 {
     char[] delims = { '<', '>' };
     String[] tokens = entity.Substring(8).Split(delims);
     String texture = tokens[1];
     float posX = float.Parse(tokens[3]);
     float posY = float.Parse(tokens[5]);
     String text = tokens[7];
     String filename = tokens[9];
     FriendlyEntity npEntity = new FriendlyEntity(texture, new Vector2(posX, posY), text, filename);
     PGS.AddEntity(npEntity);
 }
Ejemplo n.º 6
0
        private static void mapTiles(char[,] strArr, MapTile[,] mapArr, int width, int height, PlayableMainGameScreen owner)
        {
            char tempChar;
            MapTile tempTile;
            String fileIndex;
            MapTileCollisionType collision;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    tempChar = strArr[i, j];
                    switch (tempChar)
                    {
                        case '1':
                            fileIndex = "Tile";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '2':
                            fileIndex = "Wood";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '3':
                            fileIndex = "Top";
                            collision = MapTileCollisionType.HalfCollisionTop;
                            break;
                        case '4':
                            fileIndex = "Bottom";
                            collision = MapTileCollisionType.HalfCollisionBot;
                            break;
                        case '5':
                            fileIndex = "Left";
                            collision = MapTileCollisionType.HalfCollisionLeft;
                            break;
                        case '6':
                            fileIndex = "Right";
                            collision = MapTileCollisionType.HalfCollisionRight;
                            break;
                        default:
                            fileIndex = "Empty";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                    }
                    tempTile = new MapTile(fileIndex, new Microsoft.Xna.Framework.Vector2(j * 20, i * 20), collision, owner);
                    mapArr[i, j] = tempTile;
                }
            }
        }
Ejemplo n.º 7
0
 private static void LoadPlayer(String player, PlayableMainGameScreen PGS)
 {
     char[] delims = {'<','>'};
     String[] tokens = player.Substring(8).Split(delims);
     String texture = tokens[1];
     PlayerEntity pEntity;
     Vector2 playerPos = PGS.PlayerPos;
     pEntity = new PlayerEntity(texture, playerPos);
     PGS.AddEntity(pEntity);
 }
Ejemplo n.º 8
0
 private static void LoadTransferPoints(String transfer, PlayableMainGameScreen PGS)
 {
     char[] delims = { '<', '>' };
     String[] tokens = transfer.Substring(15).Split(delims);
     String nextScreen = tokens[1];
     int xCoord = Int16.Parse(tokens[3]);
     int yCoord = Int16.Parse(tokens[5]);
     int nextX = Int16.Parse(tokens[7]);
     int nextY = Int16.Parse(tokens[9]);
     PGS.setTransferPoint(nextScreen, xCoord, yCoord, nextX, nextY);
 }
Ejemplo n.º 9
0
 private static void LoadTileMap(String tileMap, PlayableMainGameScreen PGS)
 {
     char[] delims = { '<', '>' };
     String[] tokens = tileMap.Substring(9).Split(delims);
     String mapTextureName = tokens[1];
     PGS.setTileMap(MapReader.readTileMap(mapTextureName, PGS));
 }
Ejemplo n.º 10
0
 private static void LoadSongs(String songs, PlayableMainGameScreen PGS)
 {
     char[] delims = { '<', '>' };
     String[] tokens = songs.Substring(8).Split(delims);
     // First song will always be the default song to play.
     PGS.currentSong = tokens[1];
     PGS.Songs.Add(tokens[1]);
     PGS.Songs.Add(tokens[3]);
 }
Ejemplo n.º 11
0
        private static void mapTiles(char[,] strArr, MapTile[,] mapArr, int width, int height, PlayableMainGameScreen owner)
        {
            char tempChar;
            MapTile tempTile;
            String fileIndex;
            MapTileCollisionType collision;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    tempChar = strArr[i, j];
                    switch (tempChar)
                    {
                        case '1':
                            fileIndex = "Tile";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '2':
                            fileIndex = "Wood";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '3':
                            fileIndex = "70s";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '4':
                            fileIndex = "Asphalt";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '5':
                            fileIndex = "Cement";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '6':
                            fileIndex = "Cobble";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '7':
                            fileIndex = "Grass";
                            collision = MapTileCollisionType.NoCollision;
                            break;
                        case '8':
                            fileIndex = "Wall";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                        case '9':
                            fileIndex = "Window";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                        case 'A':
                            fileIndex = "Cabinet";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                        case 'B':
                            fileIndex = "TopCabinet";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                        default:
                            fileIndex = "Empty";
                            collision = MapTileCollisionType.FullCollision;
                            break;
                    }
                    tempTile = new MapTile(fileIndex, new Microsoft.Xna.Framework.Vector2(j * 20, i * 20), collision, owner);
                    mapArr[i, j] = tempTile;
                }
            }
        }
Ejemplo n.º 12
0
 private static void LoadPlayer(String player, PlayableMainGameScreen PGS)
 {
     char[] delims = {'<','>'};
     String[] tokens = player.Substring(8).Split(delims);
     String texture = tokens[1];
     float posX = float.Parse(tokens[3]);
     float posY = float.Parse(tokens[5]);
     PlayerEntity pEntity;
     Vector2 playerPos;
     if (PGS.PlayerPos.Equals(new Vector2(-1, -1)))
     {
         playerPos = new Vector2(posX, posY);
     }
     else
     {
         playerPos = PGS.PlayerPos;
     }
     pEntity = new PlayerEntity(texture, playerPos);
     PGS.AddEntity(pEntity);
 }