forked from jaildesigner-jailgames/jaildoctors_dilemma
Transició a surface: crec que falta room.cpp
This commit is contained in:
@@ -10,12 +10,12 @@
|
|||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||||
#include "s_moving_sprite.h" // for MovingSprite
|
#include "s_moving_sprite.h" // for SMovingSprite
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "surface.h" // for Texture
|
#include "surface.h" // for Surface
|
||||||
#include "utils.h" // for Color, stringToColor
|
#include "utils.h" // for Color, stringToColor
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ Ending2::Ending2()
|
|||||||
options.section.subsection = Subsection::NONE;
|
options.section.subsection = Subsection::NONE;
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
for (const auto &color : color_list)
|
for (const auto &color : COLORS)
|
||||||
{
|
{
|
||||||
colors_.push_back(stringToColor(options.video.palette, color));
|
colors_.push_back(stringToColor(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
@@ -97,7 +97,7 @@ void Ending2::update()
|
|||||||
// Dibuja el final en pantalla
|
// Dibuja el final en pantalla
|
||||||
void Ending2::render()
|
void Ending2::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la surface de juego
|
||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
@@ -325,36 +325,33 @@ void Ending2::updateTexts()
|
|||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
void Ending2::renderSprites()
|
void Ending2::renderSprites()
|
||||||
{
|
{
|
||||||
const Color color = stringToColor(options.video.palette, "red");
|
const Uint8 colorA = stringToColor("red");
|
||||||
for (auto sprite : sprites_)
|
for (auto sprite : sprites_)
|
||||||
{
|
{
|
||||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
const bool B = sprite->getRect().y < options.game.height;
|
const bool B = sprite->getRect().y < options.game.height;
|
||||||
if (A && B)
|
if (A && B)
|
||||||
{
|
{
|
||||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
sprite->render(1, colorA);
|
||||||
sprite->render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el ultimo elemento de otro color
|
// Pinta el ultimo elemento de otro color
|
||||||
const Color c = stringToColor(options.video.palette, "white");
|
const Uint8 colorB = stringToColor("white");
|
||||||
sprites_.back()->getTexture()->setColor(c.r, c.g, c.b);
|
sprites_.back()->render(1, colorB);
|
||||||
sprites_.back()->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los sprites con el texto
|
// Dibuja los sprites con el texto
|
||||||
void Ending2::renderSpriteTexts()
|
void Ending2::renderSpriteTexts()
|
||||||
{
|
{
|
||||||
const Color color = stringToColor(options.video.palette, "white");
|
const Uint8 color = stringToColor("white");
|
||||||
for (auto sprite : sprite_texts_)
|
for (auto sprite : sprite_texts_)
|
||||||
{
|
{
|
||||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
const bool B = sprite->getRect().y < options.game.height;
|
const bool B = sprite->getRect().y < options.game.height;
|
||||||
if (A && B)
|
if (A && B)
|
||||||
{
|
{
|
||||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
sprite->render(1, color);
|
||||||
sprite->render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,17 +421,16 @@ void Ending2::createSpriteTexts()
|
|||||||
// Calcula la posición Y del texto en base a la posición y altura del sprite
|
// Calcula la posición Y del texto en base a la posición y altura del sprite
|
||||||
const int Y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + DIST_SPRITE_TEXT_;
|
const int Y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + DIST_SPRITE_TEXT_;
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la surface
|
||||||
auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
|
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), W, H);
|
||||||
texture->createBlank(W, H);
|
Screen::get()->setRenderSurfaceData(surface);
|
||||||
texture->setAsRenderTarget(Screen::get()->getRenderer());
|
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
||||||
text->write(0, 0, txt);
|
text->write(0, 0, txt);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {X, Y, W, H};
|
SDL_Rect pos = {X, Y, W, H};
|
||||||
sprite_texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
sprite_texts_.emplace_back(std::make_shared<SMovingSprite>(surface, pos));
|
||||||
sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
||||||
|
Screen::get()->setRenderSurfaceData(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,17 +453,16 @@ void Ending2::createTexts()
|
|||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int y = options.game.height + (text->getCharacterSize() * (i * 2));
|
const int y = options.game.height + (text->getCharacterSize() * (i * 2));
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la surface
|
||||||
auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
|
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), w, h);
|
||||||
texture->createBlank(w, h);
|
Screen::get()->setRenderSurfaceData(surface);
|
||||||
texture->setAsRenderTarget(Screen::get()->getRenderer());
|
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
||||||
text->write(0, 0, list[i]);
|
text->write(0, 0, list[i]);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {x + dx, y, w, h};
|
SDL_Rect pos = {x + dx, y, w, h};
|
||||||
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
texts_.emplace_back(std::make_shared<SMovingSprite>(surface, pos));
|
||||||
texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
||||||
|
Screen::get()->setRenderSurfaceData(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los últimos textos
|
// Crea los últimos textos
|
||||||
@@ -487,17 +482,16 @@ void Ending2::createTexts()
|
|||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int y = START + (text->getCharacterSize() * (i * 2));
|
const int y = START + (text->getCharacterSize() * (i * 2));
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la surface
|
||||||
auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
|
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(),w, h);
|
||||||
texture->createBlank(w, h);
|
Screen::get()->setRenderSurfaceData(surface);
|
||||||
texture->setAsRenderTarget(Screen::get()->getRenderer());
|
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
||||||
text->write(0, 0, list[i]);
|
text->write(0, 0, list[i]);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {x + dx, y, w, h};
|
SDL_Rect pos = {x + dx, y, w, h};
|
||||||
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
texts_.emplace_back(std::make_shared<SMovingSprite>(surface, pos));
|
||||||
texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
texts_.back()->setVelY(SPRITE_DESP_SPEED_);
|
||||||
|
Screen::get()->setRenderSurfaceData(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +504,7 @@ void Ending2::updateFinalFade()
|
|||||||
|
|
||||||
for (const auto &text : texts_)
|
for (const auto &text : texts_)
|
||||||
{
|
{
|
||||||
text->getTexture()->setColor(colors_.at(INDEX).r, colors_.at(INDEX).g, colors_.at(INDEX).b);
|
//text->getTexture()->setColor(colors_.at(INDEX).r, colors_.at(INDEX).g, colors_.at(INDEX).b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
|
#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class AnimatedSprite; // lines 10-10
|
class SAnimatedSprite; // lines 10-10
|
||||||
class MovingSprite; // lines 13-13
|
class SMovingSprite; // lines 13-13
|
||||||
|
|
||||||
class Ending2
|
class Ending2
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Constantes
|
// Constantes
|
||||||
static constexpr int FIRST_COL_ =
|
static constexpr int FIRST_COL_ = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites
|
||||||
GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites
|
static constexpr int SECOND_COL_ = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites
|
||||||
static constexpr int SECOND_COL_ =
|
static constexpr int DIST_SPRITE_TEXT_ = 8; // Distancia entre el sprite y el texto que lo acompaña
|
||||||
GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites
|
static constexpr int DIST_SPRITE_SPRITE_ = 0; // Distancia entre dos sprites de la misma columna
|
||||||
static constexpr int DIST_SPRITE_TEXT_ = 8; // Distancia entre el sprite y el texto que lo acompaña
|
static constexpr float SPRITE_DESP_SPEED_ = -0.2f; // Velocidad de desplazamiento de los sprites
|
||||||
static constexpr int DIST_SPRITE_SPRITE_ = 0; // Distancia entre dos sprites de la misma columna
|
|
||||||
static constexpr float SPRITE_DESP_SPEED_ = -0.2f; // Velocidad de desplazamiento de los sprites
|
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::vector<std::shared_ptr<AnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
|
std::vector<std::shared_ptr<SAnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
|
||||||
std::vector<std::shared_ptr<MovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
|
std::vector<std::shared_ptr<SMovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
|
||||||
std::vector<std::shared_ptr<MovingSprite>> texts_; // Vector con los sprites de texto
|
std::vector<std::shared_ptr<SMovingSprite>> texts_; // Vector con los sprites de texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
bool counter_enabled_; // Indica si está el contador habilitado
|
bool counter_enabled_; // Indica si está el contador habilitado
|
||||||
@@ -33,7 +31,7 @@ private:
|
|||||||
bool post_counter_enabled_; // Indica si está habilitado el contador
|
bool post_counter_enabled_; // Indica si está habilitado el contador
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
std::vector<std::string> sprite_list_; // Lista con todos los sprites a dibujar
|
std::vector<std::string> sprite_list_; // Lista con todos los sprites a dibujar
|
||||||
std::vector<Color> colors_; // Vector con los colores para el fade
|
std::vector<Uint8> colors_; // Vector con los colores para el fade
|
||||||
int sprite_max_width_; // El valor de ancho del sprite mas ancho
|
int sprite_max_width_; // El valor de ancho del sprite mas ancho
|
||||||
int sprite_max_height_; // El valor de alto del sprite mas alto
|
int sprite_max_height_; // El valor de alto del sprite mas alto
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include "s_animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for SAnimatedSprite
|
||||||
#include "options.h" // for Options, OptionsVideo, options
|
#include "options.h" // for Options, OptionsVideo, options
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "surface.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Enemy::Enemy(const EnemyData &enemy)
|
Enemy::Enemy(const EnemyData &enemy)
|
||||||
: sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getSurface(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))),
|
: sprite_(std::make_shared<SAnimatedSprite>(Resource::get()->getSurface(enemy.surface_path), Resource::get()->getAnimations(enemy.animation_path))),
|
||||||
color_string_(enemy.color),
|
color_string_(enemy.color),
|
||||||
x1_(enemy.x1),
|
x1_(enemy.x1),
|
||||||
x2_(enemy.x2),
|
x2_(enemy.x2),
|
||||||
@@ -33,16 +33,13 @@ Enemy::Enemy(const EnemyData &enemy)
|
|||||||
collider_ = getRect();
|
collider_ = getRect();
|
||||||
|
|
||||||
// Coloca un frame al azar o el designado
|
// Coloca un frame al azar o el designado
|
||||||
sprite_->setCurrentAnimationFrame(
|
sprite_->setCurrentAnimationFrame((enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame);
|
||||||
(enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el enemigo en pantalla
|
// Pinta el enemigo en pantalla
|
||||||
void Enemy::render()
|
void Enemy::render()
|
||||||
{
|
{
|
||||||
sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
sprite_->render(1, color_);
|
||||||
sprite_->render();
|
|
||||||
sprite_->getTexture()->setColor(255, 255, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -111,16 +108,4 @@ SDL_Rect Enemy::getRect()
|
|||||||
SDL_Rect &Enemy::getCollider()
|
SDL_Rect &Enemy::getCollider()
|
||||||
{
|
{
|
||||||
return collider_;
|
return collider_;
|
||||||
}
|
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void Enemy::reLoadTexture()
|
|
||||||
{
|
|
||||||
sprite_->getTexture()->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna la paleta
|
|
||||||
void Enemy::setPalette(Palette pal)
|
|
||||||
{
|
|
||||||
color_ = stringToColor(pal, color_string_);
|
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class AnimatedSprite;
|
class SAnimatedSprite;
|
||||||
|
|
||||||
// Estructura para pasar los datos de un enemigo
|
// Estructura para pasar los datos de un enemigo
|
||||||
struct EnemyData
|
struct EnemyData
|
||||||
{
|
{
|
||||||
std::string texture_path; // Ruta al fichero con la textura
|
std::string surface_path; // Ruta al fichero con la textura
|
||||||
std::string animation_path; // Ruta al fichero con la animación
|
std::string animation_path; // Ruta al fichero con la animación
|
||||||
int w; // Anchura del enemigo
|
int w; // Anchura del enemigo
|
||||||
int h; // Altura del enemigo
|
int h; // Altura del enemigo
|
||||||
float x; // Posición inicial en el eje X
|
float x; // Posición inicial en el eje X
|
||||||
float y; // Posición inicial en el eje Y
|
float y; // Posición inicial en el eje Y
|
||||||
float vx; // Velocidad en el eje X
|
float vx; // Velocidad en el eje X
|
||||||
float vy; // Velocidad en el eje Y
|
float vy; // Velocidad en el eje Y
|
||||||
int x1; // Limite izquierdo de la ruta en el eje X
|
int x1; // Limite izquierdo de la ruta en el eje X
|
||||||
int x2; // Limite derecho de la ruta en el eje X
|
int x2; // Limite derecho de la ruta en el eje X
|
||||||
int y1; // Limite superior de la ruta en el eje Y
|
int y1; // Limite superior de la ruta en el eje Y
|
||||||
int y2; // Limite inferior de la ruta en el eje Y
|
int y2; // Limite inferior de la ruta en el eje Y
|
||||||
bool flip; // Indica si el enemigo hace flip al terminar su ruta
|
bool flip; // Indica si el enemigo hace flip al terminar su ruta
|
||||||
bool mirror; // Indica si el enemigo está volteado verticalmente
|
bool mirror; // Indica si el enemigo está volteado verticalmente
|
||||||
int frame; // Frame inicial para la animación del enemigo
|
int frame; // Frame inicial para la animación del enemigo
|
||||||
std::string color; // Color del enemigo
|
std::string color; // Color del enemigo
|
||||||
};
|
};
|
||||||
|
|
||||||
class Enemy
|
class Enemy
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<AnimatedSprite> sprite_; // Sprite del enemigo
|
std::shared_ptr<SAnimatedSprite> sprite_; // Sprite del enemigo
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Color color_; // Color del enemigo
|
Uint8 color_; // Color del enemigo
|
||||||
std::string color_string_; // Color del enemigo en formato texto
|
std::string color_string_; // Color del enemigo en formato texto
|
||||||
int x1_; // Limite izquierdo de la ruta en el eje X
|
int x1_; // Limite izquierdo de la ruta en el eje X
|
||||||
int x2_; // Limite derecho de la ruta en el eje X
|
int x2_; // Limite derecho de la ruta en el eje X
|
||||||
@@ -65,10 +65,4 @@ public:
|
|||||||
|
|
||||||
// Obtiene el rectangulo de colision del enemigo
|
// Obtiene el rectangulo de colision del enemigo
|
||||||
SDL_Rect &getCollider();
|
SDL_Rect &getCollider();
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void reLoadTexture();
|
|
||||||
|
|
||||||
// Asigna la paleta
|
|
||||||
void setPalette(Palette pal);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "s_sprite.h" // Para Sprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "surface.h" // Para Texture
|
#include "surface.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(ItemData item)
|
Item::Item(ItemData item)
|
||||||
: sprite_(std::make_shared<Sprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)),
|
: sprite_(std::make_shared<SSprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)),
|
||||||
change_color_speed(4)
|
change_color_speed(4)
|
||||||
{
|
{
|
||||||
// Inicia variables
|
// Inicia variables
|
||||||
@@ -25,9 +25,7 @@ Item::Item(ItemData item)
|
|||||||
void Item::render()
|
void Item::render()
|
||||||
{
|
{
|
||||||
const int INDEX = (counter_ / change_color_speed) % color_.size();
|
const int INDEX = (counter_ / change_color_speed) % color_.size();
|
||||||
sprite_->getTexture()->setColor(color_.at(INDEX).r, color_.at(INDEX).g, color_.at(INDEX).b);
|
sprite_->render(1, color_.at(INDEX));
|
||||||
sprite_->render();
|
|
||||||
sprite_->getTexture()->setColor(255, 255, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene su ubicación
|
// Obtiene su ubicación
|
||||||
@@ -38,7 +36,7 @@ SDL_Point Item::getPos()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asigna los colores del objeto
|
// Asigna los colores del objeto
|
||||||
void Item::setColors(Color col1, Color col2)
|
void Item::setColors(Uint8 col1, Uint8 col2)
|
||||||
{
|
{
|
||||||
// Reinicializa el vector de colores
|
// Reinicializa el vector de colores
|
||||||
color_.clear();
|
color_.clear();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "s_sprite.h" // for Sprite
|
#include "s_sprite.h" // for SSprite
|
||||||
#include "surface.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ struct ItemData
|
|||||||
int y; // Posición del item en pantalla
|
int y; // Posición del item en pantalla
|
||||||
int tile; // Número de tile dentro de la textura
|
int tile; // Número de tile dentro de la textura
|
||||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||||
Color color1; // Uno de los dos colores que se utiliza para el item
|
Uint8 color1; // Uno de los dos colores que se utiliza para el item
|
||||||
Color color2; // Uno de los dos colores que se utiliza para el item
|
Uint8 color2; // Uno de los dos colores que se utiliza para el item
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ItemData() : x(0), y(0), tile(0), counter(0), color1(), color2() {}
|
ItemData() : x(0), y(0), tile(0), counter(0), color1(), color2() {}
|
||||||
@@ -29,10 +29,10 @@ private:
|
|||||||
static constexpr int ITEM_SIZE_ = 8;
|
static constexpr int ITEM_SIZE_ = 8;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<Sprite> sprite_; // Sprite del objeto
|
std::shared_ptr<SSprite> sprite_; // SSprite del objeto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Color> color_; // Vector con los colores del objeto
|
std::vector<Uint8> color_; // Vector con los colores del objeto
|
||||||
int counter_; // Contador interno
|
int counter_; // Contador interno
|
||||||
SDL_Rect collider_; // Rectangulo de colisión
|
SDL_Rect collider_; // Rectangulo de colisión
|
||||||
int change_color_speed; // Cuanto mas alto, mas tarda en cambiar de color
|
int change_color_speed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||||
@@ -56,9 +56,6 @@ public:
|
|||||||
// Obtiene su ubicación
|
// Obtiene su ubicación
|
||||||
SDL_Point getPos();
|
SDL_Point getPos();
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void reLoadTexture() { sprite_->getTexture()->reLoad(); }
|
|
||||||
|
|
||||||
// Asigna los colores del objeto
|
// Asigna los colores del objeto
|
||||||
void setColors(Color col1, Color col2);
|
void setColors(Uint8 col1, Uint8 col2);
|
||||||
};
|
};
|
||||||
@@ -272,7 +272,7 @@ bool setEnemy(EnemyData *enemy, const std::string &key, const std::string &value
|
|||||||
{
|
{
|
||||||
if (key == "tileSetFile")
|
if (key == "tileSetFile")
|
||||||
{
|
{
|
||||||
enemy->texture_path = value;
|
enemy->surface_path = value;
|
||||||
}
|
}
|
||||||
else if (key == "animation")
|
else if (key == "animation")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#include "s_animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for SAnimatedSprite
|
||||||
#include "defines.h" // for BLOCK
|
#include "defines.h" // for BLOCK
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Cheat
|
#include "options.h" // for Options, options, OptionsVideo, Cheat
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
@@ -21,14 +21,14 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
|||||||
constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK;
|
constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK;
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
item_texture_ = Resource::get()->getSurface("items.gif");
|
item_surface_ = Resource::get()->getSurface("items.gif");
|
||||||
auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif");
|
auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif");
|
||||||
auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
|
auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
|
||||||
player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations);
|
player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations);
|
||||||
player_sprite_->setCurrentAnimation("walk_menu");
|
player_sprite_->setCurrentAnimation("walk_menu");
|
||||||
|
|
||||||
texture_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_);
|
surface_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_);
|
||||||
texture_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_};
|
surface_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_};
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
@@ -36,26 +36,26 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
|||||||
is_paused_ = false;
|
is_paused_ = false;
|
||||||
paused_time_ = 0;
|
paused_time_ = 0;
|
||||||
paused_time_elapsed_ = 0;
|
paused_time_elapsed_ = 0;
|
||||||
items_color_ = stringToColor(options.video.palette, "white");
|
items_color_ = stringToColor("white");
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> COLORS = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
const std::vector<std::string> COLORS = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||||
for (const auto &color : COLORS)
|
for (const auto &color : COLORS)
|
||||||
{
|
{
|
||||||
color_.push_back(stringToColor(options.video.palette, color));
|
color_.push_back(stringToColor(color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Scoreboard::~Scoreboard()
|
Scoreboard::~Scoreboard()
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(texture_);
|
SDL_DestroyTexture(surface_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void Scoreboard::render()
|
void Scoreboard::render()
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, &texture_dest_);
|
SDL_RenderCopy(Screen::get()->getRenderer(), surface_, nullptr, &surface_dest_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -124,11 +124,11 @@ void Scoreboard::updateItemsColor()
|
|||||||
|
|
||||||
if (counter_ % 20 < 10)
|
if (counter_ % 20 < 10)
|
||||||
{
|
{
|
||||||
items_color_ = stringToColor(options.video.palette, "white");
|
items_color_ = stringToColor("white");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
items_color_ = stringToColor(options.video.palette, "magenta");
|
items_color_ = stringToColor("magenta");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ void Scoreboard::fillTexture()
|
|||||||
{
|
{
|
||||||
// Empieza a dibujar en la textura
|
// Empieza a dibujar en la textura
|
||||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), surface_);
|
||||||
|
|
||||||
// Limpia la textura
|
// Limpia la textura
|
||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
||||||
@@ -162,17 +162,15 @@ void Scoreboard::fillTexture()
|
|||||||
{
|
{
|
||||||
player_sprite_->setPosX(8 + (16 * i) + desp);
|
player_sprite_->setPosX(8 + (16 * i) + desp);
|
||||||
const int index = i % color_.size();
|
const int index = i % color_.size();
|
||||||
player_sprite_->getTexture()->setColor(color_[index].r, color_[index].g, color_[index].b);
|
player_sprite_->render(1, color_.at(index));
|
||||||
player_sprite_->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra si suena la música
|
// Muestra si suena la música
|
||||||
if (data_->music)
|
if (data_->music)
|
||||||
{
|
{
|
||||||
const Color c = data_->color;
|
const Uint8 c = data_->color;
|
||||||
SDL_Rect clip = {0, 8, 8, 8};
|
SDL_Rect clip = {0, 8, 8, 8};
|
||||||
item_texture_->setColor(c.r, c.g, c.b);
|
item_surface_->renderWithColorReplace(20 * BLOCK, LINE2, 1, c, &clip);
|
||||||
item_texture_->render(20 * BLOCK, LINE2, &clip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe los textos
|
// Escribe los textos
|
||||||
@@ -182,11 +180,11 @@ void Scoreboard::fillTexture()
|
|||||||
text->writeColored(BLOCK, LINE1, "Items collected ", data_->color);
|
text->writeColored(BLOCK, LINE1, "Items collected ", data_->color);
|
||||||
text->writeColored(17 * BLOCK, LINE1, ITEMS_TEXT, items_color_);
|
text->writeColored(17 * BLOCK, LINE1, ITEMS_TEXT, items_color_);
|
||||||
text->writeColored(20 * BLOCK, LINE1, " Time ", data_->color);
|
text->writeColored(20 * BLOCK, LINE1, " Time ", data_->color);
|
||||||
text->writeColored(26 * BLOCK, LINE1, TIME_TEXT, stringToColor(options.video.palette, "white"));
|
text->writeColored(26 * BLOCK, LINE1, TIME_TEXT, stringToColor("white"));
|
||||||
|
|
||||||
const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10);
|
const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10);
|
||||||
text->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor(options.video.palette, "white"));
|
text->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor("white"));
|
||||||
text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor(options.video.palette, "white"));
|
text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor("white"));
|
||||||
|
|
||||||
// Deja el renderizador como estaba
|
// Deja el renderizador como estaba
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class AnimatedSprite; // lines 9-9
|
class SAnimatedSprite; // lines 9-9
|
||||||
class Texture; // lines 13-13
|
class Surface; // lines 13-13
|
||||||
|
|
||||||
struct ScoreboardData
|
struct ScoreboardData
|
||||||
{
|
{
|
||||||
@@ -16,16 +16,16 @@ struct ScoreboardData
|
|||||||
int lives; // Lleva la cuenta de las vidas restantes del jugador
|
int lives; // Lleva la cuenta de las vidas restantes del jugador
|
||||||
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
||||||
bool music; // Indica si ha de sonar la música durante el juego
|
bool music; // Indica si ha de sonar la música durante el juego
|
||||||
Color color; // Color para escribir el texto del marcador
|
Uint8 color; // Color para escribir el texto del marcador
|
||||||
Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido
|
Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido
|
||||||
bool jail_is_open; // Indica si se puede entrar a la Jail
|
bool jail_is_open; // Indica si se puede entrar a la Jail
|
||||||
|
|
||||||
// Constructor por defecto
|
// Constructor por defecto
|
||||||
ScoreboardData()
|
ScoreboardData()
|
||||||
: items(0), lives(0), rooms(0), music(true), color({0, 0, 0}), ini_clock(0), jail_is_open(false) {}
|
: items(0), lives(0), rooms(0), music(true), color(0), ini_clock(0), jail_is_open(false) {}
|
||||||
|
|
||||||
// Constructor parametrizado
|
// Constructor parametrizado
|
||||||
ScoreboardData(int items, int lives, int rooms, bool music, Color color, Uint32 ini_clock, bool jail_is_open)
|
ScoreboardData(int items, int lives, int rooms, bool music, Uint8 color, Uint32 ini_clock, bool jail_is_open)
|
||||||
: items(items), lives(lives), rooms(rooms), music(music), color(color), ini_clock(ini_clock), jail_is_open(jail_is_open) {}
|
: items(items), lives(lives), rooms(rooms), music(music), color(color), ini_clock(ini_clock), jail_is_open(jail_is_open) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,21 +49,21 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador
|
std::shared_ptr<SAnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador
|
||||||
std::shared_ptr<Texture> item_texture_; // Textura con los graficos para las vidas
|
std::shared_ptr<Surface> item_surface_; // Surface con los graficos para los elementos del marcador
|
||||||
std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador
|
std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador
|
||||||
SDL_Texture *texture_; // Textura donde dibujar el marcador;
|
SDL_Texture *surface_; // Surface donde dibujar el marcador;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Color> color_; // Vector con los colores del objeto
|
std::vector<Uint8> color_; // Vector con los colores del objeto
|
||||||
int counter_; // Contador interno
|
int counter_; // Contador interno
|
||||||
int change_color_speed_; // Cuanto mas alto, mas tarda en cambiar de color
|
int change_color_speed_; // Cuanto mas alto, mas tarda en cambiar de color
|
||||||
bool is_paused_; // Indica si el marcador esta en modo pausa
|
bool is_paused_; // Indica si el marcador esta en modo pausa
|
||||||
Uint32 paused_time_; // Milisegundos que ha estado el marcador en pausa
|
Uint32 paused_time_; // Milisegundos que ha estado el marcador en pausa
|
||||||
Uint32 paused_time_elapsed_; // Tiempo acumulado en pausa
|
Uint32 paused_time_elapsed_; // Tiempo acumulado en pausa
|
||||||
ClockData clock_; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
ClockData clock_; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
||||||
Color items_color_; // Color de la cantidad de items recogidos
|
Uint8 items_color_; // Color de la cantidad de items recogidos
|
||||||
SDL_Rect texture_dest_; // Rectangulo donde dibujar la textura del marcador
|
SDL_Rect surface_dest_; // Rectangulo donde dibujar la surface del marcador
|
||||||
|
|
||||||
// Obtiene el tiempo transcurrido de partida
|
// Obtiene el tiempo transcurrido de partida
|
||||||
ClockData getTime();
|
ClockData getTime();
|
||||||
@@ -71,7 +71,7 @@ private:
|
|||||||
// Actualiza el color de la cantidad de items recogidos
|
// Actualiza el color de la cantidad de items recogidos
|
||||||
void updateItemsColor();
|
void updateItemsColor();
|
||||||
|
|
||||||
// Dibuja los elementos del marcador en la textura
|
// Dibuja los elementos del marcador en la surface
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user