summary refs log tree commit diff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp33
1 files changed, 8 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 815de28..9dd42c9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,6 +12,7 @@
 #include "GFX/Image/PPMParser.hpp"
 #include "World/Clouds.hpp"
 #include "World/World.hpp"
+#include "Entities/Player.hpp"
 
 #define APP_NAME "Meowcraft"
 
@@ -23,7 +24,6 @@
 
 void run();
 void render(MC::GFX::Mesh&, MC::GFX::Texture&);
-void process_input(MC::GFX::Window&, MC::GFX::Camera&, MC::Time&);
 void setup_gl();
 void fix_macos_render(const MC::GFX::Window&);
 
@@ -57,7 +57,6 @@ void run() {
     MC::World::World world;
 
     MC::GFX::Camera camera{};
-    camera.set_position({0, MC::World::Chunk::Height / 2.0, 0});
 
     MC::GFX::Shading::Program program(
         MC::GFX::Shading::Shader::create_vertex(),
@@ -83,6 +82,8 @@ void run() {
 
     MC::World::Clouds clouds{ASPECT, FOV, 0.1f, 1000.0f, sky_color, sun_direction};
 
+    MC::Entities::Player player{{0, MC::World::Chunk::Height / 2.0, 0}};
+
     glEnable(GL_DEPTH_TEST);
     glDepthFunc(GL_LEQUAL);
 
@@ -103,7 +104,11 @@ void run() {
         fix_macos_render(window);
 #endif
 
-        process_input(window, camera, time);
+        if (window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) {
+            window.close();
+        }
+
+        player.update(time, window, camera, world);
         clouds.update(time);
 
         glClearColor(sky_color.x(), sky_color.y(), sky_color.z(), 1.0f); // #DBDBDB
@@ -142,28 +147,6 @@ void render(MC::GFX::Mesh& mesh, MC::GFX::Texture& texture) {
     texture.unbind();
 }
 
-void process_input(MC::GFX::Window& window, MC::GFX::Camera& camera, MC::Time& time) {
-    if (window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) {
-        window.close();
-    }
-
-    auto r = window.mouse_delta();
-
-    auto key = [&](Int k) -> Real { return window.key(k, GLFW_PRESS); };
-
-    Real x = key(GLFW_KEY_D) - key(GLFW_KEY_A);
-    Real y = key(GLFW_KEY_SPACE) - key(GLFW_KEY_LEFT_SHIFT);
-    Real z = key(GLFW_KEY_S) - key(GLFW_KEY_W);
-    Real boost = key(GLFW_KEY_LEFT_CONTROL) * 75.0f;
-
-    auto move_speed = (20.0f + boost) * time.delta();
-    auto rotation_speed = 5.0f * time.delta();
-
-    camera.move_relative({x * move_speed, 0.0f, z * move_speed});
-    camera.move({0.0f, y * move_speed, 0.0f});
-    camera.rotate({r.y() * rotation_speed, r.x() * rotation_speed, 0.0f});
-}
-
 void setup_gl() {
     GLenum error;
     if ((error = glewInit()) != GLEW_OK) {