|
@@ -3,6 +3,7 @@
|
|
|
#include "client/gui/StartGUI.h"
|
|
|
#include "client/rendering/Engine.h"
|
|
|
#include "common/network/Packets.h"
|
|
|
+#include "common/network/toserver/ControllerPacket.h"
|
|
|
#include "rendering/renderer/WorldRenderer.h"
|
|
|
#include "utils/Logger.h"
|
|
|
#include "utils/Utils.h"
|
|
@@ -11,7 +12,7 @@ BlockRegistry Game::blockRegistry;
|
|
|
World Game::world{blockRegistry};
|
|
|
static WorldRenderer worldRenderer{Game::world};
|
|
|
Controller Game::controller;
|
|
|
-Player Game::player;
|
|
|
+Entity Game::player;
|
|
|
|
|
|
typedef void (*State)();
|
|
|
static State tickState;
|
|
@@ -21,8 +22,63 @@ static BaseGUI baseGUI;
|
|
|
static StartGUI startGUI;
|
|
|
|
|
|
static void tickConnectedState() {
|
|
|
- GameClient::consumeEvents();
|
|
|
+ Game::player.skip = false;
|
|
|
Game::world.tick();
|
|
|
+ GameClient::consumeEvents();
|
|
|
+
|
|
|
+ Quaternion q = Game::player.getRotation();
|
|
|
+
|
|
|
+ Vector3 up(0.0f, 1.0f, 0.0f);
|
|
|
+ Vector3 back = q * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
+ back[1] = 0.0f;
|
|
|
+ back.normalize();
|
|
|
+ Vector3 right = back.cross(up);
|
|
|
+
|
|
|
+ constexpr float speed = 0.1f;
|
|
|
+ constexpr float rotationSpeed = 4.0f;
|
|
|
+ ControllerPacket cp;
|
|
|
+ if(Game::controller.down.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::DOWN);
|
|
|
+ Game::player.addForce(back * speed);
|
|
|
+ }
|
|
|
+ if(Game::controller.up.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::UP);
|
|
|
+ Game::player.addForce(back * -speed);
|
|
|
+ }
|
|
|
+ if(Game::controller.left.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::LEFT);
|
|
|
+ Game::player.addForce(right * -speed);
|
|
|
+ }
|
|
|
+ if(Game::controller.right.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::RIGHT);
|
|
|
+ Game::player.addForce(right * speed);
|
|
|
+ }
|
|
|
+ if(Game::controller.jump.isDown() && Game::player.isOnGround()) {
|
|
|
+ cp.set(ControllerPacket::Type::JUMP);
|
|
|
+ Game::player.addForce(up * 0.5f);
|
|
|
+ }
|
|
|
+ if(Game::controller.sneak.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::SNEAK);
|
|
|
+ }
|
|
|
+ if(Game::controller.camLeft.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::CAM_LEFT);
|
|
|
+ Game::player.addLengthAngle(-rotationSpeed);
|
|
|
+ }
|
|
|
+ if(Game::controller.camRight.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::CAM_RIGHT);
|
|
|
+ Game::player.addLengthAngle(rotationSpeed);
|
|
|
+ }
|
|
|
+ if(Game::controller.camUp.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::CAM_UP);
|
|
|
+ Game::player.addWidthAngle(-rotationSpeed * 0.5f);
|
|
|
+ }
|
|
|
+ if(Game::controller.camDown.isDown()) {
|
|
|
+ cp.set(ControllerPacket::Type::CAM_DOWN);
|
|
|
+ Game::player.addWidthAngle(rotationSpeed * 0.5f);
|
|
|
+ }
|
|
|
+ OutPacket out = OutPacket::reliable(ControllerPacket::getSize());
|
|
|
+ cp.write(out);
|
|
|
+ GameClient::send(out);
|
|
|
}
|
|
|
|
|
|
static void renderConnectedState() {
|
|
@@ -55,55 +111,12 @@ bool Game::init() {
|
|
|
tickState = tickConnectState;
|
|
|
renderState = renderConnectState;
|
|
|
|
|
|
- player.setPosition(Vector3(0.0f, 30.0f, 0.0f));
|
|
|
- world.addPlayer(&player);
|
|
|
+ world.addEntity(&player);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
|
tickState();
|
|
|
-
|
|
|
- Quaternion q = player.getRotation();
|
|
|
-
|
|
|
- Vector3 up(0.0f, 1.0f, 0.0f);
|
|
|
- Vector3 back = q * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
- back[1] = 0.0f;
|
|
|
- back.normalize();
|
|
|
- Vector3 right = back.cross(up);
|
|
|
-
|
|
|
- constexpr float speed = 0.1f;
|
|
|
- if(controller.down.isDown()) {
|
|
|
- player.addForce(back * speed);
|
|
|
- }
|
|
|
- if(controller.up.isDown()) {
|
|
|
- player.addForce(back * -speed);
|
|
|
- }
|
|
|
- if(controller.left.isDown()) {
|
|
|
- player.addForce(right * -speed);
|
|
|
- }
|
|
|
- if(controller.right.isDown()) {
|
|
|
- player.addForce(right * speed);
|
|
|
- }
|
|
|
- if(controller.jump.isDown() && player.isOnGround()) {
|
|
|
- player.addForce(up * 0.5f);
|
|
|
- }
|
|
|
- if(controller.sneak.isDown()) {
|
|
|
- player.addForce(up * -speed);
|
|
|
- }
|
|
|
-
|
|
|
- constexpr float rotationSpeed = 4.0f;
|
|
|
- if(controller.camLeft.isDown()) {
|
|
|
- player.addLengthAngle(-rotationSpeed);
|
|
|
- }
|
|
|
- if(controller.camRight.isDown()) {
|
|
|
- player.addLengthAngle(rotationSpeed);
|
|
|
- }
|
|
|
- if(controller.camUp.isDown()) {
|
|
|
- player.addWidthAngle(-rotationSpeed * 0.5f);
|
|
|
- }
|
|
|
- if(controller.camDown.isDown()) {
|
|
|
- player.addWidthAngle(rotationSpeed * 0.5f);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
void Game::renderWorld() {
|
|
@@ -121,4 +134,16 @@ void Game::renderOverlay() {
|
|
|
.append(" &999TPS: &722")
|
|
|
.append(Engine::getTickClock().getUpdatesPerSecond());
|
|
|
Engine::renderer.renderString(Vector2(10.0f, 10.0f), s);
|
|
|
+}
|
|
|
+
|
|
|
+void Game::onEntityUpdate(EntityUpdatePacket& p) {
|
|
|
+ float distance = (p.position - player.position).squareLength();
|
|
|
+ StringBuffer<50>(distance).printLine();
|
|
|
+ if(distance > 25.0f) {
|
|
|
+ std::cout << "set\n";
|
|
|
+ player.setPosition(p.position);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|