- [FIX] No se cridava a SDL_Init()

- [FIX] Ja funciona el gamepad
- [CHG] Canviat el format del temps en la pantalla de game over
- [CHG] Canvi en una habitació per a balancejar
This commit is contained in:
2024-10-02 20:40:10 +02:00
parent c92f2a13aa
commit 1f6956ad81
15 changed files with 85 additions and 48 deletions

View File

@@ -12,7 +12,7 @@ exit-xn: 5
editor-done: 1 editor-done: 1
actor{ actor{
name: BOX name: BOX-00
bmp: caixes.gif bmp: caixes.gif
bmp-rect: 32 0 32 32 bmp-rect: 32 0 32 32
bmp-offset: 0 32 bmp-offset: 0 32
@@ -22,6 +22,17 @@ actor{
movement: CW 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{ actor{
name: KALLAX-01 name: KALLAX-01
bmp: altres.gif bmp: altres.gif

View File

@@ -10,6 +10,7 @@
#include "config.h" #include "config.h"
#include <vector> #include <vector>
#include "m_game.h" #include "m_game.h"
#include "controller.h"
namespace actor namespace actor
{ {
@@ -682,7 +683,7 @@ namespace actor
vec3_t max = room::getMax(); vec3_t max = room::getMax();
bool moving = false; 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(); hero::useBoostRun();
act->orient = PUSH_XN; act->orient = PUSH_XN;
@@ -702,7 +703,7 @@ namespace actor
act->push |= PUSH_XN; 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(); hero::useBoostRun();
act->orient = PUSH_XP; act->orient = PUSH_XP;
@@ -722,7 +723,7 @@ namespace actor
act->push |= PUSH_XP; 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(); hero::useBoostRun();
act->orient = PUSH_YN; act->orient = PUSH_YN;
@@ -742,7 +743,7 @@ namespace actor
act->push |= PUSH_YN; 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(); hero::useBoostRun();
act->orient = PUSH_YP; act->orient = PUSH_YP;
@@ -762,7 +763,8 @@ namespace actor
act->push |= PUSH_YP; 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) if (picked)
{ {
@@ -809,7 +811,9 @@ namespace actor
} }
} }
actor::actor_t *future_below = any_below_me(act); 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 // [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) if (!act->below && future_below && future_below->flags & FLAG_DISAPPEAR)

View File

@@ -59,14 +59,14 @@ namespace config
void definePadBtn(const int which, const int btn) 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; pad_btns[which] = btn;
char tmp[5]; 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) const int getPadBtn(const int which)
{ {
return keys[which]; return pad_btns[which];
} }
} }

16
source/controller.cpp Normal file
View File

@@ -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));
}
}

7
source/controller.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
namespace controller
{
const bool down(const int which);
const bool pressed(const int which);
}

View File

@@ -34,6 +34,8 @@ int main(int argc, char *argv[])
game::param_count = argc; game::param_count = argc;
game::params = argv; game::params = argv;
SDL_Init(SDL_INIT_EVERYTHING);
game::init(); game::init();
input::init(); input::init();
audio::init(); audio::init();
@@ -64,8 +66,6 @@ int main(int argc, char *argv[])
} }
if (e.type==SDL_CONTROLLERBUTTONDOWN) { if (e.type==SDL_CONTROLLERBUTTONDOWN) {
input::updatePadBtn(e.cbutton.button); input::updatePadBtn(e.cbutton.button);
}
if (e.type==SDL_CONTROLLERBUTTONUP) {
input::updatePadBtnPressed(e.cbutton.button); input::updatePadBtnPressed(e.cbutton.button);
} }
} }

View File

