From 1f6956ad815674dbdc9cecf54bc4e95d4accd20a Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 2 Oct 2024 20:40:10 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20No=20se=20cridava=20a=20SDL=5FInit(?= =?UTF-8?q?)=20-=20[FIX]=20Ja=20funciona=20el=20gamepad=20-=20[CHG]=20Canv?= =?UTF-8?q?iat=20el=20format=20del=20temps=20en=20la=20pantalla=20de=20gam?= =?UTF-8?q?e=20over=20-=20[CHG]=20Canvi=20en=20una=20habitaci=C3=B3=20per?= =?UTF-8?q?=20a=20balancejar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/rooms/04.txt | 13 ++++++++++++- source/actor.cpp | 16 ++++++++++------ source/config.cpp | 6 +++--- source/controller.cpp | 16 ++++++++++++++++ source/controller.h | 7 +++++++ source/jgame.cpp | 4 ++-- source/m_catslife.cpp | 4 ++-- source/m_gameover.cpp | 10 +++++----- source/m_ingame.cpp | 8 ++++---- source/m_logo.cpp | 7 ++----- source/m_menu.cpp | 10 ++++++---- source/m_menu_audio.cpp | 8 ++++---- source/m_menu_gamepad.cpp | 14 +++++++------- source/m_menu_tecles.cpp | 8 ++++---- source/main.cpp | 2 +- 15 files changed, 85 insertions(+), 48 deletions(-) create mode 100644 source/controller.cpp create mode 100644 source/controller.h diff --git a/data/rooms/04.txt b/data/rooms/04.txt index fe3aad6..8c84d47 100644 --- a/data/rooms/04.txt +++ b/data/rooms/04.txt @@ -12,7 +12,7 @@ exit-xn: 5 editor-done: 1 actor{ - name: BOX + name: BOX-00 bmp: caixes.gif bmp-rect: 32 0 32 32 bmp-offset: 0 32 @@ -22,6 +22,17 @@ actor{ movement: CW } +actor{ + name: BOX-01 + bmp: caixes.gif + bmp-rect: 32 0 32 32 + bmp-offset: 0 32 + pos: 0 16 0 + size: 8 8 8 + flags: PICKABLE PUSHABLE GRAVITY + movement: CW +} + actor{ name: KALLAX-01 bmp: altres.gif diff --git a/source/actor.cpp b/source/actor.cpp index 434e39c..2597dc7 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -10,6 +10,7 @@ #include "config.h" #include #include "m_game.h" +#include "controller.h" namespace actor { @@ -682,7 +683,7 @@ namespace actor vec3_t max = room::getMax(); bool moving = false; - if (input::keyDown(SDL_SCANCODE_LEFT) || input::keyDown(config::getKey(KEY_LEFT))) + if (controller::down(KEY_LEFT)) // input::keyDown(SDL_SCANCODE_LEFT) || input::keyDown(config::getKey(KEY_LEFT))) { hero::useBoostRun(); act->orient = PUSH_XN; @@ -702,7 +703,7 @@ namespace actor act->push |= PUSH_XN; } } - else if (input::keyDown(SDL_SCANCODE_RIGHT) || input::keyDown(config::getKey(KEY_RIGHT))) + else if (controller::down(KEY_RIGHT)) //(input::keyDown(SDL_SCANCODE_RIGHT) || input::keyDown(config::getKey(KEY_RIGHT))) { hero::useBoostRun(); act->orient = PUSH_XP; @@ -722,7 +723,7 @@ namespace actor act->push |= PUSH_XP; } } - else if (input::keyDown(SDL_SCANCODE_UP) || input::keyDown(config::getKey(KEY_UP))) + else if (controller::down(KEY_UP)) //input::keyDown(SDL_SCANCODE_UP) || input::keyDown(config::getKey(KEY_UP))) { hero::useBoostRun(); act->orient = PUSH_YN; @@ -742,7 +743,7 @@ namespace actor act->push |= PUSH_YN; } } - else if (input::keyDown(SDL_SCANCODE_DOWN) || input::keyDown(config::getKey(KEY_DOWN))) + else if (controller::down(KEY_DOWN)) //input::keyDown(SDL_SCANCODE_DOWN) || input::keyDown(config::getKey(KEY_DOWN))) { hero::useBoostRun(); act->orient = PUSH_YP; @@ -762,7 +763,8 @@ namespace actor act->push |= PUSH_YP; } } - if ((input::keyPressed(SDL_SCANCODE_RETURN) || input::keyPressed(config::getKey(KEY_PICK))) && (hero::getSkills() & SKILL_PANTS)) + //if ((input::keyPressed(SDL_SCANCODE_RETURN) || input::keyPressed(config::getKey(KEY_PICK))) && (hero::getSkills() & SKILL_PANTS)) + if ((controller::pressed(KEY_PICK)) && (hero::getSkills() & SKILL_PANTS)) { if (picked) { @@ -809,7 +811,9 @@ namespace actor } } actor::actor_t *future_below = any_below_me(act); - if ((input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP))) && (hero::getSkills() & SKILL_SHOES) && (act->pos.y + act->size.y) <= max.y && act->pos.y >= min.y && (act->pos.x + act->size.x) <= max.x && act->pos.x >= min.x && act->react_mask == 0 && ((act->pos.z == 0 && room::getFloor() != 11) || (act->below || future_below))) + //if ((input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP))) && + if ((controller::down(KEY_JUMP)) && + (hero::getSkills() & SKILL_SHOES) && (act->pos.y + act->size.y) <= max.y && act->pos.y >= min.y && (act->pos.x + act->size.x) <= max.x && act->pos.x >= min.x && act->react_mask == 0 && ((act->pos.z == 0 && room::getFloor() != 11) || (act->below || future_below))) { // [RZC 01/10/2024] Hack per a que al aterrar sobre els que desapareixen puga botar sobre ells, i a més ells desapareguen if (!act->below && future_below && future_below->flags & FLAG_DISAPPEAR) diff --git a/source/config.cpp b/source/config.cpp index e0ed993..9b856c6 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -59,14 +59,14 @@ namespace config void definePadBtn(const int which, const int btn) { - static const char* nomtecles[6] = {"btnup", "btndown", "btnleft", "btnright", "btnjump", "btnpick"}; + static const char* nombotons[6] = {"btnup", "btndown", "btnleft", "btnright", "btnjump", "btnpick"}; pad_btns[which] = btn; char tmp[5]; - file::setConfigValue(nomtecles[which], SDL_itoa(btn, tmp, 10)); + file::setConfigValue(nombotons[which], SDL_itoa(btn, tmp, 10)); } const int getPadBtn(const int which) { - return keys[which]; + return pad_btns[which]; } } diff --git a/source/controller.cpp b/source/controller.cpp new file mode 100644 index 0000000..917360b --- /dev/null +++ b/source/controller.cpp @@ -0,0 +1,16 @@ +#include "controller.h" +#include "jinput.h" +#include "config.h" + +namespace controller +{ + const bool down(const int which) + { + return input::keyDown(config::getKey(which)) || input::padBtnDown(config::getPadBtn(which)); + } + + const bool pressed(const int which) + { + return input::keyPressed(config::getKey(which)) || input::padBtnPressed(config::getPadBtn(which)); + } +} diff --git a/source/controller.h b/source/controller.h new file mode 100644 index 0000000..6c71145 --- /dev/null +++ b/source/controller.h @@ -0,0 +1,7 @@ +#pragma once + +namespace controller +{ + const bool down(const int which); + const bool pressed(const int which); +} diff --git a/source/jgame.cpp b/source/jgame.cpp index 80b3484..0262a59 100644 --- a/source/jgame.cpp +++ b/source/jgame.cpp @@ -34,6 +34,8 @@ int main(int argc, char *argv[]) game::param_count = argc; game::params = argv; + SDL_Init(SDL_INIT_EVERYTHING); + game::init(); input::init(); audio::init(); @@ -64,8 +66,6 @@ int main(int argc, char *argv[]) } if (e.type==SDL_CONTROLLERBUTTONDOWN) { input::updatePadBtn(e.cbutton.button); - } - if (e.type==SDL_CONTROLLERBUTTONUP) { input::updatePadBtnPressed(e.cbutton.button); } } diff --git a/source/m_catslife.cpp b/source/m_catslife.cpp index 65db197..f63d9d6 100644 --- a/source/m_catslife.cpp +++ b/source/m_catslife.cpp @@ -1,6 +1,6 @@ #include "m_catslife.h" #include "jgame.h" -#include "jinput.h" +#include "controller.h" #include "jdraw.h" #include "actor.h" #include "room.h" @@ -20,7 +20,7 @@ namespace modules bool loop() { - if (input::keyPressed(SDL_SCANCODE_SPACE)) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) { return false; } diff --git a/source/m_gameover.cpp b/source/m_gameover.cpp index 8bddefc..e3a66d8 100644 --- a/source/m_gameover.cpp +++ b/source/m_gameover.cpp @@ -1,6 +1,6 @@ #include "m_gameover.h" #include "jgame.h" -#include "jinput.h" +#include "controller.h" #include "jdraw.h" #include "actor.h" #include "room.h" @@ -12,7 +12,7 @@ namespace modules namespace gameover { actor::actor_t *heroi = nullptr; - char time_text[7] = "000:00"; + char time_text[7] = " 00:00"; void init() { @@ -24,8 +24,8 @@ namespace modules int minutes = seconds / 60; seconds = seconds % 60; - time_text[0] = (minutes/100)+48; - time_text[1] = ((minutes%100)/10)+48; + time_text[0] = minutes<100 ? ' ' : (minutes/100)+48; + time_text[1] = minutes<10 ? ' ' : ((minutes%100)/10)+48; time_text[2] = (minutes%10)+48; time_text[4] = (seconds/10)+48; @@ -35,7 +35,7 @@ namespace modules bool loop() { - if (input::keyPressed(SDL_SCANCODE_SPACE)) { return false; } + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) { return false; } draw::cls(2); draw::color(1); diff --git a/source/m_ingame.cpp b/source/m_ingame.cpp index 469607e..794a0f7 100644 --- a/source/m_ingame.cpp +++ b/source/m_ingame.cpp @@ -1,6 +1,7 @@ #include "m_ingame.h" #include "jgame.h" #include "jinput.h" +#include "controller.h" #include "jdraw.h" #include "actor.h" #include "room.h" @@ -69,12 +70,11 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return INGAME_CONTINUAR; } - if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + if (controller::pressed(KEY_DOWN)) selected_option = (selected_option+1)&1; - if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + if (controller::pressed(KEY_UP)) selected_option = (selected_option-1)&1; - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) { return selected_option; } diff --git a/source/m_logo.cpp b/source/m_logo.cpp index bd84d82..02a41d0 100644 --- a/source/m_logo.cpp +++ b/source/m_logo.cpp @@ -1,6 +1,7 @@ #include "m_logo.h" #include "jdraw.h" #include "jinput.h" +#include "controller.h" #include "config.h" #include @@ -55,11 +56,7 @@ namespace modules bool loop() { - if (input::keyPressed(SDL_SCANCODE_ESCAPE) || - input::keyPressed(SDL_SCANCODE_SPACE) || - input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || - input::keyPressed(config::getKey(KEY_PICK)) ) { + if (input::keyPressed(SDL_SCANCODE_ESCAPE) || controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) ) { return false; } diff --git a/source/m_menu.cpp b/source/m_menu.cpp index c59ca34..f103636 100644 --- a/source/m_menu.cpp +++ b/source/m_menu.cpp @@ -1,6 +1,7 @@ #include "m_menu.h" #include "jgame.h" #include "jinput.h" +#include "controller.h" #include "jdraw.h" #include "config.h" #include @@ -33,14 +34,13 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return OPTION_EIXIR; } - if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN)) selected_option++; if (selected_option==5) selected_option=0; - if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP)) selected_option--; if (selected_option<0) selected_option=4; - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE) ) { return selected_option; } @@ -95,6 +95,8 @@ namespace modules }; + //draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, FONT_ZOOM_NONE); + draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); draw::render(); diff --git a/source/m_menu_audio.cpp b/source/m_menu_audio.cpp index 7e057f1..9038e22 100644 --- a/source/m_menu_audio.cpp +++ b/source/m_menu_audio.cpp @@ -1,6 +1,7 @@ #include "m_menu_audio.h" #include "jgame.h" #include "jinput.h" +#include "controller.h" #include "jdraw.h" #include #include "config.h" @@ -21,14 +22,13 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return MENU_AUDIO_TORNAR; } - if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + if (controller::pressed(KEY_DOWN)) selected_option = (selected_option==2)?0:selected_option+1; - if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + if (controller::pressed(KEY_UP)) selected_option = (selected_option==0)?2:selected_option-1; - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) { if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic(); if (selected_option==MENU_AUDIO_SO) config::toggleSound(); if (selected_option==MENU_AUDIO_TORNAR) return MENU_AUDIO_TORNAR; diff --git a/source/m_menu_gamepad.cpp b/source/m_menu_gamepad.cpp index c923738..caa5803 100644 --- a/source/m_menu_gamepad.cpp +++ b/source/m_menu_gamepad.cpp @@ -1,6 +1,7 @@ #include "m_menu_gamepad.h" #include "jdraw.h" #include "jinput.h" +#include "controller.h" #include "config.h" #include @@ -12,12 +13,12 @@ namespace modules int selected_option = MENU_GAMEPAD_AMUNT; states state = STATE_SELECTING; - char name[6] = "PAD00"; + char name[7] = "BTN 00"; const char *getPadBtnName(const int8_t key) { - name[3] = (key/10)+48; - name[4] = (key%10)+48; + name[4] = (key/10)+48; + name[5] = (key%10)+48; return name; } @@ -33,14 +34,13 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return MENU_GAMEPAD_TORNAR; } - if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + if (controller::pressed(KEY_DOWN)) { selected_option++; if (selected_option>6) selected_option=0; } - if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + if (controller::pressed(KEY_UP)) { selected_option--; if (selected_option<0) selected_option=6; } - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) { if (selected_option==MENU_GAMEPAD_TORNAR) return MENU_GAMEPAD_TORNAR; else diff --git a/source/m_menu_tecles.cpp b/source/m_menu_tecles.cpp index 0481cc9..4fcf9e8 100644 --- a/source/m_menu_tecles.cpp +++ b/source/m_menu_tecles.cpp @@ -1,6 +1,7 @@ #include "m_menu_tecles.h" #include "jdraw.h" #include "jinput.h" +#include "controller.h" #include "config.h" #include @@ -42,14 +43,13 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return MENU_TECLES_TORNAR; } - if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN)) { selected_option++; if (selected_option>6) selected_option=0; } - if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP)) { selected_option--; if (selected_option<0) selected_option=6; } - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || - input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE)) { if (selected_option==MENU_TECLES_TORNAR) return MENU_TECLES_TORNAR; else diff --git a/source/main.cpp b/source/main.cpp index 35e3944..b0fcf0b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -76,7 +76,7 @@ void loadConfig() for (int i=0; i<6; ++i) { const int value = SDL_atoi( file::getConfigValue(nombotons[i]).c_str() ); - if (value != 0) config::defineKey(i, value); + if (value != 0) config::definePadBtn(i, value); } }