123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "client/Game.h"
- #include "client/utils/Utils.h"
- #include "rendering/Renderer.h"
- Game::Game(const Control& control, const Camera& camera, Ray& ray, const Clock& fps, const Clock& tps,
- RenderSettings& renderSettings) :
- control(control), camera(camera), ray(ray), fps(fps), tps(tps), renderSettings(renderSettings), lengthAngle(20.0f),
- widthAngle(35.0f), world(blockRegistry), worldRenderer(world) {
- pos.set(0, 10, 0);
- }
- void Game::tick() {
- const float speed = 0.25f;
- if(control.keys.down.isDown()) {
- pos.addMul(camera.getFlatBack(), speed);
- }
- if(control.keys.up.isDown()) {
- pos.addMul(camera.getFlatBack(), -speed);
- }
- if(control.keys.left.isDown()) {
- pos.addMul(camera.getFlatRight(), -speed);
- }
- if(control.keys.right.isDown()) {
- pos.addMul(camera.getFlatRight(), speed);
- }
- if(control.keys.jump.isDown()) {
- pos.addMul(camera.getFlatUp(), speed);
- }
- if(control.keys.sneak.isDown()) {
- pos.addMul(camera.getFlatUp(), -speed);
- }
- const float rotation = 5.0f;
- if(control.keys.camLeft.isDown()) {
- lengthAngle += rotation;
- }
- if(control.keys.camRight.isDown()) {
- lengthAngle -= rotation;
- }
- if(control.keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
- widthAngle -= rotation;
- }
- if(control.keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
- widthAngle += rotation;
- }
- ray.store();
- ray.set(pos, lengthAngle, widthAngle);
- if(control.keys.test5.getDownTime() == 1) {
- renderSettings.shadows = !renderSettings.shadows;
- }
- /*if(control.keys.test.isDown()) {
- renderSettings.testRadius /= 0.95f;
- }
- if(control.keys.test2.isDown()) {
- renderSettings.testRadius *= 0.95f;
- }
- if(control.keys.test3.isDown()) {
- renderSettings.testBias /= 0.95f;
- }
- if(control.keys.test4.isDown()) {
- renderSettings.testBias *= 0.95f;
- }*/
- }
- void Game::renderWorld(float lag, Renderer& renderer) const {
- worldRenderer.render(lag, renderer);
- }
- void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) const {
- (void) lag;
- renderer.scale(1.0f).update();
- char buffer[50];
- snprintf(buffer, 50, "FPS: %.2f", fps.getUpdatesPerSecond());
- fr.drawString(10, 10, buffer);
- snprintf(buffer, 50, "TPS: %.2f", tps.getUpdatesPerSecond());
- fr.drawString(10, 20, buffer);
- snprintf(buffer, 50, "Bias: %.6f", renderSettings.testBias);
- fr.drawString(10, 30, buffer);
- snprintf(buffer, 50, "Radius: %.6f", renderSettings.testRadius);
- fr.drawString(10, 40, buffer);
- snprintf(buffer, 50, "Shadows: %d", renderSettings.shadows);
- fr.drawString(10, 50, buffer);
- }
- bool Game::isRunning() const {
- return true;
- }
|