Demo: añadida la clase input

This commit is contained in:
2023-05-07 19:51:00 +02:00
parent 1923347da9
commit 14f970011e
4 changed files with 1388 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ Código fuente creado por JailDesigner
#include "units/movingsprite.h"
#include "units/texture.h"
#include "units/screen.h"
#include "units/input.h"
SDL_Event *event;
SDL_Window *window;
@@ -35,7 +36,7 @@ int main(int argc, char *argv[])
options->screen.nativeHeight = 240;
options->screen.nativeZoom = 2;
options->screen.windowZoom = 1;
options->console = false;
options->console = true;
// Inicializa la lista de recursos
Asset *asset = new Asset(argv[0]);
@@ -43,9 +44,12 @@ int main(int argc, char *argv[])
asset->add("/data/sound.wav", t_sound);
asset->add("/data/smb2.txt", t_font);
asset->add("/data/smb2.png", t_bitmap);
asset->add("/data/debug.txt", t_font);
asset->add("/data/debug.png", t_bitmap);
asset->add("/data/z80.png", t_bitmap);
asset->add("/data/notify.png", t_bitmap);
asset->add("/data/notify.wav", t_sound);
asset->add("/data/gamecontrollerdb.txt", t_data);
asset->setVerbose(options->console);
if (!asset->check())
{
@@ -85,8 +89,18 @@ int main(int argc, char *argv[])
Screen *screen = new Screen(window, renderer, options);
screen->addNotifier(asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
// Inicializa el objeto input
Input *input = new Input(asset->get("gamecontrollerdb.txt"));
input->setVerbose(options->console);
input->discoverGameController();
input->bindKey(input_up, SDL_SCANCODE_UP);
input->bindKey(input_down, SDL_SCANCODE_DOWN);
input->bindKey(input_left, SDL_SCANCODE_LEFT);
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
// Inicializa el texto
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
Text *debugText = new Text(asset->get("debug.txt"), asset->get("debug.png"), renderer);
// Inicializa el sprite
Texture *texture = new Texture(renderer, asset->get("z80.png"));
@@ -141,6 +155,23 @@ int main(int argc, char *argv[])
}
}
}
string inputPressed = "";
if (input->checkInput(input_left))
{
inputPressed = "LEFT";
}
if (input->checkInput(input_right))
{
inputPressed = "RIGHT";
}
if (input->checkInput(input_up))
{
inputPressed = "UP";
}
if (input->checkInput(input_down))
{
inputPressed = "DOWN";
}
// Actualiza la lógica del programa
if (SDL_GetTicks() - ticks > ticksSpeed)
@@ -230,17 +261,17 @@ int main(int argc, char *argv[])
SDL_RenderDrawLine(renderer, 0, gradLastLine - i, options->screen.nativeWidth, gradLastLine - i);
}
// Escribe el texto
text->setZoom(2);
// text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
text->writeDX(TXT_CENTER | TXT_SHADOW, options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO", 1, {255, 255, 255}, 1, {48, 48, 48});
text->disableZoom();
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar");
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion");
// Dibuja el sprite
sprite->render();
// Escribe el texto
text->setZoom(2);
text->writeDX(TXT_CENTER | TXT_SHADOW, options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO", 1, {255, 255, 255}, 1, {48, 48, 48});
text->disableZoom();
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar", 1, {240, 240, 240}, 1, {0, 0, 192});
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeCentered(options->screen.nativeWidth / 2, options->screen.nativeHeight / 2, inputPressed);
// Vuelca el buffer en pantalla
screen->blit();
}
@@ -260,6 +291,16 @@ int main(int argc, char *argv[])
{
delete text;
}
if (debugText != nullptr)
{
delete debugText;
}
// Finaliza el objeto input
if (input != nullptr)
{
delete input;
}
// Finaliza el objeto screen
if (screen != nullptr)