Afegit el disparador per a la aparició del enemic nou
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#include "tabe.h"
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
|
||||
#include <stdlib.h> // Para rand, abs
|
||||
#include <algorithm> // Para max
|
||||
#include "jail_audio.h" // Para JA_PlaySound
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "utils.h" // Para Zone
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdlib.h> // Para rand, abs
|
||||
#include <algorithm> // Para max
|
||||
#include "jail_audio.h" // Para JA_PlaySound
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "utils.h" // Para Zone
|
||||
|
||||
// Constructor
|
||||
Tabe::Tabe()
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))) {}
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))),
|
||||
timer_(TabeTimer(2.5f, 4.0f)) {}
|
||||
|
||||
// Actualiza la lógica
|
||||
void Tabe::update()
|
||||
@@ -21,6 +23,11 @@ void Tabe::update()
|
||||
move();
|
||||
updateState();
|
||||
}
|
||||
timer_.update();
|
||||
if (timer_.should_spawn())
|
||||
{
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto
|
||||
@@ -49,7 +56,7 @@ void Tabe::move()
|
||||
{
|
||||
if (x_ < min_x)
|
||||
{
|
||||
enabled_ = false;
|
||||
disable();
|
||||
}
|
||||
if (x_ > param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH_ && direction_ == TabeDirection::TO_THE_RIGHT)
|
||||
{
|
||||
@@ -63,7 +70,7 @@ void Tabe::move()
|
||||
{
|
||||
if (x_ > max_x)
|
||||
{
|
||||
enabled_ = false;
|
||||
disable();
|
||||
}
|
||||
if (x_ < param.game.game_area.rect.x && direction_ == TabeDirection::TO_THE_LEFT)
|
||||
{
|
||||
@@ -193,10 +200,25 @@ void Tabe::updateState()
|
||||
// Intenta obtener el bonus
|
||||
bool Tabe::tryToGetBonus()
|
||||
{
|
||||
if (has_bonus_ && rand() % std::max(1, 10 - number_of_hits_) == 0)
|
||||
if (has_bonus_ && rand() % std::max(1, 15 - number_of_hits_) == 0)
|
||||
{
|
||||
has_bonus_ = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Actualiza el temporizador
|
||||
void Tabe::updateTimer()
|
||||
{
|
||||
timer_.current_time = SDL_GetTicks();
|
||||
timer_.delta_time = timer_.current_time - timer_.last_time;
|
||||
timer_.last_time = timer_.current_time;
|
||||
}
|
||||
|
||||
// Deshabilita el objeto
|
||||
void Tabe::disable()
|
||||
{
|
||||
enabled_ = false;
|
||||
timer_.reset();
|
||||
}
|
||||
Reference in New Issue
Block a user