protected override void OnShow(Node node, Asset asset) { TileMap2D tileMap = node.CreateComponent <TileMap2D>(); TmxFile2D tmxFile = ResourceCache.GetTmxFile2D(asset.RelativePathToAsset); tileMap.TmxFile = tmxFile; }
private Vector3 GetPositionOffset(TileMap2D tileMap) { Vector2 mapHalfSize = (Vector2)tileMap.MapSize * 0.5f; Vector2 tileHalfSize = tileMap.TileSize * 0.5f; return(new Vector3((mapHalfSize.x * tileMap.TileSize.x) - tileHalfSize.x, (-mapHalfSize.y * tileMap.TileSize.y) + tileHalfSize.y)); }
static void Main(string[] args) { Console.SetBufferSize(500, 2000); Console.SetWindowSize(155, 50); Msg.DebugVerbosity = LogVerbosity.LOW; Msg.DebugAction = (_group, _msg) => Debug.WriteLine(_group + " : " + _msg); Generate.Settings.ActionForUserMessages = Console.WriteLine; Generate.SetDefaultMaterials(1, 2); //Generate.Settings.RndSeed = -1708127739; Generate.Settings.AspectRatio = 1f; Generate.Settings.RoomBufferMin = 1; Generate.Settings.RoomBufferMax = 3; Generate.Settings.TunnelBuffer = 3; Generate.Settings.TunnelPathMag = 3; Generate.Settings.TunnelRoutingStrength = Generate.Settings.MagStrength.Minimum; Generate.Settings.ClosestConnect = false; Generate.Settings.TunnelTurningCost = Generate.Settings.TTCost.Normal; Generate.Settings.RoomCountMin = 50; Generate.Settings.RoomCountMax = 60; Generate.Settings.RoomSizeMin = 6; Generate.Settings.RoomSizeMax = 20; Generate.Settings.RoomSpread = Generate.Settings.RSType.Tight; Console.WriteLine(Generate.DebugSettingsToString()); //System.Console.ReadLine(); Generate.Dungeon(); while (!Generate.GenerateDone) { } TileMap2D map = Generate.GetGeneratedMap(); Console.WriteLine(map.DebugToString()); //System.Console.ReadLine(); Console.WriteLine("Closing..."); Console.ReadLine(); }
void CreateScene() { scene = new Scene(); scene.CreateComponent <Octree>(); // Create camera node CameraNode = scene.CreateChild("Camera"); // Set camera's position CameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); Camera camera = CameraNode.CreateComponent <Camera>(); camera.Orthographic = true; var graphics = Graphics; camera.OrthoSize = (float)graphics.Height * PixelSize; camera.Zoom = (1.0f * Math.Min((float)graphics.Width / 1280.0f, (float)graphics.Height / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution) var cache = ResourceCache; // Get tmx file TmxFile2D tmxFile = cache.GetTmxFile2D("Urho2D/isometric_grass_and_water.tmx"); if (tmxFile == null) { return; } Node tileMapNode = scene.CreateChild("TileMap"); tileMapNode.Position = new Vector3(0.0f, 0.0f, -1.0f); TileMap2D tileMap = tileMapNode.CreateComponent <TileMap2D>(); // Set animation tileMap.TmxFile = tmxFile; // Set camera's position TileMapInfo2D info = tileMap.Info; float x = info.MapWidth * 0.5f; float y = info.MapHeight * 0.5f; CameraNode.Position = new Vector3(x, y, -10.0f); }
public Level(ContentManager content) { SetSize(Game1._screenW, Game1._screenH); _tmxMap = new TmxMap("Content/test_slope2D.tmx"); _tileSet = content.Load <Texture2D>("Image/" + "TileSet_Slope2D"); //_tileMap2DX = new TileMap2D().Setup(new Rectangle(0, 0, Game1._screenW, Game1._screenH), _tmxMap.Width, _tmxMap.Height, _tmxMap.TileWidth, _tmxMap.TileHeight, 0, 0); //_layerX = _tileMap2DX.CreateLayer(null); _tileMap2D = new TileMap2D().Setup(new Rectangle(0, 0, Game1._screenW, Game1._screenH), _tmxMap.Width, _tmxMap.Height, _tmxMap.TileWidth, _tmxMap.TileHeight); _arenaSizeW = _tmxMap.Width * _tmxMap.TileWidth; _arenaSizeH = _tmxMap.Height * _tmxMap.TileHeight; _layer0 = TileMap2D.CreateLayer(_tmxMap, _tmxMap.Layers["Tile Layer 1"], _tileSet); System.Console.WriteLine("Layer0._map2D = " + _layer0._map2D); //System.Console.WriteLine("------> "+_tmxMap.Tilesets[0].Tiles[2].ObjectGroups[0].Objects[0].Points); // debug //GenerateMap(); _camera = new Camera(); _camera.SetView(new RectangleF(0, 0, Game1._screenW, Game1._screenH)); _camera.SetZone(new RectangleF(0, 0, Game1._screenW / 20, Game1._screenH / 40)); //_camera.SetLimit(new RectangleF(0, 0, _arenaSizeW, _arenaSizeH)); _camera.SetLimit(new RectangleF(0, 0, _arenaSizeW, _arenaSizeH)); _camera.SetPosition(new Vector2(_arenaSizeW / 2 + _layer0._map2D._tileW / 2, _arenaSizeH / 2 + _layer0._map2D._tileH * 2)); //for (int i = 0; i < 400; ++i) //{ // new Enemy0(_layer0).SetPosition(Misc.Rng.Next(80, (int)_arenaSizeW - 80), 80).AppendTo(this); //} _hero = (Hero) new Hero(Game1.Player1, _layer0, _mouseLevel).Init().AppendTo(this).SetPosition(80, 80); //_hero2 = (Hero)new Hero(Game1.Player2, _layer0._map2D).Init().AppendTo(this); }
void CreateScene() { scene = new Scene(); scene.CreateComponent <Octree>(); // Create camera node CameraNode = scene.CreateChild("Camera"); // Set camera's position CameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); Camera camera = CameraNode.CreateComponent <Camera>(); camera.Orthographic = true; var graphics = Graphics; camera.OrthoSize = (float)graphics.Height * PixelSize; // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution) camera.Zoom = (1.0f * Math.Min((float)graphics.Width / 1280.0f, (float)graphics.Height / 800.0f)); var cache = ResourceCache; // Get tmx file TmxFile2D tmxFile = cache.GetTmxFile2D("data/isometric_grass_and_water.tmx"); if (tmxFile == null) { return; } /*var n = tmxFile.NumLayers; * for (uint i=0; i<n; i++) * { * TmxLayer2D layer = tmxFile.GetLayer(i); * layer. * }*/ Node tileMapNode = scene.CreateChild("TileMap"); tileMapNode.Position = new Vector3(0.0f, 0.0f, -1.0f); TileMap2D tileMap = tileMapNode.CreateComponent <TileMap2D>(); // Set animation tileMap.TmxFile = tmxFile; var n = tileMap.NumLayers; var layer = tileMap.GetLayer(0); var node = tileMap.Node; var name = node.Name; while (node.GetNumChildren() == 1) { node = node.Children[0]; name = node.Name; } var n0 = node.GetNumChildren(); int ii = 0; var result = from Node xx in node.Children /*where (ii++ > n / 3) && (ii < n * 2 / 3)*/ select xx; foreach (var nn in result) { nn.Remove(); } var nx = result.Count(); var n1 = node.GetNumChildren(); //node.GetChild() // Set camera's position TileMapInfo2D info = tileMap.Info; float x = info.MapWidth * 0.5f; float y = info.MapHeight * 0.5f; CameraNode.Position = new Vector3(x, y, -10.0f); // Create a Zone component for ambient lighting & fog control var zoneNode = scene.CreateChild("Zone"); var zone = zoneNode.CreateComponent <Zone>(); zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color(0.15f, 0.15f, 0.15f); zone.FogColor = new Color(0.5f, 0.5f, 0.7f); zone.FogStart = 100.0f; zone.FogEnd = 300.0f; // Create a directional light to the world. Enable cascaded shadows on it var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); var light = lightNode.CreateComponent <Light>(); light.LightType = LightType.Directional; light.CastShadows = true; light.ShadowBias = new BiasParameters(0.00025f, 0.5f); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); // Create some mushrooms const uint numMushrooms = 240; for (uint i = 0; i < numMushrooms; ++i) { var mushroomNode = scene.CreateChild("Mushroom"); mushroomNode.Position = new Vector3(NextRandom(90.0f) - 45.0f, 0.0f, NextRandom(90.0f) - 45.0f); mushroomNode.Rotation = new Quaternion(0.0f, NextRandom(360.0f), 0.0f); mushroomNode.SetScale(0.5f + NextRandom(2.0f)); StaticModel mushroomObject = mushroomNode.CreateComponent <StaticModel>(); mushroomObject.Model = cache.GetModel("data/Mushroom.mdl"); mushroomObject.SetMaterial(cache.GetMaterial("data/Mushroom.xml")); mushroomObject.CastShadows = true; } { mobileMushroom = scene.CreateChild("Mushroom"); mobileMushroom.Position = new Vector3(20.0f, 10.0f, -10.0f); mobileMushroom.Rotation = new Quaternion(0.0f, NextRandom(360.0f), 0.0f); mobileMushroom.SetScale(0.5f + NextRandom(2.0f)); StaticModel mushroomObject = mobileMushroom.CreateComponent <StaticModel>(); mushroomObject.Model = cache.GetModel("data/Mushroom.mdl"); mushroomObject.SetMaterial(cache.GetMaterial("data/Mushroom.xml")); mushroomObject.CastShadows = true; } }
// Load the map private void CreateMap() { // Load map TmxFile2D mapFile = ResourceCache.GetTmxFile2D("test/map_1.tmx"); if (mapFile == null) { throw new Exception("Map not found"); } Node mapNode = scene.CreateChild("TileMap"); mapNode.Position = new Vector3(0f, 0f, 10f); mapNode.SetScale(1f / 0.7f); tileMap = mapNode.CreateComponent <TileMap2D>(); tileMap.TmxFile = mapFile; // Load pickup sprites var weaponSprite = ResourceCache.GetSprite2D("map/levels/platformer-art-complete-pack-0/Request pack/Tiles/raygunBig.png"); var armorSprite = ResourceCache.GetSprite2D("map/levels/platformer-art-complete-pack-0/Request pack/Tiles/shieldGold.png"); if (weaponSprite == null || armorSprite == null) { throw new Exception("Texture not found"); } // Initialize map Random r = new Random(); for (uint layerID = 0; layerID < tileMap.NumLayers; ++layerID) { TileMapLayer2D layer = tileMap.GetLayer(layerID); for (int x = 0; x < layer.Width; ++x) { for (int y = 0; y < layer.Height; ++y) { Node n = layer.GetTileNode(x, y); if (n == null) { continue; } Vector2 pos = tileMap.TileIndexToPosition(x, y); pos /= 0.7f; pos += new Vector2(0.5f, 0.5f); // Solid Block if (layer.GetProperty("Solid") == "True") { MapTile tile = new MapTile(pos); Tiles.Add(tile); collisionObjects.Add(tile); continue; } // Spawner switch (layer.GetProperty("Spawn")) { case "Player": playerSpawns.Add(pos); break; case "Enemy": enemySpawns.Add(pos); break; case "Weapon": if (r.NextDouble() < weaponSpawnRate) { Pickups.Add(new PickupWeaponUpgrade(scene, weaponSprite, pos)); } break; case "Armor": if (r.NextDouble() < armorSpawnRate) { Pickups.Add(new PickupArmor(scene, armorSprite, pos)); } break; default: continue; } // Skipped if not a spawner n.Remove(); } } } }