Game.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "client/Game.h"
  2. #include "client/utils/Utils.h"
  3. #include "rendering/Renderer.h"
  4. Game::Game(const Control& control, const Camera& camera, Ray& ray, const Clock& fps, const Clock& tps,
  5. RenderSettings& renderSettings) :
  6. control(control), camera(camera), ray(ray), fps(fps), tps(tps), renderSettings(renderSettings), lengthAngle(20.0f),
  7. widthAngle(35.0f), world(blockRegistry), worldRenderer(world) {
  8. pos.set(0, 10, 0);
  9. }
  10. void Game::tick() {
  11. const float speed = 0.25f;
  12. if(control.keys.down.isDown()) {
  13. pos.addMul(camera.getFlatBack(), speed);
  14. }
  15. if(control.keys.up.isDown()) {
  16. pos.addMul(camera.getFlatBack(), -speed);
  17. }
  18. if(control.keys.left.isDown()) {
  19. pos.addMul(camera.getFlatRight(), -speed);
  20. }
  21. if(control.keys.right.isDown()) {
  22. pos.addMul(camera.getFlatRight(), speed);
  23. }
  24. if(control.keys.jump.isDown()) {
  25. pos.addMul(camera.getFlatUp(), speed);
  26. }
  27. if(control.keys.sneak.isDown()) {
  28. pos.addMul(camera.getFlatUp(), -speed);
  29. }
  30. const float rotation = 5.0f;
  31. if(control.keys.camLeft.isDown()) {
  32. lengthAngle += rotation;
  33. }
  34. if(control.keys.camRight.isDown()) {
  35. lengthAngle -= rotation;
  36. }
  37. if(control.keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
  38. widthAngle -= rotation;
  39. }
  40. if(control.keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
  41. widthAngle += rotation;
  42. }
  43. ray.store();
  44. ray.set(pos, lengthAngle, widthAngle);
  45. if(control.keys.test5.getDownTime() == 1) {
  46. renderSettings.shadows = !renderSettings.shadows;
  47. }
  48. /*if(control.keys.test.isDown()) {
  49. renderSettings.testRadius /= 0.95f;
  50. }
  51. if(control.keys.test2.isDown()) {
  52. renderSettings.testRadius *= 0.95f;
  53. }
  54. if(control.keys.test3.isDown()) {
  55. renderSettings.testBias /= 0.95f;
  56. }
  57. if(control.keys.test4.isDown()) {
  58. renderSettings.testBias *= 0.95f;
  59. }*/
  60. }
  61. void Game::renderWorld(float lag, Renderer& renderer) const {
  62. worldRenderer.render(lag, renderer);
  63. }
  64. void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) const {
  65. (void) lag;
  66. renderer.scale(1.0f).update();
  67. char buffer[50];
  68. snprintf(buffer, 50, "FPS: %.2f", fps.getUpdatesPerSecond());
  69. fr.drawString(10, 10, buffer);
  70. snprintf(buffer, 50, "TPS: %.2f", tps.getUpdatesPerSecond());
  71. fr.drawString(10, 20, buffer);
  72. snprintf(buffer, 50, "Bias: %.6f", renderSettings.testBias);
  73. fr.drawString(10, 30, buffer);
  74. snprintf(buffer, 50, "Radius: %.6f", renderSettings.testRadius);
  75. fr.drawString(10, 40, buffer);
  76. snprintf(buffer, 50, "Shadows: %d", renderSettings.shadows);
  77. fr.drawString(10, 50, buffer);
  78. }
  79. bool Game::isRunning() const {
  80. return true;
  81. }