private void MoveFigures() { _trapeze.Rotate(RotateDirection.Right); _ellipse.Rotate(RotateDirection.Left); if (!_trapeze.Move(_trapezeMoveDirection)) { _trapezeMoveDirection = _trapezeMoveDirection == MoveDirection.Left ? MoveDirection.Right : MoveDirection.Left; } if (!_ellipse.Move(_ellipseMoveDirection)) { _ellipseMoveDirection = _ellipseMoveDirection == MoveDirection.Left ? MoveDirection.Right : MoveDirection.Left; } }
private void WindowProcedure() { bool exit = false; while (!exit) { SDL.SDL_Event sdlEvent; SDL.SDL_PollEvent(out sdlEvent); switch (sdlEvent.type) { case SDL.SDL_EventType.SDL_QUIT: { exit = true; break; } case SDL.SDL_EventType.SDL_WINDOWEVENT: { switch (sdlEvent.window.windowEvent) { case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: lock (_workWithFigures) { WindowSizeChanged(); } break; } break; } case SDL.SDL_EventType.SDL_KEYDOWN: { var key = sdlEvent.key; if (!_isTimerWork) { switch (key.keysym.sym) { case SDL.SDL_Keycode.SDLK_w: _currentFigure.Move(MoveDirection.Up); break; case SDL.SDL_Keycode.SDLK_a: _currentFigure.Move(MoveDirection.Left); break; case SDL.SDL_Keycode.SDLK_s: _currentFigure.Move(MoveDirection.Down); break; case SDL.SDL_Keycode.SDLK_d: _currentFigure.Move(MoveDirection.Right); break; case SDL.SDL_Keycode.SDLK_q: _currentFigure.Rotate(RotateDirection.Left); break; case SDL.SDL_Keycode.SDLK_e: _currentFigure.Rotate(RotateDirection.Right); break; } } switch (key.keysym.sym) { case SDL.SDL_Keycode.SDLK_SPACE: ChangeTimerState(); break; case SDL.SDL_Keycode.SDLK_1: _currentFigure = _trapeze; break; case SDL.SDL_Keycode.SDLK_2: _currentFigure = _ellipse; break; case SDL.SDL_Keycode.SDLK_F1: _rectabgleDrawer = DrawerFactory.SquareDrawer; _trapezeDrawer = DrawerFactory.SquareDrawer; _ellipseDrawer = DrawerFactory.RoundDrawer; break; case SDL.SDL_Keycode.SDLK_F2: _rectabgleDrawer = DrawerFactory.UniversalDrawer; _trapezeDrawer = DrawerFactory.UniversalDrawer; _ellipseDrawer = DrawerFactory.UniversalDrawer; break; } break; } case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: { if (sdlEvent.button.button == SDL.SDL_BUTTON_LEFT) { lock (_workWithFigures) { _currentFigure.MoveTo(sdlEvent.button.x, sdlEvent.button.y); } } break; } } _trapeze.CalculateCurrentEdges(); _ellipse.CalculateCurrentEdges(); PerformClipping(); DrawFigures(); Thread.Sleep(_renderLoopTimeoutMs); } }