Bullet: ara tenen animació de tres frames, encara que no es nota una puta merda
This commit is contained in:
@@ -62,7 +62,7 @@ notification.color 303030
|
||||
service_menu.title_color 99FF62
|
||||
service_menu.text_color FFFFFF
|
||||
service_menu.selected_color FFDC44
|
||||
service_menu.bg_color 000000F0
|
||||
service_menu.bg_color 003000F5
|
||||
service_menu.drop_shadow false
|
||||
|
||||
## --- INTRO ---
|
||||
|
||||
@@ -62,7 +62,7 @@ notification.color 303030
|
||||
service_menu.title_color 99FF62
|
||||
service_menu.text_color FFFFFF
|
||||
service_menu.selected_color FFDC44
|
||||
service_menu.bg_color 000000F0
|
||||
service_menu.bg_color 000F00F5
|
||||
service_menu.drop_shadow false
|
||||
|
||||
## --- INTRO ---
|
||||
|
||||
44
data/gfx/bullet/bullet.ani
Normal file
44
data/gfx/bullet/bullet.ani
Normal file
@@ -0,0 +1,44 @@
|
||||
frame_width=12
|
||||
frame_height=12
|
||||
|
||||
[animation]
|
||||
name=normal_up
|
||||
speed=5
|
||||
loop=0
|
||||
frames=0,1,2,2,1,0
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_left
|
||||
speed=5
|
||||
loop=0
|
||||
frames=3,4,5,5,4,3
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_right
|
||||
speed=5
|
||||
loop=0
|
||||
frames=6,7,8,8,7,6
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_up
|
||||
speed=5
|
||||
loop=0
|
||||
frames=9,10,11,11,10,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_left
|
||||
speed=5
|
||||
loop=0
|
||||
frames=12,13,14,14,13,12
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_right
|
||||
speed=5
|
||||
loop=0
|
||||
frames=15,16,17,17,26,15
|
||||
[/animation]
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 858 B After Width: | Height: | Size: 2.0 KiB |
@@ -3,11 +3,12 @@
|
||||
#include <memory> // Para unique_ptr, make_unique, shared_ptr
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "sprite.h" // Para Sprite
|
||||
class Texture; // lines 5-5
|
||||
#include "resource.h"
|
||||
class Texture; // lines 5-5
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int owner, std::shared_ptr<Texture> texture)
|
||||
: sprite_(std::make_unique<Sprite>(texture, SDL_FRect{x, y, BULLET_WIDTH_, BULLET_HEIGHT_})),
|
||||
Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("bullet.png"), Resource::get()->getAnimation("bullet.ani"))),
|
||||
pos_x_(x),
|
||||
pos_y_(y),
|
||||
bullet_type_(bullet_type),
|
||||
@@ -17,9 +18,24 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int ow
|
||||
: (bullet_type_ == BulletType::RIGHT) ? BULLET_VEL_X_RIGHT_
|
||||
: 0;
|
||||
|
||||
int sprite_offset = powered_up ? 3 : 0;
|
||||
int offset = (static_cast<int>(bullet_type) + sprite_offset) * BULLET_WIDTH_;
|
||||
sprite_->setSpriteClip(offset, 0, BULLET_WIDTH_, BULLET_HEIGHT_);
|
||||
std::string powered_type = powered ? "powered_" : "normal_";
|
||||
switch (bullet_type)
|
||||
{
|
||||
case BulletType::UP:
|
||||
sprite_->setCurrentAnimation(powered_type + "up");
|
||||
break;
|
||||
|
||||
case BulletType::LEFT:
|
||||
sprite_->setCurrentAnimation(powered_type + "left");
|
||||
break;
|
||||
|
||||
case BulletType::RIGHT:
|
||||
sprite_->setCurrentAnimation(powered_type + "right");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
collider_.r = BULLET_WIDTH_ / 2;
|
||||
shiftColliders();
|
||||
@@ -28,7 +44,15 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int ow
|
||||
// Implementación de render (llama al render del sprite_)
|
||||
void Bullet::render()
|
||||
{
|
||||
sprite_->render();
|
||||
if (bullet_type_ != BulletType::NONE)
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Actualiza el estado del objeto
|
||||
BulletMoveStatus Bullet::update()
|
||||
{
|
||||
sprite_->update();
|
||||
return move();
|
||||
}
|
||||
|
||||
// Implementación del movimiento usando BulletMoveStatus
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture;
|
||||
|
||||
@@ -27,12 +27,12 @@ class Bullet
|
||||
{
|
||||
public:
|
||||
// Constructor y Destructor
|
||||
Bullet(float x, float y, BulletType bullet_type, bool powered_up, int owner, std::shared_ptr<Texture> texture);
|
||||
Bullet(float x, float y, BulletType bullet_type, bool powered, int owner);
|
||||
~Bullet() = default;
|
||||
|
||||
// Métodos principales
|
||||
void render(); // Dibuja la bala en pantalla
|
||||
BulletMoveStatus move(); // Mueve la bala y devuelve su estado
|
||||
void render(); // Dibuja la bala en pantalla
|
||||
BulletMoveStatus update(); // Actualiza el estado del objeto
|
||||
|
||||
// Estado de la bala
|
||||
bool isEnabled() const; // Comprueba si está activa
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
static constexpr float BULLET_VEL_X_RIGHT_ = 2.0f;
|
||||
|
||||
// Propiedades
|
||||
std::unique_ptr<Sprite> sprite_; // Sprite con los gráficos
|
||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
|
||||
|
||||
float pos_x_; // Posición en el eje X
|
||||
float pos_y_; // Posición en el eje Y
|
||||
@@ -62,6 +62,7 @@ private:
|
||||
Circle collider_; // Círculo de colisión
|
||||
|
||||
// Métodos internos
|
||||
void shiftColliders(); // Ajusta el círculo de colisión
|
||||
void shiftSprite(); // Ajusta el sprite
|
||||
void shiftColliders(); // Ajusta el círculo de colisión
|
||||
void shiftSprite(); // Ajusta el sprite
|
||||
BulletMoveStatus move(); // Mueve la bala y devuelve su estado
|
||||
};
|
||||
|
||||
@@ -355,6 +355,7 @@ void Director::setFileList()
|
||||
|
||||
{ // Bala
|
||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
{ // Tabe
|
||||
|
||||
@@ -124,11 +124,6 @@ Game::~Game()
|
||||
// Asigna texturas y animaciones
|
||||
void Game::setResources()
|
||||
{
|
||||
// Texturas
|
||||
{
|
||||
bullet_texture_ = Resource::get()->getTexture("bullet.png");
|
||||
}
|
||||
|
||||
// Texturas - Game_text
|
||||
{
|
||||
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_1000_points"));
|
||||
@@ -638,7 +633,7 @@ void Game::updateBullets()
|
||||
{
|
||||
for (auto &bullet : bullets_)
|
||||
{
|
||||
if (bullet->move() == BulletMoveStatus::OUT)
|
||||
if (bullet->update() == BulletMoveStatus::OUT)
|
||||
{
|
||||
getPlayer(bullet->getOwner())->decScoreMultiplier();
|
||||
}
|
||||
@@ -656,7 +651,7 @@ void Game::renderBullets()
|
||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
|
||||
{
|
||||
bullets_.emplace_back(
|
||||
std::make_unique<Bullet>(x, y, kind, powered_up, owner, bullet_texture_));
|
||||
std::make_unique<Bullet>(x, y, kind, powered_up, owner));
|
||||
}
|
||||
|
||||
// Vacia el vector de balas
|
||||
|
||||
@@ -118,7 +118,6 @@ private:
|
||||
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
|
||||
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los pathsprites
|
||||
|
||||
std::shared_ptr<Texture> bullet_texture_; // Textura para las balas
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores
|
||||
|
||||
|
||||
Reference in New Issue
Block a user