Ejemplo n.º 1
0
        public async Task DisposeAsync()
        {
            await gameLoop.Stop();

            await Keyboard.DisposeAsync();

            if (Mouse != null)
            {
                await Mouse.DisposeAsync();
            }

            gameLoop.OnUpdate   -= OnUpdate;
            Keyboard.KeyPressed -= OnKeyPressed;
            if (Mouse != null)
            {
                Mouse.MousePressed -= OnMousePressed;
            }

            var loopingSounds = Sounds.Values.Where(sound => sound.Looping);

            foreach (var sound in loopingSounds)
            {
                await sound.Stop();
            }

            Instance = null;
        }
Ejemplo n.º 2
0
 public void PollEvents(IGameLoop gameLoop)
 {
     while (SDL.SDL_PollEvent(out var @event) != 0)
     {
         OnEvent(@event, gameLoop);
         if (@event.type == SDL.SDL_EventType.SDL_QUIT)
         {
             gameLoop.Stop();
         }
     }
 }
Ejemplo n.º 3
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);
        }