예제 #1
0
        private void LoadMap(string mapname)
        {
            string filePath;
            StreamReader sr;

            //choose which map is loaded
            switch (mapname)
            {
                case "tutorial":
                    filePath = @"Content/maps/Tutorial Map.csv";
                    viewCorner[0] = 1;
                    viewCorner[1] = 10;
                    break;
                default:
                    filePath = @"Content/maps/Tutorial Map.csv";
                    viewCorner[0] = 0;
                    viewCorner[1] = 10;
                    break;
            }

            //read the file in
            sr = new StreamReader(filePath);
            var lines = new List<int[]>();
            while (!sr.EndOfStream)
            {
                string[] line  = sr.ReadLine().Split(',');
                int[] intLine = new int[line.GetLength(0)];
                for (int i = 0; i < line.GetLength(0); i++)
                {
                    intLine[i] = int.Parse(line[i]);
                }
                lines.Add(intLine);
            }

            tileMatrix = lines.ToArray();
            sr.Close();

            //load in objects
            switch (mapname)
            {
                case "tutorial":
                    objectGrid = new ObjectGrid(tileMatrix[0].GetLength(0), tileMatrix.GetLength(0), SCREEN_WIDTH, SCREEN_HEIGHT);

                    Door entrance = new Door(keycardDoorSpriteMap, 10, 16);
                    entrance.setSpriteFrame(new Point(3,0));
                    entrance.canCollide = true;
                    objectGrid.AddObject(entrance);

                    NPC aliceNpc = new NPC(generalSecuritySpriteMap, "Alice");
                    aliceNpc.setCoords(13, 18);
                    aliceNpc.setSpriteFrame(new Point(0,10));
                    objectGrid.AddObject(aliceNpc);

                    NPC bobNpc = new NPC(generalSecuritySpriteMap, "Bob");
                    bobNpc.setCoords(16, 21);
                    bobNpc.setSpriteFrame(new Point(0, 10));
                    objectGrid.AddObject(bobNpc);

                    NPC yellowSecurity = new NPC(generalSecuritySpriteMap, "YellowMan");
                    yellowSecurity.setCoords(28, 16);
                    yellowSecurity.setSpriteFrame(new Point(0,9));
                    objectGrid.AddObject(yellowSecurity);
                    break;
                default:
                    objectGrid = new ObjectGrid(tileMatrix[0].GetLength(0), tileMatrix.GetLength(0), SCREEN_WIDTH, SCREEN_HEIGHT);
                    objectGrid.AddObject(new Door(bathroomDoorSpriteMap, 10, 16));
                    break;
            }
        }
예제 #2
0
        private void LoadMap(string mapname)
        {
            string       filePath;
            StreamReader sr;

            //choose which map is loaded
            switch (mapname)
            {
            case "tutorial":
                filePath      = @"Content/maps/Tutorial Map.csv";
                viewCorner[0] = 1;
                viewCorner[1] = 10;
                break;

            default:
                filePath      = @"Content/maps/Tutorial Map.csv";
                viewCorner[0] = 0;
                viewCorner[1] = 10;
                break;
            }

            //read the file in
            sr = new StreamReader(filePath);
            var lines = new List <int[]>();

            while (!sr.EndOfStream)
            {
                string[] line    = sr.ReadLine().Split(',');
                int[]    intLine = new int[line.GetLength(0)];
                for (int i = 0; i < line.GetLength(0); i++)
                {
                    intLine[i] = int.Parse(line[i]);
                }
                lines.Add(intLine);
            }

            tileMatrix = lines.ToArray();
            sr.Close();

            //load in objects
            switch (mapname)
            {
            case "tutorial":
                objectGrid = new ObjectGrid(tileMatrix[0].GetLength(0), tileMatrix.GetLength(0), SCREEN_WIDTH, SCREEN_HEIGHT);

                Door entrance = new Door(keycardDoorSpriteMap, 10, 16);
                entrance.setSpriteFrame(new Point(3, 0));
                entrance.canCollide = true;
                objectGrid.AddObject(entrance);

                NPC aliceNpc = new NPC(generalSecuritySpriteMap, "Alice");
                aliceNpc.setCoords(13, 18);
                aliceNpc.setSpriteFrame(new Point(0, 10));
                objectGrid.AddObject(aliceNpc);

                NPC bobNpc = new NPC(generalSecuritySpriteMap, "Bob");
                bobNpc.setCoords(16, 21);
                bobNpc.setSpriteFrame(new Point(0, 10));
                objectGrid.AddObject(bobNpc);

                NPC yellowSecurity = new NPC(generalSecuritySpriteMap, "YellowMan");
                yellowSecurity.setCoords(28, 16);
                yellowSecurity.setSpriteFrame(new Point(0, 9));
                objectGrid.AddObject(yellowSecurity);
                break;

            default:
                objectGrid = new ObjectGrid(tileMatrix[0].GetLength(0), tileMatrix.GetLength(0), SCREEN_WIDTH, SCREEN_HEIGHT);
                objectGrid.AddObject(new Door(bathroomDoorSpriteMap, 10, 16));
                break;
            }
        }