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
|
||||
DATA|${PREFIX}/data/shaders/crtpi_vertex_es.glsl|optional
|
||||
DATA|${PREFIX}/data/shaders/crtpi_fragment_es.glsl|optional
|
||||
|
||||
# Texturas - Balloons
|
||||
ANIMATION|${PREFIX}/data/gfx/balloon/balloon0.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_clouds1.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_moon.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,13 +7,14 @@
|
||||
#include <cmath> // Para M_PI, cos, sin
|
||||
#include <utility>
|
||||
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
#include "param.h" // Para Param, ParamBackground, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para funciones de easing
|
||||
#include "animated_sprite.h" // Para MovingSprite
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
#include "param.h" // Para Param, ParamBackground, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para funciones de easing
|
||||
|
||||
// Constructor
|
||||
Background::Background(float total_progress_to_complete)
|
||||
@@ -22,10 +23,10 @@ Background::Background(float total_progress_to_complete)
|
||||
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.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")),
|
||||
sun_texture_(Resource::get()->getTexture("game_sun.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),
|
||||
progress_per_stage_(total_progress_to_complete_ / STAGES),
|
||||
@@ -88,7 +89,6 @@ void Background::initializeSprites() {
|
||||
|
||||
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
|
||||
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_);
|
||||
moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
|
||||
}
|
||||
@@ -96,8 +96,8 @@ void Background::initializeSprites() {
|
||||
// Configura las propiedades iniciales de los sprites
|
||||
void Background::initializeSpriteProperties() {
|
||||
// Velocidades iniciales que coinciden con updateCloudsSpeed() cuando progress=0
|
||||
constexpr float INITIAL_TOP_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (coincide con CLOUDS_INITIAL_SPEED)
|
||||
constexpr float INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F / 2.0F; // 1.5 píxeles/segundo (mitad de velocidad)
|
||||
constexpr float INITIAL_TOP_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (coincide con CLOUDS_INITIAL_SPEED)
|
||||
constexpr float INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F / 2.0F; // 1.5 píxeles/segundo (mitad de velocidad)
|
||||
|
||||
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_a_->setVelX(-INITIAL_TOP_CLOUDS_SPEED_PX_PER_S);
|
||||
@@ -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_->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());
|
||||
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
||||
sun_sprite_->setPosition(sun_path_.front());
|
||||
moon_sprite_->setPosition(moon_path_.front());
|
||||
}
|
||||
@@ -141,12 +147,8 @@ void Background::update(float delta_time) {
|
||||
// Actualiza las nubes
|
||||
updateClouds(delta_time);
|
||||
|
||||
// Actualiza timer de hierba
|
||||
grass_timer_ += 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);
|
||||
// Actualiza el sprite con la hierba
|
||||
grass_sprite_->update(delta_time);
|
||||
|
||||
// Calcula el valor de alpha
|
||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||
@@ -309,9 +311,9 @@ void Background::updateProgression(float delta_time) {
|
||||
// Actualiza la velocidad de las nubes según el estado y progresión
|
||||
void Background::updateCloudsSpeed() {
|
||||
// Cálculo de velocidad según progreso (convertido de frame-based a time-based)
|
||||
constexpr float CLOUDS_INITIAL_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (era 0.05 px/frame @ 60fps)
|
||||
constexpr float CLOUDS_TOTAL_SPEED_PX_PER_S = 2.00F * 60.0F; // 120.0 píxeles/segundo (era 2.00 px/frame @ 60fps)
|
||||
constexpr float CLOUDS_FINAL_SPEED_RANGE_PX_PER_S = CLOUDS_TOTAL_SPEED_PX_PER_S - CLOUDS_INITIAL_SPEED_PX_PER_S; // 117.0 píxeles/segundo
|
||||
constexpr float CLOUDS_INITIAL_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (era 0.05 px/frame @ 60fps)
|
||||
constexpr float CLOUDS_TOTAL_SPEED_PX_PER_S = 2.00F * 60.0F; // 120.0 píxeles/segundo (era 2.00 px/frame @ 60fps)
|
||||
constexpr float CLOUDS_FINAL_SPEED_RANGE_PX_PER_S = CLOUDS_TOTAL_SPEED_PX_PER_S - CLOUDS_INITIAL_SPEED_PX_PER_S; // 117.0 píxeles/segundo
|
||||
|
||||
// Velocidad base según progreso (de -3.0 a -120.0 píxeles/segundo, igual que la versión original)
|
||||
float base_clouds_speed = (-CLOUDS_INITIAL_SPEED_PX_PER_S) +
|
||||
@@ -415,7 +417,7 @@ void Background::renderBottomClouds() {
|
||||
// Compone todos los elementos del fondo en la textura
|
||||
void Background::fillCanvas() {
|
||||
// Cambia el destino del renderizador
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, canvas_);
|
||||
|
||||
// Dibuja el gradiente de fondo
|
||||
@@ -466,7 +468,7 @@ void Background::setColor(Color color) {
|
||||
attenuate_color_ = color;
|
||||
|
||||
// Colorea la textura
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, color_texture_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer_, attenuate_color_.r, attenuate_color_.g, attenuate_color_.b, 255);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
class MovingSprite;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
class AnimatedSprite;
|
||||
|
||||
// --- Clase Background: gestiona el fondo de la sección jugable ---
|
||||
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
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
SDL_Renderer *renderer_; // Renderizador de la ventana
|
||||
SDL_Texture *canvas_; // Textura para componer el fondo
|
||||
SDL_Texture *color_texture_; // Textura para atenuar el fondo
|
||||
SDL_Renderer* renderer_; // Renderizador de la ventana
|
||||
SDL_Texture* canvas_; // Textura para componer el fondo
|
||||
SDL_Texture* color_texture_; // Textura para atenuar el fondo
|
||||
std::shared_ptr<Texture> buildings_texture_; // Textura de edificios
|
||||
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> grass_texture_; // Textura de hierba
|
||||
std::shared_ptr<Texture> gradients_texture_; // Textura de gradientes
|
||||
std::shared_ptr<Texture> sun_texture_; // Textura del sol
|
||||
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<Sprite> buildings_sprite_; // Sprite de edificios
|
||||
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> moon_sprite_; // Sprite de la luna
|
||||
std::unique_ptr<AnimatedSprite> grass_sprite_; // Sprite con la hierba
|
||||
|
||||
// --- Variables de configuración ---
|
||||
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 transition_ = 0; // Porcentaje de transición
|
||||
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 previous_alpha_color_texture_ = 0; // Transparencia anterior
|
||||
size_t sun_index_ = 0; // Índice del recorrido del sol
|
||||
|
||||
Reference in New Issue
Block a user