public void DrawLevel(Map map, int[,] TileGids) { _map = map; //_player = new Player(this, playerSpawnX, playerSpawnY); if (HasChild(this)) { this.GetChildren().Clear(); } ///////////background if (_map.background != null) { for (int i = 0; i < map.background.Length; i++) { if (map.background[i].name == "backgroundlayer") { Background background = new Background(map, i); AddChild(background); } if (map.background[i].name == "scrollingbackgroundlayer") { ScrollingBackground sb = new ScrollingBackground(_map, i, _player); AddChild(sb); } } } /////// tiles for (int y = 0; y < TileGids.GetLength(0); y++) { for (int x = 0; x < TileGids.GetLength(0); x++) { if (TileGids[y, x] != 0) { Tiles tile = new Tiles(TileGids[y, x], _map); tile.x = x * map.tileWidth; tile.y = y * map.tileHeight; _collisionSprites.Add(tile); this.AddChild(tile); } } } ////// objects layer if (_map.objGroup.TiledObject != null) { for (int i = 0; i < map.objGroup.TiledObject.Count(); i++) { if (_map.objGroup.TiledObject[i].properties != null) { if (_map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "PICKUP") { Pickup pickup = new Pickup(map.objGroup.TiledObject[i].gid, _map, i); pickup.x = _map.objGroup.TiledObject[i].x; pickup.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(pickup); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "DESTRUCTABLE") { Destructable destructable = new Destructable(_map.objGroup.TiledObject[i].gid, map, i, this); destructable.x = map.objGroup.TiledObject[i].x; destructable.y = map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(destructable); _collisionSprites.Add(destructable); } if (_map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "BUTTON") { Button btn = new Button(_map.objGroup.TiledObject[i].gid, _map, i); btn.x = _map.objGroup.TiledObject[i].x; btn.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(btn); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && map.objGroup.TiledObject[i].properties.property[0].value == "NOTRANSZONE") { NoZone zone = new NoZone(map.objGroup.TiledObject[i].gid, _map, i); zone.x = _map.objGroup.TiledObject[i].x; zone.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(zone); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "TRANSZONE") { YesZone yZone = new YesZone(map.objGroup.TiledObject[i].gid, map, i); yZone.x = _map.objGroup.TiledObject[i].x; yZone.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(yZone); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "ENEMY") { Enemy enemy = new Enemy(map.objGroup.TiledObject[i].gid, map, i, _player); enemy.x = _map.objGroup.TiledObject[i].x; enemy.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(enemy); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "ENEMY2") { Enemy2 enemy2 = new Enemy2(map.objGroup.TiledObject[i].gid, map, i); enemy2.x = _map.objGroup.TiledObject[i].x; enemy2.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(enemy2); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "DAMAGE") { Thornes thornes = new Thornes(map.objGroup.TiledObject[i].gid, map, i); thornes.x = _map.objGroup.TiledObject[i].x; thornes.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(thornes); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "SPAWN") { playerSpawnX = map.objGroup.TiledObject[i].x; playerSpawnY = map.objGroup.TiledObject[i].y; } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "ANIMAL") { Animal animal = new Animal(map); animal.x = _map.objGroup.TiledObject[i].x; animal.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(animal); } if (map.objGroup.TiledObject[i].properties.property[0].name == "Type" && _map.objGroup.TiledObject[i].properties.property[0].value == "ARTIFACT") { Artifact artifact = new Artifact(); artifact.x = _map.objGroup.TiledObject[i].x; artifact.y = _map.objGroup.TiledObject[i].y - _map.objGroup.TiledObject[i].height; AddChild(artifact); } } } } //////////////////////player _player = new Player(this, playerSpawnX, playerSpawnY); //player AddChild(_player); ///////// foreground if (_map.background != null) { for (int i = 0; i < map.background.Length; i++) { if (_map.background[i].name == "foreground layer") { ForeGround foreground = new ForeGround(_map, i); AddChild(foreground); } } } //////////////HUD _hud = new HUD(this, _player); AddChild(_hud); }
public Level() //TRAIN SETUP { background = new Background(); AddChild(background); BaseShort baseshort = new BaseShort(-160, 600); AddChild(baseshort); BaseLongCargo baselongcargo = new BaseLongCargo(250, 600); AddChild(baselongcargo); LongBackground longbackground = new LongBackground(1060, 400); AddChild(longbackground); BaseLong baselong = new BaseLong(1060, 600); AddChild(baselong); LongCeiling baselongceiling = new LongCeiling(1060, 400); AddChild(baselongceiling); BaseShort baseshortmiddle = new BaseShort(1870, 600); AddChild(baseshortmiddle); TallLongCargo talllongcargo = new TallLongCargo(2280, 400); AddChild(talllongcargo); BaseIntermediateCargo baseintermediatecargo = new BaseIntermediateCargo(3090, 600); AddChild(baseintermediatecargo); IntermediateBackground intermediatebackground = new IntermediateBackground(3700, 400); AddChild(intermediatebackground); BaseIntermediate baseintermediate = new BaseIntermediate(3700, 600); AddChild(baseintermediate); BaseIntermediateCeiling baseintermediateceiling = new BaseIntermediateCeiling(3700, 400); AddChild(baseintermediateceiling); BaseIntermediateCargo baseintermediatefront = new BaseIntermediateCargo(4310, 600); AddChild(baseintermediatefront); LongBackgroundLocomotive longlocomotive = new LongBackgroundLocomotive(4920, 400); AddChild(longlocomotive); Wheel wheel1 = new Wheel(320, 670); AddChild(wheel1); Wheel wheel2 = new Wheel(410, 670); AddChild(wheel2); Wheel wheel3 = new Wheel(960, 670); AddChild(wheel3); Wheel wheel4 = new Wheel(870, 670); AddChild(wheel4); Crate crate1 = new Crate(380, 560); AddChild(crate1); Crate crate2 = new Crate(200, 560); AddChild(crate2); Player player = new Player(this); AddChild(player); scrollTarget = player; }