Пример #1
0
        public Game()
        {
            View = new View
            {
                Size = new Vector2f(320, 240),
                Center = new Vector2f(320, 240)
            };
            _player = new Entity(EntityType.Player);
            _frameClock = new Clock();

            Map = new Map("testmap", 40, 30);

            for (var x = 0; x < Map.Size.X; x++)
            {
                for (var y = 0; y < Map.Size.Y; y++)
                {
                    Map.AddTile(TileType.Stonefloor, x, y, 0);
                }
            }

            Map.AmbientLightColor = new Color(70, 70, 70, 255);
            _player.Position = new Vector2f(20 * 32, 15 * 32);
            Map.AddEntity(_player);

            _playerLight = new PointLight(Color.White, 1.0f, 128, _player.Position);

            _mouseLight = new PointLight(Color.Red, 1.0f, 128, (Vector2f) InputHandler.MousePosition);

            Map.AddLight(_mouseLight);
            Map.AddLight(_playerLight);

            Map.AddTile(TileType.StonewallNorth, 22, 18, 1);
            Map.AddTile(TileType.StonewallNorth, 22, 14, 1);
            Map.AddTile(TileType.StonewallNorth, 18, 18, 1);
            Map.AddTile(TileType.StonewallNorth, 18, 14, 1);
            Map.AddTile(TileType.StonewallNorth, 20, 12, 1);
            Map.AddTile(TileType.StonewallNorth, 16, 16, 1);
            Map.AddTile(TileType.StonewallNorth, 20, 20, 1);
            Map.AddTile(TileType.StonewallNorth, 24, 16, 1);
        }
Пример #2
0
        public static Map Load(string filename)
        {
            var br = new BinaryReader(
                File.Open(filename, FileMode.Open));

            var version = br.ReadInt16();

            var name = br.ReadString();

            var size = new Vector2i(br.ReadInt32(), br.ReadInt32());

            var cellSize = br.ReadInt32();

            var entityCount = br.ReadInt32();
            var lightCount = br.ReadInt32();

            var map = new Map(name, size, cellSize);

            for (var i = 0; i < size.X; i++)
            {
                for (var j = 0; j < size.Y; j++)
                {
                    map.Layer0Cells[i, j] = MapCell.Read(br);
                    map.Layer0Cells[i, j].SetPosition(i * cellSize, j * cellSize);

                    map.Layer1Cells[i, j] = MapCell.Read(br);
                    map.Layer1Cells[i, j].SetPosition(i * cellSize, j * cellSize);

                    map.Layer2Cells[i, j] = MapCell.Read(br);
                    map.Layer2Cells[i, j].SetPosition(i * cellSize, j * cellSize);
                }
            }

            for (var i = 0; i < entityCount; i++)
                map.AddEntity(Entity.Read(br));

            map.AmbientLightColor = new Color(br.ReadByte(), br.ReadByte(), br.ReadByte());

            for (var i = 0; i < lightCount; i++)
                map.AddLight(PointLight.Read(br));

            br.Close();

            var sb = new StringBuilder();
            sb.AppendLine("Loaded map " + name);
            sb.AppendLine("\tVersion: " + version);
            sb.AppendLine("\tName: " + name);
            sb.AppendLine("\tSize: (" + size.X + ", " + size.Y + ")");
            sb.AppendLine("\tCell Size: " + cellSize);
            sb.AppendLine("\tEntity Count: " + entityCount);
            sb.AppendLine("\tLight Count: " + lightCount);

            Console.WriteLine(sb);

            return map;
        }