Compare commits

...

2 Commits

Author SHA1 Message Date
14f970011e Demo: añadida la clase input 2023-05-07 19:51:00 +02:00
1923347da9 Añadidos colores al fondo 2023-05-07 19:00:44 +02:00
5 changed files with 1402 additions and 12 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())
{
@@ -59,7 +63,11 @@ int main(int argc, char *argv[])
if (window != nullptr)
{
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr)
if (renderer != nullptr)
{
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
}
else
{
exit(EXIT_FAILURE);
}
@@ -81,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"));
@@ -98,7 +116,7 @@ int main(int argc, char *argv[])
sprite->setVelY(2);
// Bucle principal
//JA_PlayMusic(music, true);
// JA_PlayMusic(music, true);
bool should_exit = false;
while (!should_exit)
{
@@ -137,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)
@@ -203,8 +238,6 @@ int main(int argc, char *argv[])
// Dibuja en pantalla
screen->start();
screen->clean();
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
// SDL_RenderClear(renderer);
// Dibuja un degradado de fondo
const int gradFirstLine = options->screen.nativeHeight / 3;
@@ -220,19 +253,27 @@ int main(int argc, char *argv[])
SDL_RenderDrawLine(renderer, 0, i, options->screen.nativeWidth, i);
}
// Escribe el texto
text->setZoom(2);
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
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");
for (int i = gradLastLine; i > gradFirstLine; --i)
{
float step = ((float)(i - gradFirstLine) / gradNumLines);
int alpha = 0 + ((255 - 0) * step);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, alpha);
SDL_RenderDrawLine(renderer, 0, gradLastLine - i, options->screen.nativeWidth, gradLastLine - i);
}
// 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();
// SDL_RenderPresent(renderer);
}
// Finaliza el sprite
@@ -250,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)

View File

@@ -29,6 +29,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(gameCanvas, SDL_BLENDMODE_BLEND);
// Establece el modo de video
setVideoMode(options->screen.mode);