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

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

            window.GameWindow.Closing += (s, e) => Serialization.ToBinFile(gameState, GetGameStateFilePath());             //save game state at end of program
            window.GameWindow.KeyDown += (s, e) => { if (e.Key == OpenTK.Input.Key.R)
                                                     {
                                                         gameState = new GameState();
                                                     }
            };                                                                                                                    //reset
            window.GameWindow.MouseDown += (s, e) =>
            {
                var coord = window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y);                 //convert pixel coordinates to [-1,1]²
                HandleInput(gameState, (int)e.Button, coord.X * .5f + .5f, coord.Y * .5f + .5f);
            };
            //todo student: app.Resize += (width, height) => //todo student: react on window changes (update apsect ratio of game)
            window.Render += () => Visual.DrawScreen(gameState);             //this draws the game using OpenGL
            //app.Render += () => VisualConsole.DrawScreen(gameState); //this draws the game to the console
            window.Run();
        }
コード例 #2
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var model  = new Model();
            var view   = new View();

            window.Update += (dt) =>
            {
                // handle input
                var movementXAxis = Keyboard.GetState()[Key.Left] ? -1f : (Keyboard.GetState()[Key.Right] ? 1f : 0f);
                model.Update(movementXAxis, dt);
            };

            window.Render += () =>
            {
                view.ClearScreen();
                view.DrawPlayer(model.playerBounds.CenterX, model.playerBounds.CenterY, model.playerBounds.Radius);
                foreach (var shape in model.ShapeBounds)
                {
                    view.DrawAsteroids(shape);
                }
            };

            window.Resize += view.Resize;

            window.Run();
        }
コード例 #3
0
        private static void Main()
        {
            var window = new ExampleWindow();

            var camera = window.GameWindow.CreateOrbitingCameraController(0.3f, 70, 0.01f, 30f);

            camera.View.Elevation = 15;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
コード例 #4
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.AddWindowAspectHandling(visual.Camera.Projection);
            var movementState = window.GameWindow.AddFirstPersonCameraEvents(visual.Camera.View);

            window.Update += (dt) => visual.Camera.View.ApplyRotatedMovement(movementState.movement * 30 * dt);
            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw();
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var window   = new ExampleWindow(debug: true);
            var view     = new View(window.ContentLoader, window.RenderContext);
            var bounds   = view.Bounds;
            var distance = 1.5f * Math.Max(bounds.SizeX, Math.Max(bounds.SizeY, bounds.SizeZ));
            var camera   = window.GameWindow.CreateOrbitingCameraController(distance, 70f, 1f, 2000f);

            camera.View.Target = new Vector3(bounds.CenterX, bounds.CenterY, bounds.CenterZ);
            var    useViewCamera = false;
            Action draw          = () => view.Draw(camera, camera.View.CalcPosition());

            window.GameWindow.KeyDown += (s, a) =>
            {
                if (Key.C == a.Key)
                {
                    useViewCamera = !useViewCamera;
                    if (useViewCamera && 0 < view.Cameras.Count())
                    {
                        draw = () =>
                        {
                            var cam = view.Cameras.First();
                            var pos = cam.Matrix.Translation;
                            view.Draw(cam, pos);
                        };
                    }
                    else
                    {
                        draw = () => view.Draw(camera, camera.View.CalcPosition());
                    }
                }
            };
            window.Render += () => draw();
            window.Run();
        }
コード例 #6
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var model  = new Model();
            var view   = new View();

            window.Update += (dt) =>
            {
                // handle input
                float axisLeftRight = window.Input.IsButtonDown("Left") ? -1f : window.Input.IsButtonDown("Right") ? 1f : 0f;
                model.Update(axisLeftRight, dt);
            };

            window.Render += () =>
            {
                view.ClearScreen();
                foreach (var shape in model.ShapeBounds)
                {
                    view.DrawShape(shape);
                }
            };

            window.Resize += view.Resize;

            window.Run();
        }
