コード例 #1
0
ファイル: Game.cs プロジェクト: deleter8/ld27
        /// <summary>
        /// The main game loop
        /// </summary>
        public void Update(TimeMonitor time)
        {
            _text.DisplayedString  = "Fps: " + time.CurrentFps;
            _text2.DisplayedString = "Average Fps: " + time.AverageFps;
            _text.Position         = new Vector2f(10, 10);
            _text2.Position        = new Vector2f(10, 58);

            _testSprite.Scale    = new Vector2f(((float)Math.Sin(time.TotalTime * 10) / 2 + 1) * 3, ((float)Math.Cos(time.TotalTime * 3) / 2 + 1) * 3);
            _testSprite.Position = new Vector2f(_mousePos.X - (_testSprite.Texture.Size.X / 2) * _testSprite.Scale.X, _mousePos.Y - (_testSprite.Texture.Size.Y / 2) * _testSprite.Scale.Y);
        }
コード例 #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            var time = new TimeMonitor(1000);

            // Request a 32-bits depth buffer when creating the window
            var contextSettings = new ContextSettings {
                DepthBits = 32
            };

            // Create the main window
            var window = new RenderWindow(new VideoMode(1600, 900), "TenSeconds", Styles.Close | Styles.Titlebar, contextSettings);

            // Make it the active window for OpenGL calls
            window.SetActive();

            var windowInfo      = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(window.SystemHandle);
            var graphicsContext = new OpenTK.Graphics.GraphicsContext(OpenTK.Graphics.GraphicsMode.Default, windowInfo);

            graphicsContext.MakeCurrent(windowInfo);
            graphicsContext.LoadAll();

            // Setup event handlers
            window.Closed     += OnClosed;
            window.KeyPressed += OnKeyPressed;
            window.Resized    += OnResized;

            var inputManager = new InputManager();

            inputManager.Init(window);
            var game = new Game();

            game.Init(window);

            while (window.IsOpen() && game.IsRunning)
            {
                time.Update();

                // Process events
                window.DispatchEvents();

                inputManager.Update(window);
                game.HandleInput(inputManager);

                game.Update(time);

                // Clear color and depth buffer
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                game.Draw(window);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }