#include "client/Player.h" #include "client/Chat.h" #include "client/Controls.h" #include "client/Main.h" #include "client/World.h" #include "math/View.h" static BufferedValue position = Vector3(8.0f, 30.0f, 8.0f); static BufferedValue widthAngle = 0.0f; static BufferedValue lengthAngle = 0.0f; static Vector3 velocity; static Vector3 acceleration; static bool onGround = false; static View view; static void tickInput() { Vector3 back = view.getBack(); back[1] = 0.0f; back.normalize(); Vector3 right = view.getRight(); right[1] = 0.0f; right.normalize(); Vector3 force; if(Controls::isDown(Controls::down)) { force += back; } if(Controls::isDown(Controls::up)) { force -= back; } if(Controls::isDown(Controls::left)) { force -= right; } if(Controls::isDown(Controls::right)) { force += right; } if(force.squareLength() > 0.0f) { force.normalize(); } acceleration += force * 0.1f; if(Controls::isDown(Controls::jump) && onGround) { acceleration[1] += (0.42f / 0.98f + 0.08f); } if(Window::isCursorTrapped()) { Vector2 diff = (Window::Controls::getLastMousePosition() - Window::Controls::getMousePosition()) * 0.1f; widthAngle += diff[1]; lengthAngle += diff[0]; if(widthAngle > 89.0f) { widthAngle = 89.0f; } if(widthAngle < -89.0f) { widthAngle = -89.0f; } } } void Player::tick() { position.update(); widthAngle.update(); lengthAngle.update(); view.updateDirections(lengthAngle, widthAngle); if(!Chat::isActive()) { tickInput(); } velocity += acceleration; velocity *= Vector3(0.686f, 0.98f, 0.686f); acceleration = Vector3(0.0f, -0.08f, 0.0f); Box box(Vector3(0.8f, 0.8f, 0.8f)); box = box.offset(position - Vector3(0.4f, 0.0f, 0.4f)); Vector3 move = World::limitMove(box, velocity); if(move[1] + position[1] < 0.0f) { move[1] = -position[1]; } position += move; onGround = move[1] == 0.0f && velocity[1] < 0.0f; velocity = move; } Vector3 Player::getPosition(float lag) { return position.get(lag); } float Player::getLengthAngle(float lag) { return lengthAngle.get(lag); } float Player::getWidthAngle(float lag) { return widthAngle.get(lag); } Vector3 Player::getLook(float lag) { view.updateDirections(lengthAngle.get(lag), widthAngle.get(lag)); return view.getFront(); }