Trabajando en la clase screen

This commit is contained in:
2022-08-11 18:39:56 +02:00
parent 09ad78b02e
commit 89a43b3529
8 changed files with 180 additions and 71 deletions

View File

@@ -1,10 +1,83 @@
#include "game.h"
// Constructor
Game::Game()
Game::Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input)
{
this->renderer = renderer;
this->asset = asset;
this->screen = screen;
this->input = input;
eventHandler = new SDL_Event();
}
// Destructor
Game::~Game()
{
delete eventHandler;
}
// Bucle para el juego
section_t Game::run()
{
init();
while (section.name == SECTION_PROG_GAME)
{
// Sección juego jugando
if (section.subsection == SUBSECTION_GAME_PLAY)
{
update();
render();
}
}
return section;
}
// Inicializa las variables necesarias para la sección 'Game'
void Game::init()
{
// Carga los recursos
// loadMedia();
ticks = 0;
ticksSpeed = 15;
section.name = SECTION_PROG_GAME;
section.subsection = SUBSECTION_GAME_PLAY;
}
// Actualiza el juego, las variables, comprueba la entrada, etc.
void Game::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
break;
}
}
}
}
// Pinta los objetos en pantalla
void Game::render()
{
// Prepara para dibujar el frame
screen->start();
screen->clean();
// Actualiza la pantalla
screen->blit();
}