コード例 #7
0
        private static void Main()
        {
            var window = new ExampleWindow(debug: true);

            var camera = window.GameWindow.CreateFirstPersonCameraController(1f, new Vector3(36f, 0.1f, 30f), 70f, 0.01f, 300f);

            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.KeyDown += (s, a) => { if (a.Key == OpenTK.Input.Key.Tab)
                                                     {
                                                         visual.Wireframe = !visual.Wireframe;
                                                     }
            };

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var window  = new ExampleWindow();
            var dir     = ContentSearchDirectoryAttribute.GetContentSearchDirectory();
            var tileMap = new TileMap(dir + @"\Content\level.tmx");
            var model   = new Model(tileMap.ExtractStart(), tileMap.ExtractCollisionGrid());
            var view    = new View(window.ContentLoader, window.RenderContext.RenderState, tileMap.ExtractTileSprites(), tileMap.ExtractViewLayerGrids());

            window.GameWindow.MouseWheel += (s, e) => view.Zoom *= (float)Math.Pow(1.05, 3 * e.DeltaPrecise);

            float MovementAxis(float dt, string keyMinus, string keyPlus)
            {
                return(window.Input.IsButtonDown(keyPlus) ? dt : window.Input.IsButtonDown(keyMinus) ? -dt : 0f);
            }

            window.Update += (dt) =>
            {
                Console.WriteLine(string.Join("#", window.Input.PressedButtons));
                float deltaX = MovementAxis(dt, "Left", "Right");
                float deltaY = MovementAxis(dt, "Down", "Up");
                model.Update(deltaX, deltaY);
            };
            window.Render += () =>
            {
                view.Draw(model.Player);
            };
            window.Resize += view.Resize;
            window.Run();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: twentySeven7/Zenseless
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext, window.ContentLoader);

            void updateMouseState(MouseEventArgs e)
            {
                var pos = window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y);                 //convert pixel coordinates to [0,1]²

                pos *= .5f;
                pos += System.Numerics.Vector2.One * .5f;
                var mouseState = new MouseState()
                {
                    position  = pos,
                    drawState = GetDrawState(e.Mouse)
                };

                visual.MouseState = mouseState;
            }

            window.GameWindow.MouseMove += (s, a) => updateMouseState(a);
            window.GameWindow.MouseDown += (s, a) => updateMouseState(a);
            window.Render += visual.Render;
            window.Run();
        }
コード例 #10
0
        private static void Main()
        {
            var window   = new ExampleWindow();
            var model    = new Model(1000);
            var renderer = new Renderer();

            void updateSourceLocation(MouseEventArgs e)
            {
                model.Emitter = window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y);                 //convert pixel coordinates to [-1,1]²
            }

            //move the mouse to move the particle source(emitter)
            window.GameWindow.MouseMove += (s, a) => updateSourceLocation(a);
            window.GameWindow.MouseDown += (s, a) => updateSourceLocation(a);

            window.Update += (time) => model.Update(time);
            window.Resize += renderer.Resize;
            window.Render += () =>
            {
                renderer.Clear();
                foreach (var particle in model.Particles)
                {
                    renderer.DrawPoint(particle.Location, particle.Age);
                }
                renderer.DrawPoint(model.Emitter, Color.Red);
            };
            window.Run();
        }
コード例 #11
0
ファイル: Sokoban.cs プロジェクト: twentySeven7/Zenseless
        private static void Main()
        {
            var       window = new ExampleWindow();
            GameLogic logic;

            try
            {
                logic = (GameLogic)Serialization.FromBinFile(GetGameStateFilePath());                 //try to load the last game state from a file at start of program
            }
            catch
            {
                logic = new GameLogic(window.ContentLoader.Load <string>("levels"));                //loading failed -> default game state
            }
            window.GameWindow.Title = "Sokoban";
            //app.GameWindow.CursorVisible = false;
            window.GameWindow.Closing += (s, e) => Serialization.ToBinFile(logic, GetGameStateFilePath());             //save game state at end of program

            var renderer = new RendererGL4(window.RenderContext.RenderState, window.ContentLoader);
            //var renderer = new Renderer(window.RenderContext.RenderState, window.ContentLoader);
            var sceneManager = new SceneManager(logic, renderer);

            window.GameWindow.KeyDown += (s, e) => sceneManager.HandleInput(KeyBindings(e.Key));
            window.Resize             += (w, h) => renderer.ResizeWindow(w, h);
            window.Render             += () => sceneManager.Render();
            window.Run();
        }
コード例 #12
0
        static void Main(string[] args)
        {
            var window = new ExampleWindow();
            var logic  = new Logic();
            var view   = new View();

            window.Update += (updatePeriod) =>
            {
                float axisPaddle = Keyboard.GetState()[Key.Left] ? -1.0f : Keyboard.GetState()[Key.Right] ? 1.0f : 0.0f;
                if (!logic.Update(updatePeriod, axisPaddle))
                {
                    window.GameWindow.Close();
                }
            };
            window.Render += () =>
            {
                view.Clear();
                foreach (var brick in logic.Bricks)
                {
                    view.DrawBox(brick);
                }
                view.DrawBox(logic.Paddle);
                view.DrawBall(logic.Ball);
            };
            window.Run();
        }
コード例 #13
0
        private static void Main()
        {
            var window = new ExampleWindow();

            var camera = window.GameWindow.CreateOrbitingCameraController(1.8f, 70, 0.1f, 50f);

            camera.View.TargetY = -0.3f;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var  globalTime       = new GameTime();
            bool doPostProcessing = false;

            window.Render += () =>
            {
                if (doPostProcessing)
                {
                    visual.DrawWithPostProcessing(globalTime.AbsoluteTime, camera);
                }
                else
                {
                    visual.Draw(camera);
                }
            };

            window.Update += (t) => doPostProcessing = !window.Input.IsButtonDown("Space");
            window.Resize += visual.Resize;
            window.Run();
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: Chr1stianSutter/Zenseless
        static void Main(string[] args)
        {
            var window = new ExampleWindow(debug: true);
            var view   = new View(window.ContentLoader);

            window.Render += () => view.Draw();
            window.Run();
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Michael-Zp/GraphicsWar
        static void Main(string[] args)
        {
            var window = new ExampleWindow();
            var view   = new View();

            window.Render += () => view.Draw();
            window.Run();
        }
コード例 #16
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MyVisual();

            window.Render += visual.Render;
            window.Run();
        }
コード例 #17
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MyVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += visual.Render;
            window.Run();
        }
