protected void ProcessLayouts(BoardLayoutFinder finder) { var lua = LuaMachine.Instance; object[] luaResult = lua.DoFile("Content/Config/layouts.lua"); var tbl = (LuaTable) luaResult[0]; var thumbnailsPath = (string) tbl["thumbnails"]; var blockSizeTbl = (LuaTable) tbl["block_size"]; var blockSize = LuaMachine.LuaTableToPoint(blockSizeTbl); Texture2D thumbnailSprites = null; if (thumbnailsPath != null) thumbnailSprites = _content.Load<Texture2D>(thumbnailsPath); foreach (var key in tbl.Keys) { if (!(key is double)) { continue; } var layoutTbl = (LuaTable) tbl[key]; var top = (string) layoutTbl["top"]; var bottom = (string) layoutTbl["bottom"]; var unit = (string) layoutTbl["unit"]; var coords = (LuaTable) layoutTbl["thumbnails"]; var layout = new LayoutDescription(unit, top, bottom); if (coords != null && thumbnailSprites != null) { // process thumbnails coordinates layout.Thumbnails = thumbnailSprites; layout.ThumbnailBlocks = coords.Values.Cast<LuaTable>().Select(LuaMachine.LuaTableToPoint).ToArray(); layout.BlockSize = blockSize; } finder.AddLayout(layout); } }
/// <summary> /// Load graphics content for the game. /// </summary> public override void Activate(bool instancePreserved) { if (instancePreserved) { return; } if (_content == null) { _content = new ContentManager(ScreenManager.Game.Services, "Content"); } _sceneRenderer = new SimpleSceneRenderer(ScreenManager.GraphicsDevice, _content) { RenderShadows = false }; var pp = ScreenManager.GraphicsDevice.PresentationParameters; var aspectRatio = pp.BackBufferWidth/(float) pp.BackBufferHeight; _camera = new FreeCamera(SCENE_CENTER, MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000.0f); _cameraManager = new CameraManager(_camera); _scene = new Scene {CameraManager = _cameraManager, Ambient = new Color(0.7f, 0.7f, 0.7f)}; var dirLight = new Light(LightType.Directional, Color.Red) { Direction = new Vector3(0.45f, -0.15f, 0.875f), Position = new Vector3(5.6f, 7.6f, 12.0f) }; _scene.ShadowCastingLights.Add(dirLight); InitializeScene(); // add the debug puzzleboard control int boardMargin = 15; int boardWidth = (pp.BackBufferWidth - 3*boardMargin)/3; int boardHeight = 5*boardWidth/7; var finder = new BoardLayoutFinder(); ProcessLayouts(finder); var board1 = new PuzzleBoard(6, 5) {Player = _player1}; board1.Randomize(); _puzzleBoard1 = new PuzzleBoardWidget(this, _content, new Point(boardMargin, boardMargin), new Point(boardWidth, boardHeight)); _puzzleBoard1.LayoutFinder = finder; _puzzleBoard1.Board = board1; _puzzleBoard1.LayoutAccepted += LayoutAccepted; var board2 = new PuzzleBoard(6, 5); board2.Player = _player2; board2.Randomize(); _puzzleBoard2 = new PuzzleBoardWidget(this, _content, new Point(pp.BackBufferWidth - boardWidth - 2*boardMargin, boardMargin), new Point(boardWidth, boardHeight)); _puzzleBoard2.LayoutFinder = finder; _puzzleBoard2.Board = board2; _puzzleBoard2.LayoutAccepted += LayoutAccepted; //_particleManager = new ParticleManager((Game)ScreenManager.Game); //_particleManager.AddSystem<DustParticleSystem>(DUST_PARTICLE_SYSTEM, 10, player1.InitialPosition.Z + 0.1f); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }