integrada classe Input
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "core/math/easing.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
@@ -74,6 +75,9 @@ void EscenaJoc::executar() {
|
||||
// Actualitzar visibilitat del cursor (auto-ocultar)
|
||||
Mouse::updateCursorVisibility();
|
||||
|
||||
// Actualitzar sistema d'input ABANS del event loop
|
||||
Input::get()->update();
|
||||
|
||||
// Processar events SDL
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Manejo de finestra
|
||||
@@ -82,12 +86,7 @@ void EscenaJoc::executar() {
|
||||
}
|
||||
|
||||
// Events globals (F1/F2/F3/ESC/QUIT)
|
||||
if (GlobalEvents::handle(event, sdl_, context_)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Processament específic del joc (SPACE per disparar)
|
||||
processar_input(event);
|
||||
GlobalEvents::handle(event, sdl_, context_);
|
||||
}
|
||||
|
||||
// Actualitzar física del joc amb delta_time real
|
||||
@@ -180,6 +179,21 @@ void EscenaJoc::inicialitzar() {
|
||||
}
|
||||
|
||||
void EscenaJoc::actualitzar(float delta_time) {
|
||||
// Processar disparos (state-based, no event-based)
|
||||
if (!game_over_) {
|
||||
auto* input = Input::get();
|
||||
|
||||
// Jugador 1 dispara
|
||||
if (input->checkActionPlayer1(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
disparar_bala(0);
|
||||
}
|
||||
|
||||
// Jugador 2 dispara
|
||||
if (input->checkActionPlayer2(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
disparar_bala(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check game over state first
|
||||
if (game_over_) {
|
||||
// Game over: only update timer, enemies, bullets, and debris
|
||||
@@ -534,28 +548,6 @@ void EscenaJoc::dibuixar() {
|
||||
}
|
||||
}
|
||||
|
||||
void EscenaJoc::processar_input(const SDL_Event& event) {
|
||||
// Ignore ship controls during game over
|
||||
if (game_over_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Processament d'input per events puntuals (no continus)
|
||||
// L'input continu (fletxes/WASD) es processa en actualitzar() amb
|
||||
// SDL_GetKeyboardState()
|
||||
|
||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||
// P1 shoot
|
||||
if (event.key.key == Defaults::Controls::P1::SHOOT) {
|
||||
disparar_bala(0);
|
||||
}
|
||||
// P2 shoot
|
||||
else if (event.key.key == Defaults::Controls::P2::SHOOT) {
|
||||
disparar_bala(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EscenaJoc::tocado(uint8_t player_id) {
|
||||
// Death sequence: 3 phases
|
||||
// Phase 1: First call (itocado_per_jugador_[player_id] == 0) - trigger explosion
|
||||
|
||||
Reference in New Issue
Block a user