Example #1
0
        public void OnEvent(SDL.SDL_Event @event, IGameLoop gameLoop)
        {
            if ([email protected](SDL.SDL_EventType.SDL_KEYDOWN))
            {
                return;
            }

            if (@event.key.keysym.sym.Equals(SDL.SDL_Keycode.SDLK_ESCAPE))
            {
                Console.WriteLine("Escape pressed.");
                gameLoop.Stop();
            }

            float?simulationSpeed = @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_BACKQUOTE => 10.0f, SDL.SDL_Keycode.SDLK_1 => 1.0f, SDL.SDL_Keycode.SDLK_2 => 0.5f
                , SDL.SDL_Keycode.SDLK_3 => 0.25f, SDL.SDL_Keycode.SDLK_4 => 0.125f, SDL.SDL_Keycode.SDLK_5 => 0.01f
                , SDL.SDL_Keycode.SDLK_6 => 0.0f, _ => null
            };

            if (simulationSpeed.HasValue)
            {
                Console.WriteLine($"Set simulation speed to {simulationSpeed.Value}");
                gameLoop.SetSimulationSpeed(simulationSpeed.Value);
            }

            _cameraX += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_LEFT => 10, SDL.SDL_Keycode.SDLK_RIGHT => - 10, _ => 0
            };

            _cameraY += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_UP => 10, SDL.SDL_Keycode.SDLK_DOWN => - 10, _ => 0
            };

            _zoom += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_HOME => 0.25f, SDL.SDL_Keycode.SDLK_END => - 0.25f, _ => 0.0f
            };

            _zoom = Math.Max(_zoom, 0.25f);
        }