Exemple #1
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);

            Stopwatch globalTime       = new Stopwatch();
            bool      doPostProcessing = false;

            app.Render += () =>
            {
                float time = (float)globalTime.Elapsed.TotalSeconds;
                if (doPostProcessing)
                {
                    visual.DrawWithPostProcessing(time);
                }
                else
                {
                    visual.Draw();
                }
            };

            app.Update += (t) => doPostProcessing = !Keyboard.GetState()[Key.Space];
            app.Resize += visual.Resize;
            app.GameWindow.ConnectEvents(visual.OrbitCamera);

            globalTime.Start();
            app.Run();
        }
Exemple #2
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();
        }
Exemple #3
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MyVisual();

            app.Render += visual.Render;
            app.Run();
        }
Exemple #4
0
        private static void Main()
        {
            var app        = new ExampleApplication();
            var controller = new Controller();

            app.Render += controller.Render;
            app.Update += controller.Update;
            app.Run();
        }
Exemple #5
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MyVisual(app.GameWindow.Width, app.GameWindow.Height);

            app.Render += visual.Render;
            app.Update += visual.Update;
            app.Run();
        }
Exemple #6
0
        private static void Main()
        {
            var app = new ExampleApplication();
            //run the update loop, which calls our registered callbacks
            var visual = new MyVisual();

            app.Render += visual.Render;
            app.Run();
        }
Exemple #7
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += visual.Render;
            app.Run();
        }
Exemple #8
0
        public static void Main()
        {
            var app        = new ExampleApplication();
            var canvas     = new Canvas();
            var rasterizer = new Rasterizer(10, 10, canvas.Draw);

            app.Render += rasterizer.Render;
            //app.Render += () => Screenshot();
            app.Run();
        }
Exemple #9
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.GameWindow.ConnectEvents(visual.OrbitCamera);
            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += visual.Render;
            app.Run();
        }
Exemple #10
0
        private static void Main()
        {
            var app = new ExampleApplication();
            //app.IsRecording = true;
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);

            app.Render += visual.Render;
            app.Update += visual.Update;
            app.Run();
        }
Exemple #11
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var model  = new Model();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += () => visual.Render(model.Bodies);
            app.Update += model.Update;
            app.GameWindow.ConnectEvents(visual.Camera);
            app.Run();
        }
Exemple #12
0
        private static void Main()
        {
            var app        = new ExampleApplication();
            var controller = new Controller();
            var logic      = new GameLogic();
            var renderer   = new Renderer();

            logic.NewPosition += (name, x, y) => renderer.UpdateSprites(name, x, y);
            LoadLevelData(LevelData.level1, logic, renderer);

            app.Resize += (width, height) => renderer.Resize(width, height);
            app.Render += () => renderer.Render(logic.Bounds);
            app.Update += (updatePeriod) => HandleInput(updatePeriod, logic);
            app.Run();
        }
Exemple #13
0
        private static void Main()
        {
            var app = new ExampleApplication();

            LoadResources(app.ResourceManager);
            var controller = new Controller();
            var visual     = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            var timeSource = new Stopwatch();

            app.GameWindow.ConnectEvents(visual.OrbitCamera);
            app.Render += visual.Render;
            app.Update += (t) => visual.Update((float)timeSource.Elapsed.TotalSeconds);
            timeSource.Start();
            app.Run();
        }
Exemple #14
0
        public MainVisual(ExampleApplication app)
        {
            this.app = app;
            this.timeSource.Start();


            // light setup
            this.lightPosition = new Vector3(0, 1.1f, 0);

            // wind setup
            this.windDirection = new Vector3(0.0f);

            // rain setup
            this.rainState    = false;
            this.rainPosition = new Vector3(-.5f, 1.2f, -.5f);
            this.visualRain   = new VisualRain(this.rainPosition, this.windDirection);

            // candle setup
            this.candleState     = true;
            this.candlePosition  = new Vector3(.0f, -.02f, .0f);
            this.candleThickness = .15f;

            // cloud setup
            this.cloudTranslation = new Vector3(.0f, .1f, .0f);

            // objects setup
            this.visualObjects = new VisualObjects(this.rainPosition, this.candlePosition, this.lightPosition);

            // smoke setup
            this.smokeState    = false;
            this.smokePosition = new Vector3(.0f, .5f, .0f);
            this.visualSmoke   = new VisualSmoke(Vector3.Zero, this.windDirection);

            // flame setup
            this.firePosition = new Vector3(.0f, .55f, .0f);
            this.visualFlame  = new VisualFlame(this.firePosition);

            // camera setup
            this.camera.FarClip   = 80;
            this.camera.Distance  = 2.5f;
            this.camera.FovY      = 70;
            this.camera.Elevation = 15;
            this.camera.Azimuth   = 0;
        }
Exemple #15
0
        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();
        }
Exemple #16
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.GameWindow.MouseMove += (s, e) =>
            {
                if (ButtonState.Pressed == e.Mouse.LeftButton)
                {
                    visual.CameraAzimuth   += 300 * e.XDelta / (float)app.GameWindow.Width;
                    visual.CameraElevation += 300 * e.YDelta / (float)app.GameWindow.Height;
                }
            };
            app.GameWindow.MouseWheel += (s, e) => visual.CameraDistance *= (float)Math.Pow(1.05, e.DeltaPrecise);
            app.Update += visual.Update;
            app.Render += visual.Render;
            app.Run();
        }