fix: ja es mou la herbeta
This commit is contained in:
@@ -81,6 +81,7 @@ DATA|${PREFIX}/data/shaders/crtpi_fragment.glsl
|
|||||||
# Shaders OpenGL ES 3.0 (Raspberry Pi) - opcionales
|
# Shaders OpenGL ES 3.0 (Raspberry Pi) - opcionales
|
||||||
DATA|${PREFIX}/data/shaders/crtpi_vertex_es.glsl|optional
|
DATA|${PREFIX}/data/shaders/crtpi_vertex_es.glsl|optional
|
||||||
DATA|${PREFIX}/data/shaders/crtpi_fragment_es.glsl|optional
|
DATA|${PREFIX}/data/shaders/crtpi_fragment_es.glsl|optional
|
||||||
|
|
||||||
# Texturas - Balloons
|
# Texturas - Balloons
|
||||||
ANIMATION|${PREFIX}/data/gfx/balloon/balloon0.ani
|
ANIMATION|${PREFIX}/data/gfx/balloon/balloon0.ani
|
||||||
ANIMATION|${PREFIX}/data/gfx/balloon/balloon1.ani
|
ANIMATION|${PREFIX}/data/gfx/balloon/balloon1.ani
|
||||||
@@ -117,6 +118,7 @@ BITMAP|${PREFIX}/data/gfx/tabe/tabe.png
|
|||||||
BITMAP|${PREFIX}/data/gfx/game/game_buildings.png
|
BITMAP|${PREFIX}/data/gfx/game/game_buildings.png
|
||||||
BITMAP|${PREFIX}/data/gfx/game/game_clouds1.png
|
BITMAP|${PREFIX}/data/gfx/game/game_clouds1.png
|
||||||
BITMAP|${PREFIX}/data/gfx/game/game_clouds2.png
|
BITMAP|${PREFIX}/data/gfx/game/game_clouds2.png
|
||||||
|
ANIMATION|${PREFIX}/data/gfx/game/game_grass.ani
|
||||||
BITMAP|${PREFIX}/data/gfx/game/game_grass.png
|
BITMAP|${PREFIX}/data/gfx/game/game_grass.png
|
||||||
BITMAP|${PREFIX}/data/gfx/game/game_moon.png
|
BITMAP|${PREFIX}/data/gfx/game/game_moon.png
|
||||||
BITMAP|${PREFIX}/data/gfx/game/game_power_meter.png
|
BITMAP|${PREFIX}/data/gfx/game/game_power_meter.png
|
||||||
|
|||||||
9
data/gfx/game/game_grass.ani
Normal file
9
data/gfx/game/game_grass.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frame_width=320
|
||||||
|
frame_height=10
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=0.2
|
||||||
|
loop=0
|
||||||
|
frames=0,1,2,1
|
||||||
|
[/animation]
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
release/SDL3.dll
BIN
release/SDL3.dll
Binary file not shown.
@@ -7,6 +7,7 @@
|
|||||||
#include <cmath> // Para M_PI, cos, sin
|
#include <cmath> // Para M_PI, cos, sin
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "animated_sprite.h" // Para MovingSprite
|
||||||
#include "moving_sprite.h" // Para MovingSprite
|
#include "moving_sprite.h" // Para MovingSprite
|
||||||
#include "param.h" // Para Param, ParamBackground, param
|
#include "param.h" // Para Param, ParamBackground, param
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
@@ -22,10 +23,10 @@ Background::Background(float total_progress_to_complete)
|
|||||||
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||||
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
||||||
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
||||||
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
|
||||||
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
|
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
|
||||||
sun_texture_(Resource::get()->getTexture("game_sun.png")),
|
sun_texture_(Resource::get()->getTexture("game_sun.png")),
|
||||||
moon_texture_(Resource::get()->getTexture("game_moon.png")),
|
moon_texture_(Resource::get()->getTexture("game_moon.png")),
|
||||||
|
grass_sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("game_grass.png"), Resource::get()->getAnimation("game_grass.ani"))),
|
||||||
|
|
||||||
total_progress_to_complete_(total_progress_to_complete),
|
total_progress_to_complete_(total_progress_to_complete),
|
||||||
progress_per_stage_(total_progress_to_complete_ / STAGES),
|
progress_per_stage_(total_progress_to_complete_ / STAGES),
|
||||||
@@ -88,7 +89,6 @@ void Background::initializeSprites() {
|
|||||||
|
|
||||||
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
|
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
|
||||||
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
|
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
|
||||||
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
|
|
||||||
sun_sprite_ = std::make_unique<Sprite>(sun_texture_);
|
sun_sprite_ = std::make_unique<Sprite>(sun_texture_);
|
||||||
moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
|
moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
|
||||||
}
|
}
|
||||||
@@ -111,8 +111,14 @@ void Background::initializeSpriteProperties() {
|
|||||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||||
bottom_clouds_sprite_b_->setVelX(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S);
|
bottom_clouds_sprite_b_->setVelX(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S);
|
||||||
|
|
||||||
|
// grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
||||||
|
// grass_sprite_->resetAnimation();
|
||||||
|
grass_sprite_->setPos(0.0F, base_ - 10.0F);
|
||||||
|
grass_sprite_->setWidth(320.0F);
|
||||||
|
grass_sprite_->setHeight(10.0F);
|
||||||
|
//grass_sprite_->setCurrentAnimation(0);
|
||||||
|
|
||||||
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
|
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
|
||||||
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
|
||||||
sun_sprite_->setPosition(sun_path_.front());
|
sun_sprite_->setPosition(sun_path_.front());
|
||||||
moon_sprite_->setPosition(moon_path_.front());
|
moon_sprite_->setPosition(moon_path_.front());
|
||||||
}
|
}
|
||||||
@@ -141,12 +147,8 @@ void Background::update(float delta_time) {
|
|||||||
// Actualiza las nubes
|
// Actualiza las nubes
|
||||||
updateClouds(delta_time);
|
updateClouds(delta_time);
|
||||||
|
|
||||||
// Actualiza timer de hierba
|
// Actualiza el sprite con la hierba
|
||||||
grass_timer_ += delta_time;
|
grass_sprite_->update(delta_time);
|
||||||
|
|
||||||
// Calcula el frame de la hierba (alterna cada GRASS_FRAME_DURATION ms)
|
|
||||||
int grass_frame = static_cast<int>(grass_timer_ / GRASS_FRAME_DURATION) % 2;
|
|
||||||
grass_sprite_->setSpriteClip(0, (10 * grass_frame), 320, 10);
|
|
||||||
|
|
||||||
// Calcula el valor de alpha
|
// Calcula el valor de alpha
|
||||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||||
@@ -415,7 +417,7 @@ void Background::renderBottomClouds() {
|
|||||||
// Compone todos los elementos del fondo en la textura
|
// Compone todos los elementos del fondo en la textura
|
||||||
void Background::fillCanvas() {
|
void Background::fillCanvas() {
|
||||||
// Cambia el destino del renderizador
|
// Cambia el destino del renderizador
|
||||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer_, canvas_);
|
SDL_SetRenderTarget(renderer_, canvas_);
|
||||||
|
|
||||||
// Dibuja el gradiente de fondo
|
// Dibuja el gradiente de fondo
|
||||||
@@ -466,7 +468,7 @@ void Background::setColor(Color color) {
|
|||||||
attenuate_color_ = color;
|
attenuate_color_ = color;
|
||||||
|
|
||||||
// Colorea la textura
|
// Colorea la textura
|
||||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer_, color_texture_);
|
SDL_SetRenderTarget(renderer_, color_texture_);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer_, attenuate_color_.r, attenuate_color_.g, attenuate_color_.b, 255);
|
SDL_SetRenderDrawColor(renderer_, attenuate_color_.r, attenuate_color_.g, attenuate_color_.b, 255);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
class MovingSprite;
|
class MovingSprite;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
class AnimatedSprite;
|
||||||
|
|
||||||
// --- Clase Background: gestiona el fondo de la sección jugable ---
|
// --- Clase Background: gestiona el fondo de la sección jugable ---
|
||||||
class Background {
|
class Background {
|
||||||
@@ -66,13 +67,12 @@ class Background {
|
|||||||
static constexpr float COMPLETION_TRANSITION_DURATION_S = 3.0F; // Duración de la transición de completado en segundos
|
static constexpr float COMPLETION_TRANSITION_DURATION_S = 3.0F; // Duración de la transición de completado en segundos
|
||||||
|
|
||||||
// --- Objetos y punteros ---
|
// --- Objetos y punteros ---
|
||||||
SDL_Renderer *renderer_; // Renderizador de la ventana
|
SDL_Renderer* renderer_; // Renderizador de la ventana
|
||||||
SDL_Texture *canvas_; // Textura para componer el fondo
|
SDL_Texture* canvas_; // Textura para componer el fondo
|
||||||
SDL_Texture *color_texture_; // Textura para atenuar el fondo
|
SDL_Texture* color_texture_; // Textura para atenuar el fondo
|
||||||
std::shared_ptr<Texture> buildings_texture_; // Textura de edificios
|
std::shared_ptr<Texture> buildings_texture_; // Textura de edificios
|
||||||
std::shared_ptr<Texture> top_clouds_texture_; // Textura de nubes superiores
|
std::shared_ptr<Texture> top_clouds_texture_; // Textura de nubes superiores
|
||||||
std::shared_ptr<Texture> bottom_clouds_texture_; // Textura de nubes inferiores
|
std::shared_ptr<Texture> bottom_clouds_texture_; // Textura de nubes inferiores
|
||||||
std::shared_ptr<Texture> grass_texture_; // Textura de hierba
|
|
||||||
std::shared_ptr<Texture> gradients_texture_; // Textura de gradientes
|
std::shared_ptr<Texture> gradients_texture_; // Textura de gradientes
|
||||||
std::shared_ptr<Texture> sun_texture_; // Textura del sol
|
std::shared_ptr<Texture> sun_texture_; // Textura del sol
|
||||||
std::shared_ptr<Texture> moon_texture_; // Textura de la luna
|
std::shared_ptr<Texture> moon_texture_; // Textura de la luna
|
||||||
@@ -82,9 +82,9 @@ class Background {
|
|||||||
std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite de nubes inferiores B
|
std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite de nubes inferiores B
|
||||||
std::unique_ptr<Sprite> buildings_sprite_; // Sprite de edificios
|
std::unique_ptr<Sprite> buildings_sprite_; // Sprite de edificios
|
||||||
std::unique_ptr<Sprite> gradient_sprite_; // Sprite de gradiente
|
std::unique_ptr<Sprite> gradient_sprite_; // Sprite de gradiente
|
||||||
std::unique_ptr<Sprite> grass_sprite_; // Sprite de hierba
|
|
||||||
std::unique_ptr<Sprite> sun_sprite_; // Sprite del sol
|
std::unique_ptr<Sprite> sun_sprite_; // Sprite del sol
|
||||||
std::unique_ptr<Sprite> moon_sprite_; // Sprite de la luna
|
std::unique_ptr<Sprite> moon_sprite_; // Sprite de la luna
|
||||||
|
std::unique_ptr<AnimatedSprite> grass_sprite_; // Sprite con la hierba
|
||||||
|
|
||||||
// --- Variables de configuración ---
|
// --- Variables de configuración ---
|
||||||
const float total_progress_to_complete_; // Progreso total para completar
|
const float total_progress_to_complete_; // Progreso total para completar
|
||||||
@@ -108,8 +108,6 @@ class Background {
|
|||||||
float clouds_speed_ = 0; // Velocidad de las nubes
|
float clouds_speed_ = 0; // Velocidad de las nubes
|
||||||
float transition_ = 0; // Porcentaje de transición
|
float transition_ = 0; // Porcentaje de transición
|
||||||
size_t gradient_number_ = 0; // Índice de fondo degradado
|
size_t gradient_number_ = 0; // Índice de fondo degradado
|
||||||
float grass_timer_ = 0.0f; // Timer para animación de hierba (ms)
|
|
||||||
static constexpr float GRASS_FRAME_DURATION = 333.34f; // Duración por frame de hierba (20 frames * 16.67ms)
|
|
||||||
size_t alpha_color_texture_ = 0; // Transparencia de atenuación
|
size_t alpha_color_texture_ = 0; // Transparencia de atenuación
|
||||||
size_t previous_alpha_color_texture_ = 0; // Transparencia anterior
|
size_t previous_alpha_color_texture_ = 0; // Transparencia anterior
|
||||||
size_t sun_index_ = 0; // Índice del recorrido del sol
|
size_t sun_index_ = 0; // Índice del recorrido del sol
|
||||||
|
|||||||
Reference in New Issue
Block a user