コード例 #18
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(30, 90, 0.1f, 500f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(camera);
            window.Run();
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: twentySeven7/Zenseless
        static void Main(string[] args)
        {
            var window  = new ExampleWindow();
            var tileMap = new TileMap();
            var view    = new View(window.ContentLoader, window.RenderContext.RenderState, tileMap.SpriteSheetName);

            window.Render += () => view.Draw(tileMap.Tiles);
            window.Run();
        }
コード例 #20
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MyVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time   = new GameTime();

            window.Render += () => visual.Render(time.AbsoluteTime);
            window.Run();
        }
コード例 #21
0
        private static void Main()
        {
            var window = new ExampleWindow(debug: true);
            var camera = window.GameWindow.CreateOrbitingCameraController(3f, 70f, 0.1f, 500f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(camera, camera.View.CalcPosition());
            window.Run();
        }
コード例 #22
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MyVisual(window.RenderContext.RenderState);

            window.Update += visual.Update;
            window.Render += visual.Render;
            window.Run();
        }
コード例 #23
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var orbit  = window.GameWindow.CreateOrbitingCameraController(0.5f, 70, 0.01f, 50f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(orbit, orbit.CalcPosition());
            window.Run();
        }
コード例 #24
0
        private static void Main()
        {
            var window = new ExampleWindow();

            window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath())); //would be faster if you only specify a subdirectory
            var visual = new MainVisual(window.ContentLoader);

            window.Render += visual.Render;
            window.Run();
        }
コード例 #25
0
        private static void Main()
        {
            var window = new ExampleWindow();
            //window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath())); //would be faster if you only specify a subdirectory
            var orbit  = window.GameWindow.CreateOrbitingCameraController(15, 30, 0.1f, 50f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(orbit, orbit.CalcPosition());
            window.Run();
        }
コード例 #26
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var logic  = new Model();
            var visual = new MyVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Update += logic.Update;
            window.Render += () => visual.Render(logic.GetPlanets());
            window.Run();
        }
コード例 #27
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.AddWindowAspectHandling(visual.Camera.Projection);
            window.GameWindow.AddMayaCameraEvents(visual.Camera.Projection, visual.Camera.View);
            window.Render += visual.Render;
            window.Run();
        }
コード例 #28
0
        private static void Main()
        {
            var window = new ExampleWindow();
            //window.GameWindow.Bounds = new System.Drawing.Rectangle(2000, 1000, 1000, 1000); //TODO: for debug
            var model = new Model();
            var view  = new View(window.RenderContext, window.ContentLoader);

            var selectionStart = Vector2.Zero;
            var selectionEnd   = Vector2.Zero;

            window.GameWindow.MouseDown += (s, e) =>
            {
                var coord = view.TransformToModel(window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y));
                switch (e.Button)
                {
                case MouseButton.Left:
                    selectionStart = coord;
                    selectionEnd   = coord;
                    break;

                case MouseButton.Right:
                    model.MoveTo(coord);
                    break;
                }
            };
            window.GameWindow.MouseUp += (s, e) =>
            {
                if (MouseButton.Left == e.Button)
                {
                    model.Select(selectionStart, selectionEnd);
                    selectionStart = Vector2.Zero;
                    selectionEnd   = Vector2.Zero;
                }
            };
            window.GameWindow.MouseMove += (s, e) =>
            {
                if (e.Mouse.IsButtonDown(MouseButton.Left))
                {
                    var coord = view.TransformToModel(window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y));
                    selectionEnd = coord;
                    model.Select(selectionStart, selectionEnd);
                }
            };
            window.Render += () =>
            {
                view.Clear();
                foreach (var unit in model.Units)
                {
                    view.DrawUnit(unit);
                }
                view.DrawRect(selectionStart, selectionEnd);
            };
            window.Update += model.Update;
            window.Run();
        }
コード例 #29
0
        private static void Main()
        {
            var window = new ExampleWindow();

            window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath()));             //would be faster if you only specify a subdirectory
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time   = new GameTime();

            window.Render += () => visual.Render(time.AbsoluteTime);
            window.Run();
        }
コード例 #30
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var logic  = new Model();
            var visual = new MyVisual();

            window.Update += logic.Update;
            window.Render += () => visual.Render(logic.Shapes);
            window.Resize += visual.Resize;
            window.Run();
        }