La zona de juego se dibuja en su propia textura
This commit is contained in:
@@ -16,7 +16,8 @@ Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
counter = 0;
|
||||
rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
srcRect = {0, rect.h - playArea.h, playArea.w, playArea.h};
|
||||
dstRect = playArea;
|
||||
srcRect = {playArea.x, rect.h - playArea.h, playArea.w, playArea.h};
|
||||
dstRect = {0, 0, playArea.w, playArea.h};
|
||||
base = rect.h;
|
||||
|
||||
gradientRect[0] = {0, 0, rect.w, rect.h};
|
||||
|
||||
@@ -21,11 +21,11 @@ const int SCOREBOARD_X = 0;
|
||||
const int SCOREBOARD_Y = GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT;
|
||||
|
||||
// Zona de juego
|
||||
const SDL_Rect playArea = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT};
|
||||
const int PLAY_AREA_TOP = playArea.y;
|
||||
const int PLAY_AREA_BOTTOM = playArea.y + playArea.h;
|
||||
const int PLAY_AREA_LEFT = playArea.x;
|
||||
const int PLAY_AREA_RIGHT = playArea.x + playArea.w;
|
||||
const SDL_Rect playArea = {10, 10, GAMECANVAS_WIDTH-20, GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT-20};
|
||||
const int PLAY_AREA_TOP = 0;
|
||||
const int PLAY_AREA_BOTTOM = playArea.h;
|
||||
const int PLAY_AREA_LEFT = 0;
|
||||
const int PLAY_AREA_RIGHT = playArea.w;
|
||||
const int PLAY_AREA_WIDTH = playArea.w;
|
||||
const int PLAY_AREA_HEIGHT = playArea.h;
|
||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||
|
||||
@@ -46,6 +46,9 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
gameOverSprite = new Sprite(16, 80, 128, 96, gameOverTexture, renderer);
|
||||
gameOverEndSprite = new Sprite(PLAY_AREA_CENTER_X - gameOverEndTexture->getWidth() / 2, 80, 128, 96, gameOverEndTexture, renderer);
|
||||
|
||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, playArea.w, playArea.h);
|
||||
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa las variables necesarias para la sección 'Game'
|
||||
init();
|
||||
}
|
||||
@@ -141,6 +144,8 @@ Game::~Game()
|
||||
delete gameOverSprite;
|
||||
delete gameOverEndSprite;
|
||||
|
||||
SDL_DestroyTexture(canvas);
|
||||
|
||||
JA_DeleteSound(balloonSound);
|
||||
JA_DeleteSound(bulletSound);
|
||||
JA_DeleteSound(playerCollisionSound);
|
||||
@@ -2684,17 +2689,18 @@ void Game::renderSeparator()
|
||||
{
|
||||
// Dibuja la linea que separa el marcador de la zona de juego
|
||||
SDL_SetRenderDrawColor(renderer, separator.r, separator.g, separator.b, 255);
|
||||
SDL_RenderDrawLine(renderer, PLAY_AREA_LEFT, PLAY_AREA_BOTTOM, PLAY_AREA_RIGHT, PLAY_AREA_BOTTOM);
|
||||
SDL_RenderDrawLine(renderer, SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_X + SCOREBOARD_WIDTH, SCOREBOARD_Y);
|
||||
}
|
||||
|
||||
// Dibuja el juego
|
||||
void Game::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
//Dibujamos el contenido de la zona de juego en su textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, canvas);
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Dibuja los objetos
|
||||
background->render();
|
||||
@@ -2703,10 +2709,22 @@ void Game::render()
|
||||
renderBalloons();
|
||||
renderBullets();
|
||||
renderMessages();
|
||||
scoreboard->render();
|
||||
renderSeparator();
|
||||
renderPlayers();
|
||||
|
||||
// Deja el renderizador apuntando donde estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
|
||||
// Dibuja la zona de juego y el marcador
|
||||
SDL_RenderCopy(renderer, canvas, nullptr, &playArea);
|
||||
scoreboard->render();
|
||||
//renderSeparator();
|
||||
|
||||
if ((deathCounter <= 150) && !players[0]->isAlive())
|
||||
{
|
||||
renderDeathFade(150 - deathCounter);
|
||||
|
||||
@@ -126,6 +126,7 @@ private:
|
||||
section_t *section; // Seccion actual dentro del juego
|
||||
Scoreboard *scoreboard; // Objeto para dibujar el marcador
|
||||
Background *background; // Objetio para dibujar el fondo del juego
|
||||
SDL_Texture *canvas; // Textura para dibujar la zona de juego
|
||||
|
||||
std::vector<Player *> players; // Vector con los jugadores
|
||||
std::vector<Balloon *> balloons; // Vector con los globos
|
||||
|
||||
Reference in New Issue
Block a user