feat: added delay to chase -> fire transition
This commit is contained in:
parent
4e6751a832
commit
5c00f882f4
2 changed files with 26 additions and 3 deletions
|
|
@ -56,11 +56,29 @@ String RiflemanPatrolState::get_next_state() const {
|
|||
return get_class();
|
||||
}
|
||||
|
||||
String RiflemanChaseState::get_next_state() const {
|
||||
void RiflemanChaseState::enter_state() {
|
||||
super_type::enter_state();
|
||||
if (get_body()->get_detector()->line_of_sight_exists()) {
|
||||
return RiflemanFireState::get_class_static();
|
||||
this->fire_timer = 0.3;
|
||||
} else {
|
||||
this->fire_timer = 0.0;
|
||||
}
|
||||
}
|
||||
void RiflemanChaseState::process(double delta) {
|
||||
super_type::process(delta);
|
||||
if (get_body()->get_detector()->line_of_sight_exists()) {
|
||||
this->fire_timer += delta;
|
||||
} else {
|
||||
this->fire_timer = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
String RiflemanChaseState::get_next_state() const {
|
||||
if (this->fire_timer >= 0.3) {
|
||||
return RiflemanFireState::get_class_static();
|
||||
} else {
|
||||
return get_class();
|
||||
}
|
||||
return get_class();
|
||||
}
|
||||
|
||||
void RiflemanFireState::enter_state() {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,12 @@ class RiflemanChaseState : public EnemyChaseState {
|
|||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
void enter_state() override;
|
||||
void process(double delta) override;
|
||||
String get_next_state() const override;
|
||||
|
||||
private:
|
||||
double fire_timer{ 0.0 };
|
||||
};
|
||||
|
||||
class RiflemanFireState : public RiflemanState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue