override public void create() { FlxG.backColor = FlxColor.ToColor("dedbc3"); base.create(); _world = new World(new Vector2(0, 98.0f)); charactersGrp = new FlxGroup(); blocksGrp = new FlxGroup(); movingBlocksGrp = new FlxGroup(); doors = new FlxGroup(); crates = new FlxGroup(); //Dictionary<string,string> levelAttrs = FlxXMLReader.readAttributesFromOelFile("ogmo/level1.oel", "level/grid"); //FlxTilemap tiles = new FlxTilemap(); //tiles.useExtraMiddleTiles = false; //tiles.auto = FlxTilemap.AUTO; //tiles.indexOffset = -1; //tiles.loadMap(levelAttrs["grid"], FlxG.Content.Load<Texture2D>("level1_tiles"), 10, 10); //tiles.setScrollFactors(0, 0); //tiles.boundingBoxOverride = true; //blocksGrp.add(tiles); List <Dictionary <string, string> > lblocks = FlxXMLReader.readNodesFromOelFile("ogmo/level1.oel", "level/grid"); foreach (Dictionary <string, string> nodes in lblocks) { FarTileblock t = new FarTileblock(Convert.ToInt32(nodes["x"]) + (Convert.ToInt32(nodes["w"]) / 2), Convert.ToInt32(nodes["y"]) + (Convert.ToInt32(nodes["h"]) / 2), Convert.ToInt32(nodes["w"]), Convert.ToInt32(nodes["h"]), _world); t.auto = FlxTilemap.AUTO; t.loadTiles("level1_tiles", 10, 10, 0); blocksGrp.add(t); t._body.BodyType = BodyType.Static; FlxTileblock t2 = new FlxTileblock(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"]), Convert.ToInt32(nodes["w"]), Convert.ToInt32(nodes["h"])); t2.auto = FlxTilemap.AUTO; t2.loadTiles("level1_tiles", 10, 10, 0); blocksGrp.add(t2); } List <Dictionary <string, string> > blocks = FlxXMLReader.readNodesFromOelFile("ogmo/level1.oel", "level/tileblocks"); foreach (Dictionary <string, string> nodes in blocks) { if (nodes["Name"] == "elevator") { MovingBlock block = new MovingBlock(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"])); block.loadGraphic("level1_specialBlock", false, true, 40, 20); movingBlocksGrp.add(block); FlxPath xpath = new FlxPath(null); xpath.add(Convert.ToInt32(nodes["x"]) + 20, Convert.ToInt32(nodes["y"]) + 10); xpath.addPointsUsingStrings(nodes["pathNodesX"], nodes["pathNodesY"], 20, 10); block.followPath(xpath, 80, FlxObject.PATH_FORWARD, false); } if (nodes["Name"] == "door") { Door door = new Door(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"]) - 100); doors.add(door); } //foreach (var item in nodes) //{ // Console.WriteLine("{0} {1}", item.Key, item.Value); //} } //bat = new Bat(x, y); //actors.add(bat); //Console.WriteLine("Building a bat {0} {1} {2} {3}", x, y, PathNodesX, PathNodesY); //if (PathNodesX != "" && PathNodesY != "") //{ // Console.WriteLine("Building a path {0} {1} {2}", PathNodesX, PathNodesY, PathCornering); // FlxPath xpath = new FlxPath(null); // xpath.add(x, y); // xpath.addPointsUsingStrings(PathNodesX, PathNodesY); // bat.followPath(xpath, PathSpeed, PathType, false); // bat.pathCornering = PathCornering; //} Andre andre = new Andre(0, 0); charactersGrp.add(andre); Liselot liselot = new Liselot(40, 40); charactersGrp.add(liselot); Army army = new Army(30, 20); charactersGrp.add(army); Inspector inspector = new Inspector(50, 50); charactersGrp.add(inspector); Worker worker = new Worker(60, 60); charactersGrp.add(worker); Chef chef = new Chef(100, 30); charactersGrp.add(chef); FlxTileblock bg = new FlxTileblock(0, 0, 240, 800); bg.auto = FlxTileblock.RANDOM; bg.loadTiles("level1_shelfTile", 80, 80, 0); add(bg); bg = new FlxTileblock(640, 0, 240, 800); bg.auto = FlxTileblock.RANDOM; bg.loadTiles("level1_shelfTile", 80, 80, 0); add(bg); for (int i = 0; i < 5; i++) { SmallCrate c = new SmallCrate((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100)); crates.add(c); } for (int i = 0; i < 5; i++) { Bottle b = new Bottle((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100)); crates.add(b); } for (int i = 0; i < 55; i++) { Fruit f = new Fruit((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100), _world); f._body.ApplyLinearImpulse(new Vector2(20, 2120)); crates.add(f); } add(doors); add(charactersGrp); add(blocksGrp); add(movingBlocksGrp); add(crates); FlxG.showHud(); FlxG.setHudTextPosition(1, FlxG.width / 2, 10); FlxG.setHudTextScale(1, 3); }
public void loadOgmo() { Console.WriteLine("Ogmo Loading level {0}", Globals.hole); Dictionary <string, string> ogmo = FlxXMLReader.readAttributesFromOelFile("putt/ogmo/hole" + Globals.hole.ToString() + ".oel", "level/roll"); rollTiles = new FlxTilemap(); rollTiles.loadMap(ogmo["roll"], FlxG.Content.Load <Texture2D>("putt/rollIndicators"), 8, 8); rollTiles.color = new Color(1, 1, 1, 0.8f); //add(rollTiles); // ------------------------------------ string[] cols; string[] rows = ogmo["roll"].Split('\n'); int heightInTiles = rows.Length; int r = 0; //int c; foreach (var item in rows) { int l = 0; cols = rows[r].Split(','); foreach (var x in cols) { if (x != "-1" && x != "-1\r") { //Console.WriteLine("Roll: {0}", x); RollIndicator roll = new RollIndicator(l * 8, r * 8, Convert.ToInt32(x)); add(roll); } l++; } r++; } List <Dictionary <string, string> > levelNodes = FlxXMLReader.readNodesFromOelFile("putt/ogmo/hole" + Globals.hole.ToString() + ".oel", "level/bg"); foreach (Dictionary <string, string> nodes in levelNodes) { //foreach (KeyValuePair<string, string> kvp in nodes) //{ // Console.Write("Key = {0}, Value = {1}, ", // kvp.Key, kvp.Value); //} //Console.Write("\r\n"); if (nodes["Name"] == "hole") { hole.reset(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"])); } } }