override public void create() { base.create(); FlxG.hideHud(); _world = new World(new Vector2(0, 98.0f)); for (int i = 0; i < 10; i++) { Vector2 v = new Vector2((int)FlxU.random(0, 400), (int)FlxU.random(0, 200)); FarSprite f = new FarSprite((int)v.X, (int)v.Y, _world); f.loadGraphic("flixel/initials/crate_80x60", true, false, (int)FlxU.random(10, 20), (int)FlxU.random(10, 20)); f._body.Mass = 500f; //f._body.AngularVelocity = FlxU.random(-20,20); add(f); } for (int i = 0; i < 10; i++) { Vector2 v = new Vector2((int)FlxU.random(0, 400), (int)FlxU.random(0, 200)); FarTileblock f = new FarTileblock((int)v.X, (int)v.Y, (int)FlxU.random(10, 40), (int)FlxU.random(10, 40), _world); f.loadTiles("flixel/initials/crate_80x60", 5, 5, 0); //f.loadGraphic("flixel/initials/crate_80x60", true, false, (int)FlxU.random(10, 20), (int)FlxU.random(10, 20)); f._body.Mass = 500f; f._body.AngularVelocity = FlxU.random(-20, 20); f.moves = true; add(f); } _ground = BodyFactory.CreateRectangle(_world, 2000, 20, 1.0f, new Vector2(0, 350), null); _ground.BodyType = BodyType.Static; g1 = new FlxSprite(0, 340); g1.loadGraphic("flixel/diagnostic/testpalette", true, false, 1000, 20); add(g1); }
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); }