summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entity.hpp1
-rw-r--r--src/GameState.cpp9
-rw-r--r--src/Render.cpp7
-rw-r--r--src/Render.hpp1
-rw-r--r--src/World.cpp17
5 files changed, 32 insertions, 3 deletions
diff --git a/src/Entity.hpp b/src/Entity.hpp
index cc9f6fa..2b1a041 100644
--- a/src/Entity.hpp
+++ b/src/Entity.hpp
@@ -142,6 +142,7 @@ struct Entity {
double terminalVelocity = 78.4;
bool onGround = true;
VectorF EyeOffset = VectorF(0,1.62,0);
+ bool isFlying = false;
static VectorF DecodeVelocity(short x, short y, short z);
static VectorF DecodeDeltaPos(short deltaX, short deltaY, short deltaZ);
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 6c2ad42..c42092a 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -484,7 +484,7 @@ void GameState::HandleMovement(GameState::Direction direction, float deltaTime)
glm::vec3 front, right, worldUp, up;
worldUp = glm::vec3(0.0f, 1.0f, 0.0f);
front.x = cos(glm::radians(playerYaw)) * cos(glm::radians(playerPitch));
- front.y = 0;
+ front.y = player->isFlying ? sin(glm::radians(playerPitch)): 0;
front.z = sin(glm::radians(playerYaw)) * cos(glm::radians(playerPitch));
front = glm::normalize(front);
right = glm::normalize(glm::cross(front, worldUp));
@@ -513,10 +513,13 @@ void GameState::HandleMovement(GameState::Direction direction, float deltaTime)
}
case JUMP:
- if (player->onGround) {
+ if (player->onGround && !player->isFlying) {
vel.y += 10;
player->onGround = false;
- }
+ } else
+ if (player->isFlying) {
+ vel += up * velocity;
+ }
break;
}
player->vel = VectorF(vel.x, vel.y, vel.z);
diff --git a/src/Render.cpp b/src/Render.cpp
index ae9814d..ea3252c 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -39,6 +39,7 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight,
fieldSensetivity = Settings::ReadDouble("mouseSensetivity", 0.1);
fieldVsync = Settings::ReadBool("vsync", false);
fieldWireframe = Settings::ReadBool("wireframe", false);
+ fieldFlight = Settings::ReadBool("flight", false);
//Apply settings
if (fieldSensetivity != sensetivity)
@@ -64,6 +65,7 @@ Render::~Render() {
Settings::WriteDouble("mouseSensetivity", fieldSensetivity);
Settings::WriteBool("vsync", fieldVsync);
Settings::WriteBool("wireframe", fieldWireframe);
+ Settings::WriteBool("flight", fieldFlight);
Settings::Save();
ImGui_ImplSdlGL3_Shutdown();
@@ -567,6 +569,8 @@ void Render::RenderGui() {
ImGui::Checkbox("VSync", &fieldVsync);
+ ImGui::Checkbox("Creative flight", &fieldFlight);
+
if (ImGui::Button("Apply settings")) {
if (fieldDistance != world->MaxRenderingDistance) {
world->MaxRenderingDistance = fieldDistance;
@@ -576,6 +580,8 @@ void Render::RenderGui() {
if (fieldSensetivity != sensetivity)
sensetivity = fieldSensetivity;
+ world->GameStatePtr()->player->isFlying = fieldFlight;
+
isWireframe = fieldWireframe;
timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / fieldTargetFps * 1000.0));
if (fieldVsync) {
@@ -625,6 +631,7 @@ void Render::InitEvents() {
renderWorld = true;
GlobalState::SetState(State::Playing);
glClearColor(0, 0, 0, 1.0f);
+ world->GameStatePtr()->player->isFlying = this->fieldFlight;
});
listener.RegisterHandler("ConnectionFailed", [this](const Event& eventData) {
diff --git a/src/Render.hpp b/src/Render.hpp
index b0058b7..272e14f 100644
--- a/src/Render.hpp
+++ b/src/Render.hpp
@@ -40,6 +40,7 @@ class Render {
float fieldTargetFps;
bool fieldWireframe;
bool fieldVsync;
+ bool fieldFlight;
void SetMouseCapture(bool IsCaptured);
diff --git a/src/World.cpp b/src/World.cpp
index 718f54c..251890b 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -201,6 +201,23 @@ void World::UpdatePhysics(float delta) {
entitiesMutex.lock();
for (auto& it : entities) {
+ if (it.isFlying) {
+ VectorF newPos = it.pos + VectorF(it.vel.x, it.vel.y, it.vel.z) * delta;
+ auto coll = testCollision(it.width, it.height, newPos);
+ if (coll.isCollide) {
+ it.vel = VectorF(0, 0, 0);
+ }
+ else {
+ it.pos = newPos;
+ }
+
+ const float AirResistance = 10.0f;
+ VectorF resistForce = it.vel * AirResistance * delta * -1.0;
+ it.vel = it.vel + resistForce;
+
+ continue;
+ }
+
{ //Vertical velocity
it.vel.y -= it.gravity * delta;
VectorF newPos = it.pos + VectorF(0, it.vel.y, 0) * delta;