Treballant en el enemic nou
This commit is contained in:
@@ -451,6 +451,11 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
{ // Tabe
|
||||
Asset::get()->add(prefix + "/data/gfx/tabe/tabe.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/tabe/tabe.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
{ // Juego
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "smart_sprite.h" // Para SmartSprite
|
||||
#include "stage.h" // Para number, get, Stage, power, total_p...
|
||||
#include "tabe.h" // Para Tabe
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
struct JA_Sound_t; // lines 37-37
|
||||
@@ -46,7 +47,8 @@ Game::Game(int player_id, int current_stage, bool demo)
|
||||
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
balloon_manager_(std::make_unique<BalloonManager>())
|
||||
balloon_manager_(std::make_unique<BalloonManager>()),
|
||||
tabe_(std::make_unique<Tabe>())
|
||||
{
|
||||
// Pasa variables
|
||||
demo_.enabled = demo;
|
||||
@@ -942,6 +944,7 @@ void Game::fillCanvas()
|
||||
renderItems();
|
||||
renderSmartSprites();
|
||||
balloon_manager_->render();
|
||||
tabe_->render();
|
||||
renderBullets();
|
||||
renderPathSprites();
|
||||
renderPlayers();
|
||||
@@ -1207,6 +1210,12 @@ void Game::checkEvents()
|
||||
case SDLK_8:
|
||||
{
|
||||
players_.at(0)->setPlayingState(PlayerState::LEAVING_SCREEN);
|
||||
break;
|
||||
}
|
||||
case SDLK_9:
|
||||
{
|
||||
tabe_->enable();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -1373,7 +1382,7 @@ void Game::handleDemoMode()
|
||||
|
||||
if (input_->checkAnyButtonPressed())
|
||||
{
|
||||
section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal.
|
||||
section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal.
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo
|
||||
return;
|
||||
}
|
||||
@@ -1805,6 +1814,7 @@ void Game::updateGame()
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
balloon_manager_->update();
|
||||
tabe_->update();
|
||||
moveBullets();
|
||||
updateItems();
|
||||
updateStage();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
class Asset; // lines 13-13
|
||||
class Background; // lines 14-14
|
||||
class BalloonManager;
|
||||
class Tabe;
|
||||
class Bullet; // lines 15-15
|
||||
class Fade; // lines 16-16
|
||||
class Input; // lines 17-17
|
||||
@@ -144,6 +145,7 @@ private:
|
||||
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
std::unique_ptr<Tabe> tabe_; // Objeto para gestionar el Tabe Volaor
|
||||
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
|
||||
|
||||
// Variables
|
||||
|
||||
@@ -234,7 +234,6 @@ void Logo::render()
|
||||
void Logo::run()
|
||||
{
|
||||
// Detiene la música
|
||||
//JA_StopMusic();
|
||||
JA_FadeOutMusic(500);
|
||||
|
||||
while (section::name == section::Name::LOGO)
|
||||
|
||||
55
source/tabe.cpp
Normal file
55
source/tabe.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "tabe.h"
|
||||
#include "resource.h"
|
||||
#include "param.h"
|
||||
#include <algorithm>
|
||||
|
||||
// Constructor
|
||||
Tabe::Tabe()
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani")))
|
||||
{
|
||||
}
|
||||
|
||||
// Actualiza la lógica
|
||||
void Tabe::update()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
sprite_->update();
|
||||
move();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto
|
||||
void Tabe::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Mueve el objeto
|
||||
void Tabe::move()
|
||||
{
|
||||
x_ += speed_;
|
||||
const float min_x = param.game.game_area.rect.x;
|
||||
const float max_x = param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH_;
|
||||
if (x_ < min_x || x_ > max_x)
|
||||
{
|
||||
x_ = std::clamp(x_, min_x, max_x);
|
||||
speed_ = -speed_;
|
||||
sprite_->setFlip(speed_ > 0.0f ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
|
||||
}
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Habilita el objeto
|
||||
void Tabe::enable()
|
||||
{
|
||||
enabled_ = true;
|
||||
speed_ = 5.0f;
|
||||
x_ = 50.0f;
|
||||
y_ = 20.0f;
|
||||
sprite_->setFlip(speed_ > 0.0f ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
|
||||
shiftSprite();
|
||||
}
|
||||
44
source/tabe.h
Normal file
44
source/tabe.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "animated_sprite.h"
|
||||
#include <memory>
|
||||
|
||||
// Clase Tabe
|
||||
class Tabe
|
||||
{
|
||||
private:
|
||||
// Constantes
|
||||
static constexpr int WIDTH_ = 32;
|
||||
static constexpr int HEIGHT_ = 32;
|
||||
|
||||
// Punteros
|
||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los graficos y animaciones
|
||||
|
||||
// Variables
|
||||
float x_; // Posición del objeto
|
||||
float y_; // Posición del objeto
|
||||
float speed_; // Velocidad de movimiento del objeto
|
||||
bool enabled_ = false; // Indica si el objeto está activo
|
||||
|
||||
// Mueve el objeto
|
||||
void move();
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
void shiftSprite() { sprite_->setPos(x_, y_); }
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Tabe();
|
||||
|
||||
// Destructor
|
||||
~Tabe() = default;
|
||||
|
||||
// Actualiza la lógica
|
||||
void update();
|
||||
|
||||
// Dibuja el objeto
|
||||
void render();
|
||||
|
||||
// Habilita el objeto
|
||||
void enable();
|
||||
};
|
||||
Reference in New Issue
Block a user