예제 #1
0
파일: Program.cs 프로젝트: leontodd/NATE
        static void Initialize()
        {
            Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Environment.CurrentDirectory + "\\libs");
            dtClock = new Stopwatch();
            textFps = new Text("0", new Font(new FileStream("assets\\fonts\\arial.ttf", FileMode.Open, FileAccess.Read)));
            window = new RenderWindow(new VideoMode(1280, 768), "Test", Styles.Default);
            window.SetFramerateLimit(60);
            window.SetTitle("NATE");
            tiles = new TileManager("assets\\tilemaps\\rpgtiles.png", 32);
            iMap = new MapInterface();
            //map = new Map(new Vector2i(32, 32), ((int)tiles.image.Size.X / tiles.tileSize) * ((int)tiles.image.Size.Y / tiles.tileSize), true); -- for random
            //map = new Map(new Vector2i(32, 32), ((int)tiles.image.Size.X / tiles.tileSize) * ((int)tiles.image.Size.Y / tiles.tileSize), false); -- blank
            map = iMap.ReadMap("map1.ntm");
            
            scaling = new Vector2f(2, 2);
            textureCollection = new Texture[(tiles.image.Size.X / tiles.tileSize) * (tiles.image.Size.Y / tiles.tileSize)];
            camera = new Camera();
            camera.speed = 1000;

            window.Closed += (s, a) => window.Close();
            window.KeyPressed += (s, a) => { if (a.Code == Keyboard.Key.Z) { iMap.WriteMap("map0.ntm", map); } };
            window.MouseWheelMoved += (s, a) => { scaling.X += a.Delta * 0.075f; scaling.Y += a.Delta * 0.075f; };

            dtClock.Start();

            for (int i = 0; i < (tiles.image.Size.X / tiles.tileSize) * (tiles.image.Size.Y / tiles.tileSize); i++)
            {
                textureCollection[i] = tiles.GetTile(i);
                textureCollection[i].Smooth = false;
            }
        }
예제 #2
0
파일: Map.cs 프로젝트: leontodd/NATE
 public Map ReadMap(string path)
 {
     
     StreamReader s = File.OpenText(path);
     dynamic o = JsonConvert.DeserializeObject(s.ReadToEnd());
     JArray j = o["layers"][0]["data"];
     int[] d1 = j.Select(jv => (int)jv).ToArray();
     Map m = new Map(new Vector2i((int)o["width"], (int)o["height"]));
     m.tileCount = (int)o["properties"]["tileCount"];
     for (int x = 0; x < m.size.X; x++)
     {
         for (int y = 0; y < m.size.Y; y++)
         {
             m.data[x, y] = d1[y * m.size.X + x] - 1;
         }
     }
     return m;
 }
예제 #3
0
파일: Map.cs 프로젝트: leontodd/NATE
 public void WriteMap(string path, Map map)
 {
     Stream s = File.Open(path, FileMode.Create);
     BinaryFormatter b = new BinaryFormatter();
     b.Serialize(s, map);
 }