add interacton by long press
This commit is contained in:
parent
316de42cca
commit
ee8d0368bd
@ -37,7 +37,7 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr<Level> level)
|
|||||||
auto menu = engine->getGUI()->getMenu();
|
auto menu = engine->getGUI()->getMenu();
|
||||||
menu->reset();
|
menu->reset();
|
||||||
|
|
||||||
controller = std::make_unique<LevelController>(settings, std::move(level));
|
controller = std::make_unique<LevelController>(engine, std::move(level));
|
||||||
frontend = std::make_unique<LevelFrontend>(controller->getPlayer(), controller.get(), assets);
|
frontend = std::make_unique<LevelFrontend>(controller->getPlayer(), controller.get(), assets);
|
||||||
|
|
||||||
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
|
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
|
#include "engine.hpp"
|
||||||
#include "files/WorldFiles.hpp"
|
#include "files/WorldFiles.hpp"
|
||||||
#include "interfaces/Object.hpp"
|
#include "interfaces/Object.hpp"
|
||||||
#include "objects/Entities.hpp"
|
#include "objects/Entities.hpp"
|
||||||
@ -15,10 +16,8 @@
|
|||||||
|
|
||||||
static debug::Logger logger("level-control");
|
static debug::Logger logger("level-control");
|
||||||
|
|
||||||
LevelController::LevelController(
|
LevelController::LevelController(Engine* engine, std::unique_ptr<Level> level)
|
||||||
EngineSettings& settings, std::unique_ptr<Level> level
|
: settings(engine->getSettings()),
|
||||||
)
|
|
||||||
: settings(settings),
|
|
||||||
level(std::move(level)),
|
level(std::move(level)),
|
||||||
blocks(std::make_unique<BlocksController>(
|
blocks(std::make_unique<BlocksController>(
|
||||||
this->level.get(), settings.chunks.padding.get()
|
this->level.get(), settings.chunks.padding.get()
|
||||||
@ -27,7 +26,7 @@ LevelController::LevelController(
|
|||||||
this->level.get(), settings.chunks.padding.get()
|
this->level.get(), settings.chunks.padding.get()
|
||||||
)),
|
)),
|
||||||
player(std::make_unique<PlayerController>(
|
player(std::make_unique<PlayerController>(
|
||||||
this->level.get(), settings, blocks.get()
|
engine, this->level.get(), blocks.get()
|
||||||
)) {
|
)) {
|
||||||
scripting::on_world_load(this);
|
scripting::on_world_load(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "ChunksController.hpp"
|
#include "ChunksController.hpp"
|
||||||
#include "PlayerController.hpp"
|
#include "PlayerController.hpp"
|
||||||
|
|
||||||
|
class Engine;
|
||||||
class Level;
|
class Level;
|
||||||
class Player;
|
class Player;
|
||||||
struct EngineSettings;
|
struct EngineSettings;
|
||||||
@ -19,7 +20,7 @@ class LevelController {
|
|||||||
std::unique_ptr<ChunksController> chunks;
|
std::unique_ptr<ChunksController> chunks;
|
||||||
std::unique_ptr<PlayerController> player;
|
std::unique_ptr<PlayerController> player;
|
||||||
public:
|
public:
|
||||||
LevelController(EngineSettings& settings, std::unique_ptr<Level> level);
|
LevelController(Engine* engine, std::unique_ptr<Level> level);
|
||||||
|
|
||||||
/// @param delta time elapsed since the last update
|
/// @param delta time elapsed since the last update
|
||||||
/// @param input is user input allowed to be handled
|
/// @param input is user input allowed to be handled
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "core_defs.hpp"
|
#include "core_defs.hpp"
|
||||||
|
#include "engine.hpp"
|
||||||
#include "items/Inventory.hpp"
|
#include "items/Inventory.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "items/ItemStack.hpp"
|
#include "items/ItemStack.hpp"
|
||||||
@ -26,6 +27,7 @@
|
|||||||
#include "BlocksController.hpp"
|
#include "BlocksController.hpp"
|
||||||
#include "scripting/scripting.hpp"
|
#include "scripting/scripting.hpp"
|
||||||
|
|
||||||
|
const float INTERACTION_RELOAD = 0.160f;
|
||||||
const float STEPS_SPEED = 2.2f;
|
const float STEPS_SPEED = 2.2f;
|
||||||
const float CAM_SHAKE_OFFSET = 0.0075f;
|
const float CAM_SHAKE_OFFSET = 0.0075f;
|
||||||
const float CAM_SHAKE_OFFSET_Y = 0.031f;
|
const float CAM_SHAKE_OFFSET_Y = 0.031f;
|
||||||
@ -187,13 +189,12 @@ void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerController::PlayerController(
|
PlayerController::PlayerController(
|
||||||
Level* level,
|
Engine* const engine, Level* level,
|
||||||
const EngineSettings& settings,
|
|
||||||
BlocksController* blocksController
|
BlocksController* blocksController
|
||||||
)
|
)
|
||||||
: level(level),
|
: engine(engine), level(level),
|
||||||
player(level->getObject<Player>(0)),
|
player(level->getObject<Player>(0)),
|
||||||
camControl(player, settings.camera),
|
camControl(player, engine->getSettings().camera),
|
||||||
blocksController(blocksController) {
|
blocksController(blocksController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,12 +486,19 @@ void PlayerController::updateInteraction() {
|
|||||||
auto chunks = level->chunks.get();
|
auto chunks = level->chunks.get();
|
||||||
const auto& selection = player->selection;
|
const auto& selection = player->selection;
|
||||||
|
|
||||||
|
if (interactionTimer > 0.0f) {
|
||||||
|
interactionTimer -= static_cast<float>(engine->getDelta());
|
||||||
|
}
|
||||||
bool xkey = Events::pressed(keycode::X);
|
bool xkey = Events::pressed(keycode::X);
|
||||||
bool lclick = Events::jactive(BIND_PLAYER_ATTACK) ||
|
|
||||||
(xkey && Events::active(BIND_PLAYER_ATTACK));
|
|
||||||
bool rclick = Events::jactive(BIND_PLAYER_BUILD) ||
|
|
||||||
(xkey && Events::active(BIND_PLAYER_BUILD));
|
|
||||||
float maxDistance = xkey ? 200.0f : 10.0f;
|
float maxDistance = xkey ? 200.0f : 10.0f;
|
||||||
|
bool longInteraction = interactionTimer <= 0 || xkey;
|
||||||
|
bool lclick = Events::jactive(BIND_PLAYER_ATTACK) ||
|
||||||
|
(longInteraction && Events::active(BIND_PLAYER_ATTACK));
|
||||||
|
bool rclick = Events::jactive(BIND_PLAYER_BUILD) ||
|
||||||
|
(longInteraction && Events::active(BIND_PLAYER_BUILD));
|
||||||
|
if (lclick || rclick) {
|
||||||
|
interactionTimer = INTERACTION_RELOAD;
|
||||||
|
}
|
||||||
|
|
||||||
auto inventory = player->getInventory();
|
auto inventory = player->getInventory();
|
||||||
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
|
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "objects/Player.hpp"
|
#include "objects/Player.hpp"
|
||||||
|
|
||||||
|
class Engine;
|
||||||
class Camera;
|
class Camera;
|
||||||
class Level;
|
class Level;
|
||||||
class Block;
|
class Block;
|
||||||
@ -45,12 +46,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class PlayerController {
|
class PlayerController {
|
||||||
|
Engine* engine;
|
||||||
Level* level;
|
Level* level;
|
||||||
std::shared_ptr<Player> player;
|
std::shared_ptr<Player> player;
|
||||||
PlayerInput input {};
|
PlayerInput input {};
|
||||||
CameraControl camControl;
|
CameraControl camControl;
|
||||||
BlocksController* blocksController;
|
BlocksController* blocksController;
|
||||||
|
|
||||||
|
float interactionTimer = 0.0f;
|
||||||
void updateKeyboard();
|
void updateKeyboard();
|
||||||
void resetKeyboard();
|
void resetKeyboard();
|
||||||
void updatePlayer(float delta);
|
void updatePlayer(float delta);
|
||||||
@ -65,9 +68,7 @@ class PlayerController {
|
|||||||
voxel* updateSelection(float maxDistance);
|
voxel* updateSelection(float maxDistance);
|
||||||
public:
|
public:
|
||||||
PlayerController(
|
PlayerController(
|
||||||
Level* level,
|
Engine* const engine, Level* level, BlocksController* blocksController
|
||||||
const EngineSettings& settings,
|
|
||||||
BlocksController* blocksController
|
|
||||||
);
|
);
|
||||||
void update(float delta, bool input, bool pause);
|
void update(float delta, bool input, bool pause);
|
||||||
void postUpdate(float delta, bool input, bool pause);
|
void postUpdate(float delta, bool input, bool pause);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user