Demo: implementado el cambio de tamaño de la ventana
This commit is contained in:
36
main.cpp
36
main.cpp
@@ -32,8 +32,10 @@ int main(int argc, char *argv[])
|
||||
// Inicializa las opciones
|
||||
struct options_t *options = new options_t;
|
||||
initOptions(options);
|
||||
options->gameWidth = 640;
|
||||
options->gameHeight = 480;
|
||||
options->screen.nativeWidth = 320;
|
||||
options->screen.nativeHeight = 240;
|
||||
options->screen.nativeZoom = 1;
|
||||
options->screen.windowZoom = 2;
|
||||
options->console = true;
|
||||
|
||||
// Inicializa la lista de recursos
|
||||
@@ -53,7 +55,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Inicializa SDL y la ventana
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options->gameWidth, options->gameHeight, SDL_WINDOW_SHOWN);
|
||||
window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom, options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom, SDL_WINDOW_SHOWN);
|
||||
if (window != nullptr)
|
||||
{
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
@@ -116,6 +118,19 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
switch (event->key.keysym.scancode)
|
||||
{
|
||||
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
should_exit = true;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_1:
|
||||
screen->decWindowSize();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_2:
|
||||
screen->incWindowSize();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_N:
|
||||
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
|
||||
break;
|
||||
@@ -139,7 +154,7 @@ int main(int argc, char *argv[])
|
||||
screen->update();
|
||||
|
||||
// Actualiza el sprite
|
||||
if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0)
|
||||
if (sprite->getPosX() + sprite->getWidth() > options->screen.nativeWidth or sprite->getPosX() < 0)
|
||||
{
|
||||
sprite->undoMoveX();
|
||||
int spr_direction = 1;
|
||||
@@ -155,7 +170,7 @@ int main(int argc, char *argv[])
|
||||
sprite->setVelX(spr_force * spr_direction);
|
||||
JA_PlaySound(sound);
|
||||
}
|
||||
if (sprite->getPosY() + sprite->getHeight() > options->gameHeight or sprite->getPosY() < 0)
|
||||
if (sprite->getPosY() + sprite->getHeight() > options->screen.nativeHeight or sprite->getPosY() < 0)
|
||||
{
|
||||
sprite->undoMoveY();
|
||||
int spr_direction = 1;
|
||||
@@ -193,8 +208,8 @@ int main(int argc, char *argv[])
|
||||
screen->clean();
|
||||
|
||||
// Dibuja un degradado de fondo
|
||||
const int gradFirstLine = options->gameHeight / 3;
|
||||
const int gradLastLine = options->gameHeight;
|
||||
const int gradFirstLine = options->screen.nativeHeight / 3;
|
||||
const int gradLastLine = options->screen.nativeHeight;
|
||||
const int gradNumLines = gradLastLine - gradFirstLine;
|
||||
const int gradColorFrom = 0;
|
||||
|
||||
@@ -203,14 +218,15 @@ int main(int argc, char *argv[])
|
||||
float step = ((float)(i - gradFirstLine) / gradNumLines);
|
||||
int color = gradColorFrom + ((gradCurrentColor - gradColorFrom) * step);
|
||||
SDL_SetRenderDrawColor(renderer, color, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i);
|
||||
SDL_RenderDrawLine(renderer, 0, i, options->screen.nativeWidth, i);
|
||||
}
|
||||
|
||||
// Escribe el texto
|
||||
text->setZoom(2);
|
||||
text->writeCentered(options->gameWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
|
||||
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
|
||||
text->disableZoom();
|
||||
text->writeCentered(options->gameWidth / 2, text->getCharacterSize() * 6, "Pulsa 'N' para mostrar una notificacion");
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user