Treballant en el enemic nou
This commit is contained in:
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();
|
||||
}
|
||||
Reference in New Issue
Block a user