TODOFix: Un-hardcode the flying keybind

master
Nicole Collings 2020-02-01 16:09:50 -08:00
parent 06bbb0ca5f
commit 99d26ed71f
7 changed files with 56 additions and 32 deletions

View File

@ -3,7 +3,6 @@
//
#include "Player.h"
#include "../../../util/Ray.h"
Player::Player(LocalWorld& world, LocalDefs& defs, Renderer& renderer) :
Collidable(world, defs, {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}}),
@ -32,8 +31,6 @@ void Player::update(Input &input, double delta, glm::vec2 mouseDelta) {
gameGui.winResized(win);
});
if (input.isKeyPressed(GLFW_KEY_F)) flying = !flying; //TODO: Move to Lua Bind
moveAndLook(input, delta, mouseDelta);
findPointedThing(input);
updateWireframe();
@ -244,19 +241,22 @@ float Player::getPitch() {
return pitch;
}
Inventory &Player::getInventory() {
return inventory;
void Player::setFlying(bool flying) {
this->flying = flying;
}
/*
* Pointed Thing
*/
bool Player::isFlying() {
return flying;
}
PointedThing& Player::getPointedThing() {
return pointedThing;
}
Inventory &Player::getInventory() {
return inventory;
}
/*
* GUI Functions
*/

View File

@ -8,15 +8,16 @@
#include <iostream>
#include "LocalWorld.h"
#include "Inventory.h"
#include "../../hud/GameGui.h"
#include "../../graph/Camera.h"
#include "../../../util/Timer.h"
#include "../../graph/drawable/DrawableGroup.h"
#include "../../entity/Collidable.h"
#include "../../entity/world/WireframeEntity.h"
#include "../../entity/world/BlockCrackEntity.h"
#include "../../graph/drawable/DrawableGroup.h"
#include "../../../util/Ray.h"
#include "../../../util/Timer.h"
#include "../../../world/block/PointedThing.h"
#include "../../hud/GameGui.h"
#include "../../entity/Collidable.h"
#include "Inventory.h"
class Player : Collidable, public Drawable {
public:
@ -30,14 +31,8 @@ public:
static constexpr float BLOCK_INTERVAL = 0.02f;
Player(LocalWorld& world, LocalDefs& defs, Renderer& renderer);
void update(Input &input, double delta, glm::vec2 mouseDelta);
void moveAndLook(Input &input, double delta, glm::vec2 mouseDelta);
void updateCamera();
void findPointedThing(Input &input);
void updateWireframe();
void breakBlock(Input& input, double delta);
~Player();
void setPos(glm::vec3 pos);
glm::vec3 getPos();
@ -47,9 +42,13 @@ public:
void setYaw(float yaw);
float getYaw();
void setPitch(float pitch);
float getPitch();
void setFlying(bool flying);
bool isFlying();
void setActiveBlock(const std::string& block);
void setMenu(const std::string& menu, const std::map<std::string, GuiBuilder::ComponentCallbacks>& callbacks);
@ -58,14 +57,18 @@ public:
void setGuiVisible(bool hudVisible);
void draw(Renderer& renderer) override;
void drawViginette(Renderer& renderer);
void drawGUI(Renderer& renderer);
void drawViginette(Renderer& renderer);
Inventory& getInventory();
PointedThing& getPointedThing();
~Player();
private:
void moveAndLook(Input &input, double delta, glm::vec2 mouseDelta);
void updateCamera();
void findPointedThing(Input &input);
void updateWireframe();
void breakBlock(Input& input, double delta);
Renderer& renderer;
LocalDefs& defs;
@ -73,9 +76,9 @@ private:
Inventory inventory;
GameGui gameGui;
bool flying = false;
float yaw = 0;
float pitch = 0;
bool flying = false;
unsigned int activeBlock = -1;

View File

@ -89,3 +89,11 @@ LuaInventory LocalLuaPlayer::get_inventory() {
void LocalLuaPlayer::set_selected_block(std::string block) {
player.setActiveBlock(block);
}
void LocalLuaPlayer::set_flying(bool shouldFly) {
player.setFlying(shouldFly);
}
bool LocalLuaPlayer::get_flying() {
return player.isFlying();
}

View File

@ -29,10 +29,13 @@ public:
float get_look_pitch();
std::string get_menu_state();
void open_menu(sol::this_state s, std::string menu, sol::optional<sol::table> callbacks);
void close_menu();
void open_menu(sol::this_state s, std::string menu, sol::optional<sol::table> callbacks);
LuaInventory get_inventory();
void set_selected_block(std::string block);
void set_flying(bool shouldFly);
bool get_flying();
};

View File

@ -22,18 +22,21 @@ namespace ClientApi {
"set_look_pitch", &LocalLuaPlayer::set_look_pitch,
"get_look_pitch", &LocalLuaPlayer::get_look_pitch,
"get_inventory", &LocalLuaPlayer::get_inventory,
"set_selected_block", &LocalLuaPlayer::set_selected_block,
"open_menu", &LocalLuaPlayer::open_menu,
"close_menu", &LocalLuaPlayer::close_menu,
"pos", sol::property(&LocalLuaPlayer::get_pos, &LocalLuaPlayer::set_pos),
"block_pos", sol::property(&LocalLuaPlayer::get_block_pos, &LocalLuaPlayer::set_pos),
"vel", sol::property(&LocalLuaPlayer::get_vel, &LocalLuaPlayer::set_vel),
"look_yaw", sol::property(&LocalLuaPlayer::get_look_yaw, &LocalLuaPlayer::set_look_yaw),
"look_yaw", sol::property(&LocalLuaPlayer::get_look_pitch, &LocalLuaPlayer::set_look_pitch),
"menu_state", sol::property(&LocalLuaPlayer::get_menu_state),
"open_menu", &LocalLuaPlayer::open_menu,
"close_menu", &LocalLuaPlayer::close_menu,
"flying", sol::property(&LocalLuaPlayer::set_flying, &LocalLuaPlayer::get_flying),
"get_inventory", &LocalLuaPlayer::get_inventory,
"set_selected_block", &LocalLuaPlayer::set_selected_block
"menu_state", sol::property(&LocalLuaPlayer::get_menu_state)
);
}
}

View File

@ -69,7 +69,7 @@ void LocalLuaParser::loadModules(LocalDefs &defs, LocalWorld &world, Player& pla
core["player"] = LocalLuaPlayer(player);
//Load Modules
Api::delay(core, delayed_functions);
Api::delay (core, delayed_functions);
Api::register_block (lua, core);
Api::register_blockmodel (lua, core);

View File

@ -6,5 +6,12 @@ runfile(_PATH .. "dump")
runfile(_PATH .. "math")
runfile(_PATH .. "vector")
-- Set flying toggle
zepha.register_keybind("base:toggle_flying", {
description = "Toggle Flying",
default = zepha.keys.f,
on_press = function() zepha.player.flying = not zepha.player.flying end
})
-- Signal completion
print("Base definitions loaded.")