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

BIN
data/debug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

194
data/debug.txt Normal file
View File

@@ -0,0 +1,194 @@
# box width
5
# box height
5
# 32 espacio ( )
3
# 33 !
1
# 34 "
3
# 35 #
3
# 36 $
3
# 37 %
3
# 38 &
3
# 39 '
1
# 40 (
2
# 41 )
2
# 42 *
3
# 43 +
3
# 44 ,
1
# 45 -
3
# 46 .
1
# 47 /
3
# 48 0
3
# 49 1
3
# 50 2
3
# 51 3
3
# 52 4
3
# 53 5
3
# 54 6
3
# 55 7
3
# 56 8
3
# 57 9
3
# 58 :
1
# 59 ;
1
# 60 <
3
# 61 =
3
# 62 >
3
# 63 ?
3
# 64 @
3
# 65 A
3
# 66 B
3
# 67 C
3
# 68 D
3
# 69 E
3
# 70 F
3
# 71 G
3
# 72 H
3
# 73 I
3
# 74 J
3
# 75 K
3
# 76 L
3
# 77 M
3
# 78 N
3
# 79 O
3
# 80 P
3
# 81 Q
3
# 82 R
3
# 83 S
3
# 84 T
3
# 85 U
3
# 86 V
3
# 87 W
3
# 88 X
3
# 89 Y
3
# 90 Z
3
# 91 [
2
# 92 \
3
# 93 ]
2
# 94 ^
3
# 95 _
3
# 96 `
2
# 97 a
3
# 98 b
3
# 99 c
3
# 100 d
3
# 101 e
3
# 102 f
3
# 103 g
3
# 104 h
3
# 105 i
3
# 106 j
3
# 107 k
3
# 108 l
3
# 109 m
3
# 110 n
3
# 111 o
3
# 112 p
3
# 113 q
3
# 114 r
3
# 115 s
3
# 116 t
3
# 117 u
3
# 118 v
3
# 119 w
3
# 120 x
3
# 121 y
3
# 122 z
3
# 123 {
3
# 124 |
3
# 125 }
3
# 126 ~
5

1144
data/gamecontrollerdb.txt Normal file

File diff suppressed because it is too large Load Diff

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)