@@ -1,6 +1,6 @@
#include "m_catslife.h" #include "m_catslife.h"
#include "jgame.h" #include "jgame.h"
#include "jinput.h" #include "controller.h"
#include "jdraw.h" #include "jdraw.h"
#include "actor.h" #include "actor.h"
#include "room.h" #include "room.h"
@@ -20,7 +20,7 @@ namespace modules
bool loop() bool loop()
{ {
if (input::keyPressed(SDL_SCANCODE_SPACE)) { if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) {
return false; return false;
} }

View File

@@ -1,6 +1,6 @@
#include "m_gameover.h" #include "m_gameover.h"
#include "jgame.h" #include "jgame.h"
#include "jinput.h" #include "controller.h"
#include "jdraw.h" #include "jdraw.h"
#include "actor.h" #include "actor.h"
#include "room.h" #include "room.h"
@@ -12,7 +12,7 @@ namespace modules
namespace gameover namespace gameover
{ {
actor::actor_t *heroi = nullptr; actor::actor_t *heroi = nullptr;
char time_text[7] = "000:00"; char time_text[7] = " 00:00";
void init() void init()
{ {
@@ -24,8 +24,8 @@ namespace modules
int minutes = seconds / 60; int minutes = seconds / 60;
seconds = seconds % 60; seconds = seconds % 60;
time_text[0] = (minutes/100)+48; time_text[0] = minutes<100 ? ' ' : (minutes/100)+48;
time_text[1] = ((minutes%100)/10)+48; time_text[1] = minutes<10 ? ' ' : ((minutes%100)/10)+48;
time_text[2] = (minutes%10)+48; time_text[2] = (minutes%10)+48;
time_text[4] = (seconds/10)+48; time_text[4] = (seconds/10)+48;
@@ -35,7 +35,7 @@ namespace modules
bool loop() 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::cls(2);
draw::color(1); draw::color(1);

View File

@@ -1,6 +1,7 @@
#include "m_ingame.h" #include "m_ingame.h"
#include "jgame.h" #include "jgame.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "jdraw.h" #include "jdraw.h"
#include "actor.h" #include "actor.h"
#include "room.h" #include "room.h"
@@ -69,12 +70,11 @@ namespace modules
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return INGAME_CONTINUAR; 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; 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; selected_option = (selected_option-1)&1;
if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) {
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
return selected_option; return selected_option;
} }

View File

@@ -1,6 +1,7 @@
#include "m_logo.h" #include "m_logo.h"
#include "jdraw.h" #include "jdraw.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "config.h" #include "config.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -55,11 +56,7 @@ namespace modules
bool loop() bool loop()
{ {
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || if (input::keyPressed(SDL_SCANCODE_ESCAPE) || controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) ) {
input::keyPressed(SDL_SCANCODE_SPACE) ||
input::keyPressed(SDL_SCANCODE_RETURN) ||
input::keyPressed(config::getKey(KEY_JUMP)) ||
input::keyPressed(config::getKey(KEY_PICK)) ) {
return false; return false;
} }

View File

@@ -1,6 +1,7 @@
#include "m_menu.h" #include "m_menu.h"
#include "jgame.h" #include "jgame.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "jdraw.h" #include "jdraw.h"
#include "config.h" #include "config.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -33,14 +34,13 @@ namespace modules
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return OPTION_EIXIR; 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; 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; selected_option--; if (selected_option<0) selected_option=4;
if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE) ) {
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
return selected_option; 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::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);
draw::render(); draw::render();

View File

@@ -1,6 +1,7 @@
#include "m_menu_audio.h" #include "m_menu_audio.h"
#include "jgame.h" #include "jgame.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "jdraw.h" #include "jdraw.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "config.h" #include "config.h"
@@ -21,14 +22,13 @@ namespace modules
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return MENU_AUDIO_TORNAR; 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; 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; selected_option = (selected_option==0)?2:selected_option-1;
if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) {
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic(); if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic();
if (selected_option==MENU_AUDIO_SO) config::toggleSound(); if (selected_option==MENU_AUDIO_SO) config::toggleSound();
if (selected_option==MENU_AUDIO_TORNAR) return MENU_AUDIO_TORNAR; if (selected_option==MENU_AUDIO_TORNAR) return MENU_AUDIO_TORNAR;

View File

@@ -1,6 +1,7 @@
#include "m_menu_gamepad.h" #include "m_menu_gamepad.h"
#include "jdraw.h" #include "jdraw.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "config.h" #include "config.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -12,12 +13,12 @@ namespace modules
int selected_option = MENU_GAMEPAD_AMUNT; int selected_option = MENU_GAMEPAD_AMUNT;
states state = STATE_SELECTING; states state = STATE_SELECTING;
char name[6] = "PAD00"; char name[7] = "BTN 00";
const char *getPadBtnName(const int8_t key) 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; return name;
} }
@@ -33,14 +34,13 @@ namespace modules
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return MENU_GAMEPAD_TORNAR; 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; } { 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; } { selected_option--; if (selected_option<0) selected_option=6; }
if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) {
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
if (selected_option==MENU_GAMEPAD_TORNAR) if (selected_option==MENU_GAMEPAD_TORNAR)
return MENU_GAMEPAD_TORNAR; return MENU_GAMEPAD_TORNAR;
else else

View File

@@ -1,6 +1,7 @@
#include "m_menu_tecles.h" #include "m_menu_tecles.h"
#include "jdraw.h" #include "jdraw.h"
#include "jinput.h" #include "jinput.h"
#include "controller.h"
#include "config.h" #include "config.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -42,14 +43,13 @@ namespace modules
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return MENU_TECLES_TORNAR; 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; } { 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; } { selected_option--; if (selected_option<0) selected_option=6; }
if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE)) {
input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) {
if (selected_option==MENU_TECLES_TORNAR) if (selected_option==MENU_TECLES_TORNAR)
return MENU_TECLES_TORNAR; return MENU_TECLES_TORNAR;
else else

View File

@@ -76,7 +76,7 @@ void loadConfig()
for (int i=0; i<6; ++i) for (int i=0; i<6; ++i)
{ {
const int value = SDL_atoi( file::getConfigValue(nombotons[i]).c_str() ); 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);
} }
} }