コード例 #1
0
        private static void Main()
        {
            var       app = new ExampleApplication();
            GameState gameState;

            try
            {
                gameState = (GameState)Serialize.ObjFromBinFile(GetGameStateFilePath());                 //try to load the game state from a file at start of program
            }
            catch
            {
                gameState = new GameState();                 //loading failed -> reset
            }

            app.GameWindow.Closing += (s, e) => gameState.ObjIntoBinFile(GetGameStateFilePath());             //save game state at end of program
            app.GameWindow.KeyDown += (s, e) => { if (e.Key == OpenTK.Input.Key.R)
                                                  {
                                                      gameState = new GameState();
                                                  }
            };                                                                                                                 //reset
            app.GameWindow.MouseDown += (s, e) =>
            {
                var coord = app.CalcNormalized(e.X, e.Y);                 //convert mouse coordinates from pixel to [0,1]²
                HandleInput(gameState, (int)e.Button, coord.X, coord.Y);
            };
            //todo student: app.Resize += (width, height) => //todo student: react on window changes (update apsect ratio of game)
            app.Render += () => Visual.DrawScreen(gameState);             //this draws the game using OpenGL
            //app.Render += () => VisualConsole.DrawScreen(gameState); //this draws the game to the console
            app.Run();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Jonnyf16/Framework
        private static void Main()
        {
            var app = new ExampleApplication();

            Resources.LoadResources(app.ResourceManager);
            var visual = new MainVisual();
            Action <MouseEventArgs> updateMouseState = (a) =>
            {
                var mouseState = new MouseState();
                mouseState.position  = app.CalcNormalized(a.X, a.Y);
                mouseState.drawState = GetDrawState(a.Mouse);
                visual.MouseState    = mouseState;
            };

            app.GameWindow.MouseMove += (s, a) => updateMouseState(a);
            app.GameWindow.MouseDown += (s, a) => updateMouseState(a);
            app.Render += visual.Render;
            app.Run();
        }