#include "game.h" // Constructor 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(); }