InputAction → enum class Input::Action
This commit is contained in:
@@ -95,27 +95,27 @@ void Player::init() {
|
||||
}
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(Uint8 input) {
|
||||
void Player::setInput(Input::Action input) {
|
||||
switch (input) {
|
||||
case LEFT:
|
||||
case Input::Action::LEFT:
|
||||
vel_x_ = -base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_LEFT);
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
case Input::Action::RIGHT:
|
||||
vel_x_ = base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_RIGHT);
|
||||
break;
|
||||
|
||||
case FIRE_CENTER:
|
||||
case Input::Action::FIRE_CENTER:
|
||||
setFiringStatus(STATUS_FIRING_UP);
|
||||
break;
|
||||
|
||||
case FIRE_LEFT:
|
||||
case Input::Action::FIRE_LEFT:
|
||||
setFiringStatus(STATUS_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case FIRE_RIGHT:
|
||||
case Input::Action::FIRE_RIGHT:
|
||||
setFiringStatus(STATUS_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
#include "core/input/input.h" // for Input::Action
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
@@ -26,7 +27,7 @@ class Player {
|
||||
void move(); // Mueve el jugador a la posición y animación que le corresponde
|
||||
|
||||
void setPlayerTextures(const std::vector<Texture *> &texture); // Pone las texturas del jugador
|
||||
void setInput(Uint8 input); // Actua en consecuencia de la entrada recibida
|
||||
void setInput(Input::Action input); // Actua en consecuencia de la entrada recibida
|
||||
void setAnimation(); // Establece la animación correspondiente al estado
|
||||
|
||||
[[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable
|
||||
|
||||
+18
-18
@@ -2473,29 +2473,29 @@ void Game::processDemoInput() {
|
||||
const DemoKeys &keys = demo_.data_file[demo_.counter];
|
||||
|
||||
if (keys.left == 1) {
|
||||
players_[INDEX]->setInput(LEFT);
|
||||
players_[INDEX]->setInput(Input::Action::LEFT);
|
||||
}
|
||||
if (keys.right == 1) {
|
||||
players_[INDEX]->setInput(RIGHT);
|
||||
players_[INDEX]->setInput(Input::Action::RIGHT);
|
||||
}
|
||||
if (keys.no_input == 1) {
|
||||
players_[INDEX]->setInput(INVALID);
|
||||
players_[INDEX]->setInput(Input::Action::INVALID);
|
||||
}
|
||||
|
||||
if (keys.fire == 1 && players_[INDEX]->canFire()) {
|
||||
players_[INDEX]->setInput(FIRE_CENTER);
|
||||
players_[INDEX]->setInput(Input::Action::FIRE_CENTER);
|
||||
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::UP, players_[INDEX]->isPowerUp(), INDEX);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
|
||||
if (keys.fire_left == 1 && players_[INDEX]->canFire()) {
|
||||
players_[INDEX]->setInput(FIRE_LEFT);
|
||||
players_[INDEX]->setInput(Input::Action::FIRE_LEFT);
|
||||
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::LEFT, players_[INDEX]->isPowerUp(), INDEX);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
|
||||
if (keys.fire_right == 1 && players_[INDEX]->canFire()) {
|
||||
players_[INDEX]->setInput(FIRE_RIGHT);
|
||||
players_[INDEX]->setInput(Input::Action::FIRE_RIGHT);
|
||||
createBullet(players_[INDEX]->getPosX() + (players_[INDEX]->getWidth() / 2) - 4, players_[INDEX]->getPosY() + (players_[INDEX]->getHeight() / 2), Bullet::Kind::RIGHT, players_[INDEX]->isPowerUp(), INDEX);
|
||||
players_[INDEX]->setFireCooldown(10);
|
||||
}
|
||||
@@ -2531,20 +2531,20 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
const auto &device = Options::inputs[i];
|
||||
|
||||
// Movimiento izquierda / derecha / nada
|
||||
if (input->checkInput(LEFT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(LEFT);
|
||||
if (input->checkInput(Input::Action::LEFT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
demo_.keys.left = 1;
|
||||
} else if (input->checkInput(RIGHT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(RIGHT);
|
||||
} else if (input->checkInput(Input::Action::RIGHT, Input::Repeat::ON, device.device_type, device.id)) {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
demo_.keys.right = 1;
|
||||
} else {
|
||||
player->setInput(INVALID);
|
||||
player->setInput(Input::Action::INVALID);
|
||||
demo_.keys.no_input = 1;
|
||||
}
|
||||
|
||||
// Disparo al centro
|
||||
if (input->checkInput(FIRE_CENTER, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_CENTER);
|
||||
if (input->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_CENTER);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::UP, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2552,8 +2552,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// Disparo a la izquierda
|
||||
if (input->checkInput(FIRE_LEFT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_LEFT);
|
||||
if (input->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_LEFT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::LEFT, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2561,8 +2561,8 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// Disparo a la derecha
|
||||
if (input->checkInput(FIRE_RIGHT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(FIRE_RIGHT);
|
||||
if (input->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) {
|
||||
player->setInput(Input::Action::FIRE_RIGHT);
|
||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::RIGHT, player->isPowerUp(), i);
|
||||
player->setFireCooldown(10);
|
||||
Audio::get()->playSound(bullet_sound_);
|
||||
@@ -2570,7 +2570,7 @@ void Game::processPlayerLiveInput(Player *player, int i) {
|
||||
}
|
||||
|
||||
// Pausa
|
||||
if (input->checkInput(PAUSE, Input::Repeat::OFF, device.device_type, device.id)) {
|
||||
if (input->checkInput(Input::Action::PAUSE, Input::Repeat::OFF, device.device_type, device.id)) {
|
||||
section_->subsection = SUBSECTION_GAME_PAUSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ void Instructions::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Instructions::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
quit_requested_ = true;
|
||||
finished_ = true;
|
||||
return;
|
||||
@@ -219,7 +219,7 @@ void Instructions::checkInput() {
|
||||
#endif
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
if (mode_ == Mode::AUTO) {
|
||||
finished_ = true;
|
||||
} else {
|
||||
|
||||
@@ -167,14 +167,14 @@ Intro::~Intro() {
|
||||
// Comprueba las entradas
|
||||
void Intro::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
Audio::get()->stopMusic();
|
||||
section_->name = SECTION_PROG_TITLE;
|
||||
section_->subsection = SUBSECTION_TITLE_1;
|
||||
|
||||
@@ -57,14 +57,14 @@ void Logo::checkLogoEnd() {
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(Input::Action::FIRE_RIGHT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_TITLE;
|
||||
section_->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
|
||||
@@ -622,7 +622,7 @@ void Title::render() {
|
||||
// Comprueba las entradas
|
||||
void Title::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
||||
section_->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -740,28 +740,28 @@ void Menu::setDefaultActionWhenCancel(int item) {
|
||||
|
||||
// Gestiona la entrada de teclado y mando durante el menu
|
||||
void Menu::checkInput() {
|
||||
if (Input::get()->checkInput(UP, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::UP, Input::Repeat::OFF)) {
|
||||
decreaseSelectorIndex();
|
||||
if (sound_move_ != nullptr) {
|
||||
Audio::get()->playSound(sound_move_);
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(DOWN, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::DOWN, Input::Repeat::OFF)) {
|
||||
increaseSelectorIndex();
|
||||
if (sound_move_ != nullptr) {
|
||||
Audio::get()->playSound(sound_move_);
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(ACCEPT, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::ACCEPT, Input::Repeat::OFF)) {
|
||||
item_selected_ = selector_.index;
|
||||
if (sound_accept_ != nullptr) {
|
||||
Audio::get()->playSound(sound_accept_);
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(CANCEL, Input::Repeat::OFF)) {
|
||||
if (Input::get()->checkInput(Input::Action::CANCEL, Input::Repeat::OFF)) {
|
||||
item_selected_ = default_action_when_cancel_;
|
||||
if (sound_cancel_ != nullptr) {
|
||||
Audio::get()->playSound(sound_cancel_);
|
||||
|
||||
Reference in New Issue
Block a user