public static bool isWalkable(FTilemap map, float xPos, float yPos) { int tileFrame = map.getFrameNumAt(xPos, yPos); int[] wallFrames = new int[] { 1, -1 }; return(!wallFrames.Contains(tileFrame)); }
virtual protected FNode createTilemap(XMLNode node) { XMLNode csvData = new XMLNode(); XMLNode properties = new XMLNode(); foreach (XMLNode child in node.children) { if (child.tagName == "data") { csvData = child; } else if (child.tagName == "properties") { properties = child; } } // make sure encoding is set to csv if (csvData.attributes["encoding"] != "csv") { Debug.Log("FTiledScene: Could not render layer data, encoding set to: " + csvData.attributes["encoding"]); return(null); } // remember name _layerNames.Add(node.attributes["name"]); // skipZero, if this is true all filled tiles will be drawn without clipping bool skipZero = false; // do stuff with properties foreach (XMLNode property in properties.children) { // check each property if (property.attributes["name"] == "skipZero") { skipZero = bool.Parse(property.attributes["value"]); } } // get text for csv data string csvText = csvData.value; string firstFrame = csvText.Substring(0, csvText.IndexOf(',')); int firstID = RemoveFrameFlags(uint.Parse(firstFrame)); // find name of tileset being used, assumes all tiles are from the same tileset string baseName = this.getTilesetNameForID(firstID); // create tilemap FTilemap tilemap = new FTilemap(baseName); if (!skipZero) { tilemap.clipToScreen = true; tilemap.clipNode = _clipNode; } tilemap.LoadText(csvText, skipZero); return(tilemap); }
// Use this for initialization void Start() { FutileParams fparams = new FutileParams(true, true, false, false); fparams.AddResolutionLevel(480.0f, 2.0f, 1.0f, ""); fparams.origin = new Vector2(0.5f, 0.5f); fparams.backgroundColor = new Color(0.15f, 0.15f, 0.3f); Futile.instance.Init(fparams); // load image atlas (within Resources/Atlases folder) Futile.atlasManager.LoadAtlas("Atlases/Burglar"); // Add tilemap FTilemap room1 = new FTilemap("Burglar Walls"); room1.LoadCSV("CSVs/Room1Map"); // load comma separated text file (within Resources/CSVs folder) room1.x = -room1.width / 2; room1.y -= 4; Futile.stage.AddChild(room1); // create burglar burglar = new FAnimatedSprite("Burglar"); burglar.y = -24; int[] frames = { 1, 1, 2, 1, 1, 1, 10, 1, 11, 1 }; // idle anim burglar.addAnimation(new FAnimation("idle", frames, 400, true)); int[] frames2 = { 3, 4, 5, 6, 4, 7 }; // run anim burglar.addAnimation(new FAnimation("run", frames2, 180, true)); Futile.stage.AddChild(burglar); // add burglar to stage // load font atlas Futile.atlasManager.LoadAtlas("Atlases/Fonts"); // Add large font text Futile.atlasManager.LoadFont("Large", "Large Font", "Atlases/Large Font", 0, 0); FLabel label1 = new FLabel("Large", "LARGE FONT"); label1.y = 26; Futile.stage.AddChild(label1); // Add small font text Futile.atlasManager.LoadFont("Small", "Small Font", "Atlases/Small Font", 0, 0); FLabel label2 = new FLabel("Small", "Small Font"); label2.y = 12; Futile.stage.AddChild(label2); // Add tiny font text Futile.atlasManager.LoadFont("Tiny", "Tiny Font", "Atlases/Tiny Font", 0, 0); FLabel label3 = new FLabel("Tiny", "Tiny Font"); label3.y = 3; Futile.stage.AddChild(label3); }
// Use this for initialization void Start() { FutileParams fparams = new FutileParams(true, true, false, false); fparams.AddResolutionLevel(480.0f, 2.0f, 1.0f, ""); fparams.origin = new Vector2(0.5f, 0.5f); fparams.backgroundColor = new Color(0.15f, 0.15f, 0.3f); Futile.instance.Init(fparams); // load image atlas (within Resources/Atlases folder) Futile.atlasManager.LoadAtlas("Atlases/Burglar"); // Add tilemap FTilemap room1 = new FTilemap("Burglar Walls"); room1.LoadCSV("CSVs/Room1Map"); // load comma separated text file (within Resources/CSVs folder) room1.x = -room1.width/2; room1.y -= 4; Futile.stage.AddChild(room1); // create burglar burglar = new FAnimatedSprite("Burglar"); burglar.y = -24; int[] frames = { 1,1,2,1,1,1,10,1,11,1 }; // idle anim burglar.addAnimation(new FAnimation("idle", frames, 400, true)); int[] frames2 = { 3,4,5,6,4,7 }; // run anim burglar.addAnimation(new FAnimation("run", frames2, 180, true)); Futile.stage.AddChild(burglar); // add burglar to stage // load font atlas Futile.atlasManager.LoadAtlas("Atlases/Fonts"); // Add large font text Futile.atlasManager.LoadFont("Large", "Large Font", "Atlases/Large Font"); FLabel label1 = new FLabel("Large", "LARGE FONT"); label1.y = 26; Futile.stage.AddChild(label1); // Add small font text Futile.atlasManager.LoadFont("Small", "Small Font", "Atlases/Small Font"); FLabel label2 = new FLabel("Small", "Small Font"); label2.y = 12; Futile.stage.AddChild(label2); // Add tiny font text Futile.atlasManager.LoadFont("Tiny", "Tiny Font", "Atlases/Tiny Font"); FLabel label3 = new FLabel("Tiny", "Tiny Font"); label3.y = 3; Futile.stage.AddChild(label3); }
public void LoadTMX(string fileName) { // load xml document TextAsset dataAsset = (TextAsset)Resources.Load(fileName, typeof(TextAsset)); if (!dataAsset) { Debug.Log("FTiledScene: Couldn't load the xml data from: " + fileName); } string fileContents = dataAsset.ToString(); Resources.UnloadAsset(dataAsset); // parse xml string XMLReader parser = new XMLReader(); XMLNode xmlNode = parser.read(fileContents); XMLNode rootNode = xmlNode.children[0] as XMLNode; // loop through all children foreach (XMLNode child in rootNode.children) { // save references to tilesets if (child.tagName == "tileset") { _tilesets.Add(child); } // create FTilemap for layer nodes if (child.tagName == "layer" && child.children.Count > 0) { FTilemap newTilemapLayer = this.createTilemap(child); AddChild(newTilemapLayer); tilemaps.Add(newTilemapLayer); } // create FContainers for layer nodes if (child.tagName == "objectgroup") { AddChild(this.createObjectLayer(child)); } } }
protected virtual FNode createTilemap(XMLNode node) { XMLNode csvData = new XMLNode(); XMLNode properties = new XMLNode(); foreach (XMLNode child in node.children) { if (child.tagName == "data") { csvData = child; } else if (child.tagName == "properties") { properties = child; } } // make sure encoding is set to csv if (csvData.attributes["encoding"] != "csv") { Debug.Log ("FTiledScene: Could not render layer data, encoding set to: " + csvData.attributes["encoding"]); return null; } // remember name _layerNames.Add (node.attributes["name"]); // skipZero, if this is true all filled tiles will be drawn without clipping bool skipZero = false; // do stuff with properties foreach (XMLNode property in properties.children) { // check each property if (property.attributes["name"] == "skipZero") { skipZero = bool.Parse(property.attributes["value"]); } } // get text for csv data string csvText = csvData.value; string firstFrame = csvText.Substring( 0, csvText.IndexOf(',') ); int firstID = RemoveFrameFlags(uint.Parse(firstFrame)); // find name of tileset being used, assumes all tiles are from the same tileset string baseName = this.getTilesetNameForID(firstID); // create tilemap FTilemap tilemap = new FTilemap(baseName); if (!skipZero) { tilemap.clipToScreen = true; tilemap.clipNode = _clipNode; } tilemap.LoadText(csvText, skipZero); return tilemap; }
public void LoadMap(string mapName) { GetEnemyCounts(); map = new FTmxMap(); objects.Clear(); spawnPoints.Clear(); enemySpawns.Clear(); backgroundLayer.RemoveAllChildren(); foregroundLayer.RemoveAllChildren(); playerLayer.RemoveAllChildren(); map.LoadTMX("Maps/" + mapName); backgroundTilemap = (FTilemap)map.getLayerNamed("background"); collisionTilemap = (FTilemap)map.getLayerNamed("collision"); foregroundTilemap = (FTilemap)map.getLayerNamed("foreground"); backgroundTilemap.clipNode = C.getCameraInstance(); collisionTilemap.clipNode = C.getCameraInstance(); foregroundTilemap.clipNode = C.getCameraInstance(); if (p == null) { p = new Player(this); ui = new UI(this); C.getCameraInstance().AddChild(ui); } backgroundLayer.AddChild(backgroundTilemap); backgroundLayer.AddChild(collisionTilemap); foregroundLayer.AddChild(foregroundTilemap); playerLayer.AddChild(p); MapLoader.loadObjects(this, map.objects); SpawnPlayer(p); }
internal void loadMap(string mapName) { this.clearMap(); this.LoadTMX("Maps/" + mapName); tilemap = (FTilemap)(getLayerNamed("Tilemap")); for (int x = 0; x < 3; x++) { otherTilemaps[x] = new FTilemap(tilemap.BaseElementName + "_" + (x + 1), 1); otherTilemaps[x].LoadText(tilemap.dataString, false); } tilemapCollision = (FTilemap)(getLayerNamed("Meta")); objectGroup = (FContainer)(getLayerNamed("Objects")); foreach (XMLNode xml in this.objects) { switch (xml.attributes["type"]) { case "Spawn": FNode spawnPoint = new FNode(); spawnPoint.SetPosition(int.Parse(xml.attributes["x"]) + 8, -int.Parse(xml.attributes["y"]) + 8); spawnPoints.Add(spawnPoint); player.SetPosition(spawnPoint.GetPosition()); break; case "Warp": int warpX = 0; int warpY = 0; XMLNode propertiesNode = (XMLNode)xml.children[0]; foreach (XMLNode property in propertiesNode.children) { switch (property.attributes["name"]) { case "warpTileX": warpX = int.Parse(property.attributes["value"]); break; case "warpTileY": warpY = int.Parse(property.attributes["value"]); break; } } WarpPoint warpPoint = new WarpPoint(warpX, warpY, xml.attributes["name"], int.Parse(xml.attributes["x"]) + 8, -int.Parse(xml.attributes["y"]) + 8); warpPoints.Add(warpPoint); break; } } for (int x = 0; x < 100; x++) { Scientist s = new Scientist(tilemap.width * RXRandom.Float(), -tilemap.height * RXRandom.Float()); while (BaseGameObject.isWalkable(tilemap, s.x, s.y)) { s.SetPosition(tilemap.width * RXRandom.Float(), -tilemap.height * RXRandom.Float()); } addEnemy(s); } backgroundLayer.AddChild(tilemap); foreach (FTilemap f in otherTilemaps) { backgroundLayer.AddChild(f); } backgroundLayer.AddChild(tilemapCollision); backgroundLayer.AddChild(objectGroup); player.setMap(this); playerLayer.AddChild(player); }
public World(int level) { string beginningMessage = ""; if (beginningMessages.Length > level) { beginningMessage = beginningMessages[level]; } beginningLabel = new FLabel("Large", beginningMessage); beginningLabel.alpha = 1.0f; beginningLabel.y = -70; beginningLabelShadow = new FLabel("Large", beginningMessage); beginningLabelShadow.color = Color.black; beginningLabelShadow.SetPosition(beginningLabel.GetPosition()); beginningLabelShadow.x += 1; beginningLabelShadow.y += -1; this.currentLevelNum = level; string levelName = "Maps/map" + level; this.startNumPlayers = enemiesOnLevel[level]; clock = new Clock(); clock.enableSound(); enemyClock = new EnemyClock(); gui = new FCamObject(); gui.AddChild(clock); gui.AddChild(enemyClock); setClock(clock); Futile.stage.AddChild(playerLayer); tmxMap.LoadTMX(levelName); tilemap = (FTilemap)(tmxMap.getLayerNamed("Tilemap")); FTilemap objectLayer = (FTilemap)(tmxMap.getLayerNamed("Objects")); for (int xInd = 0; xInd < objectLayer.widthInTiles; xInd++) { for (int yInd = 0; yInd < objectLayer.heightInTiles; yInd++) { switch (objectLayer.getFrameNum(xInd, yInd)) { case 0: break; case 10: FNode newSpawn = new FNode(); newSpawn.x = xInd * tilemap._tileWidth + tilemap._tileWidth / 2; newSpawn.y = -yInd * tilemap._tileHeight - tilemap._tileHeight / 2; spawnPoints.Add(newSpawn); break; case 11: playerSpawn = new FNode(); playerSpawn.x = xInd * tilemap._tileWidth + tilemap._tileWidth / 2; playerSpawn.y = -yInd * tilemap._tileHeight - tilemap._tileHeight / 2; break; } } } this.miniMap = new Minimap(this); playerLayer.AddChild(tmxMap); tilemap.clipNode = gui; Player player = new Player(true); gui.follow(player); addPlayer(player); player.setScale(2.0f, true); miniMap.setFollow(player); for (int ind = 0; ind < startNumPlayers; ind++) { Player p = new Player(); addPlayer(p); } Futile.stage.AddChild(gui); gui.AddChild(new MuteMusicButton()); gui.AddChild(miniMap); gui.AddChild(beginningLabelShadow); gui.AddChild(beginningLabel); }
public void setMap(Map map) { this.currentMap = map; this.collisionTilemap = map.tilemapCollision; }
public void LoadMap(string mapName) { C.Save.lastMap = mapName; spawnPoints.Clear(); signs.Clear(); villagers.Clear(); hitSwitches.Clear(); collisionObjects.Clear(); damageObjects.Clear(); playerLayer.RemoveAllChildren(); background.RemoveAllChildren(); foreground.RemoveAllChildren(); this.map = new FTmxMap(); this.map.LoadTMX("Maps/" + mapName); FSoundManager.PlayMusic(map.mapMusic); collisionTilemap = (FTilemap)this.map.getLayerNamed("collision"); wallCollisionTilemap = (FTilemap)this.map.getLayerNamed("walls"); backgroundTilemap = (FTilemap)this.map.getLayerNamed("background"); foregroundTilemap = (FTilemap)this.map.getLayerNamed("foreground"); background.AddChild(backgroundTilemap); background.AddChild(collisionTilemap); background.AddChild(wallCollisionTilemap); foreground.AddChild(foregroundTilemap); if (player == null) { player = new Player(this); C.getCameraInstance().follow(player); player.LoadLastSave(); } collisionObjects.Add(player); playerLayer.AddChild(player); this.y = -16; C.getCameraInstance().setWorldBounds(new Rect(0, -collisionTilemap.height - 16, collisionTilemap.width, collisionTilemap.height + 16)); foregroundTilemap.clipNode = C.getCameraInstance(); collisionTilemap.clipNode = C.getCameraInstance(); wallCollisionTilemap.clipNode = C.getCameraInstance(); backgroundTilemap.clipNode = C.getCameraInstance(); MapLoader.loadObjects(this, map.objects); }