mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-31 17:33:20 +00:00
Handling buttons on key up
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
.idea
|
||||
cmake-build-debug
|
||||
cmake-build-release
|
||||
./bomberman
|
||||
.vscode
|
||||
build/*
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace BBM
|
||||
float speed = .15f;
|
||||
//! @brief The layout used for this controllable.
|
||||
Layout layout = NONE;
|
||||
//! @brief True if buttons should be triggered every frame where the key is down, false if the button should only be triggered once the key is released.
|
||||
bool fastClick = false;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace BBM
|
||||
engine.shouldClose = true;
|
||||
if (gameState.currentScene == GameState::SceneID::GameScene) {
|
||||
for (auto &[_, component]: engine.getScene()->view<ControllableComponent>()) {
|
||||
component.fastClick = true;
|
||||
if (component.pause && gameState.currentScene == GameState::SceneID::GameScene) {
|
||||
gameState.nextScene = GameState::SceneID::PauseMenuScene;
|
||||
break;
|
||||
@@ -72,8 +73,12 @@ namespace BBM
|
||||
}
|
||||
if (gameState.nextScene == gameState.currentScene)
|
||||
return;
|
||||
if (gameState.nextScene == GameState::SceneID::ScoreScene)
|
||||
if (gameState.nextScene == GameState::SceneID::ScoreScene) {
|
||||
gameState._loadedScenes[GameState::SceneID::ScoreScene] = Runner::loadScoreScene(*engine.getScene());
|
||||
for (auto &[_, component]: engine.getScene()->view<ControllableComponent>()) {
|
||||
component.fastClick = false;
|
||||
}
|
||||
}
|
||||
gameState._loadedScenes[gameState.currentScene] = engine.getScene();
|
||||
engine.changeScene(gameState._loadedScenes[gameState.nextScene]);
|
||||
gameState.currentScene = gameState.nextScene;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BBM
|
||||
};
|
||||
|
||||
for (auto key : keyPressedMap)
|
||||
key.second = gamepad.isDown(key.first);
|
||||
key.second = controllable.fastClick ? gamepad.isDown(key.first) : gamepad.isPressed(key.first);
|
||||
controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1;
|
||||
controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1;
|
||||
controllable.move.x -= static_cast<float>(gamepad.isDown(gamepadComponent.keyRight));
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BBM
|
||||
};
|
||||
|
||||
for (auto key : keyPressedMap)
|
||||
key.second = Keyboard::isDown(key.first);
|
||||
key.second = controllable.fastClick ? Keyboard::isDown(key.first) : Keyboard ::isPressed(key.first);
|
||||
controllable.move = Vector2f();
|
||||
if (Keyboard::isDown(keyboard.keyRight))
|
||||
controllable.move.x -= 1;
|
||||
|
||||
@@ -55,24 +55,24 @@ namespace BBM
|
||||
bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const
|
||||
{
|
||||
auto &positionComponent = entity.get<PositionComponent>();
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.get<Drawable2DComponent>().drawable.get());
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get());
|
||||
Vector2f buttonPos(positionComponent.getX(), positionComponent.getY());
|
||||
Vector2f dimensions;
|
||||
|
||||
if (texture) {
|
||||
if (auto *texture = dynamic_cast<RAY::Texture *>(entity.get<Drawable2DComponent>().drawable.get())) {
|
||||
dimensions.x = texture->getDimensions().x;
|
||||
dimensions.y = texture->getDimensions().y;
|
||||
} else if (text) {
|
||||
}
|
||||
else if (auto *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get())) {
|
||||
dimensions.y = text->getFontSize();
|
||||
dimensions.x = text->getString().size() * (text->getFontSize());
|
||||
} else
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return ((buttonPos.x <= mousePos.x && mousePos.x <= buttonPos.x + dimensions.x)
|
||||
&& (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y));
|
||||
&& (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y));
|
||||
}
|
||||
|
||||
void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime)
|
||||
void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds)
|
||||
{
|
||||
RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition();
|
||||
RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions();
|
||||
|
||||
Reference in New Issue
Block a user