Stage getStageFromNode(XmlNode stageNode) { Vector2 boundary = parseAndScaleOrderedPairToVector2(stageNode.Attributes["boundary"].InnerText); Stage stage = new Stage(game, boundary, stageNode.Attributes["background"].InnerText, stageNode.Attributes["music"].InnerText, stageNode.Attributes["id"].InnerText); ControllerFactory controllerFactory = new ControllerFactory(stage, game, megaman); addBoundary(stage, boundary); foreach (XmlNode configItemNode in stageNode.ChildNodes) { if (configItemNode.Name == "block") { Block block = getBlockFromNode(configItemNode, stage); // there's got to be a better way then passing the stage... stage.AddSprite(block); stage.AddCollidable(block); } else if (configItemNode.Name == "platform") { Point platformDimensions = parseAndScaleOrderedPairToPoint(configItemNode.Attributes["size"].InnerText); Vector2 platformLocation = parseAndScaleOrderedPairToVector2(configItemNode.Attributes["location"].InnerText); BlockState platformType = BlockStateHelper.GetState(configItemNode.Attributes["blockType"].InnerText); platformDimensions.X += (int)platformLocation.X; platformDimensions.Y += (int)platformLocation.Y; for (int i = (int)platformLocation.X; i < platformDimensions.X; i += 32) { for (int j = (int)platformLocation.Y; j < platformDimensions.Y; j += 32) { Block block = new Block(new Vector2(i, j), platformType, megaman, content); stage.AddSprite(block); stage.AddCollidable(block); } } } else if (configItemNode.Name == "item") { Sprite item = getItemFromNode(configItemNode); stage.AddSprite(item); stage.AddCollidable(item); } else if (configItemNode.Name == "enemy") { Sprite enemy = getEnemyFromNode(configItemNode); stage.AddSprite(enemy); stage.AddCollidable(enemy); } else if(configItemNode.Name == "megaman") { stage.MegamanInitialPosition = parseAndScaleOrderedPairToVector2(configItemNode.Attributes["location"].InnerText); } else if (configItemNode.Name == "parallax") { stage.AddSprite(getParallaxSpriteFromNode(configItemNode, stage)); } } stage.Checkpoint = parseAndScaleOrderedPairToVector2(stageNode.Attributes["checkpoint"].InnerText); stage.AddSprite(new HUD(game.Content, game.Megaman, stage)); stage.AddController(controllerFactory.GetGamePadController()); stage.AddController(controllerFactory.GetKeyboardController()); return stage; }
Menu getMenuFromNode(XmlNode menuNode) { Menu menu = new Menu(menuNode.Attributes["background"].InnerText, bool.Parse(menuNode.Attributes["canGoBack"].InnerText), game, menuNode.Attributes["initialChoice"].InnerText); ControllerFactory controllerFactory = new ControllerFactory(menu, game, megaman); foreach (XmlNode configItemNode in menuNode.ChildNodes) { if (configItemNode.Name == "choice") { MenuChoice menuChoice = getMenuChoiceFromNode(configItemNode); menu.AddSprite(menuChoice); menu.AddChoice(menuChoice); } else if (configItemNode.Name == "text") { menu.AddSprite(getMenuTextFromNode(configItemNode)); } } menu.AddController(controllerFactory.GetKeyboardController()); menu.AddController(controllerFactory.GetGamePadController()); return menu; }