feat: implemented run animation for revolver
This commit is contained in:
parent
66aede32bd
commit
2d720a983a
7 changed files with 109 additions and 23 deletions
|
|
@ -107,7 +107,7 @@ bool PlayerBody::get_is_running() const {
|
|||
}
|
||||
|
||||
bool PlayerBody::get_wants_to_run() const {
|
||||
return this->try_running && this->movement_input.y > 0.f && this->is_on_floor();
|
||||
return this->try_running && this->movement_input.y > 0.f;
|
||||
}
|
||||
|
||||
HealthStatus *PlayerBody::get_health() const {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "revolver.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "wave_survival/macros.h"
|
||||
#include "wave_survival/player_body.h"
|
||||
#include "wave_survival/player_camera.h"
|
||||
#include "wave_survival/player_input.h"
|
||||
|
||||
|
|
@ -10,33 +11,67 @@ void Revolver::_bind_methods() {
|
|||
BIND_PROPERTY(Variant::FLOAT, double_action_spread);
|
||||
}
|
||||
|
||||
void Revolver::play_equip_anim() {
|
||||
get_anim()->play("equip", 0.0);
|
||||
get_anim()->queue("idle_double");
|
||||
get_anim()->advance(0.0);
|
||||
}
|
||||
|
||||
void Revolver::shoot() {
|
||||
if (!is_animating()) {
|
||||
if (this->alt_active) {
|
||||
get_anim()->queue("fire_single");
|
||||
this->alt_active = false;
|
||||
this->muzzle->set_spread(this->single_action_spread);
|
||||
this->muzzle->shoot();
|
||||
start_recoil();
|
||||
} else {
|
||||
this->muzzle->set_spread(this->double_action_spread);
|
||||
get_anim()->queue("fire_double");
|
||||
}
|
||||
void Revolver::queue_idle_anim() {
|
||||
if (get_anim()->get_current_animation() == "run") {
|
||||
stop_running();
|
||||
}
|
||||
// set a delay between the end of an action and (re)starting the run animation
|
||||
this->run_animation_timer = this->run_animation_delay;
|
||||
if (this->alt_active == true) {
|
||||
get_anim()->queue("idle_single");
|
||||
} else {
|
||||
get_anim()->queue("idle_double");
|
||||
}
|
||||
}
|
||||
|
||||
void Revolver::start_running() {
|
||||
if (this->run_animation_timer <= 0.0) {
|
||||
get_anim()->queue("run");
|
||||
}
|
||||
}
|
||||
|
||||
void Revolver::stop_running() {
|
||||
String const current{ get_anim()->get_current_animation() };
|
||||
|
||||
if (current == "run") {
|
||||
get_anim()->stop();
|
||||
}
|
||||
if (current.begins_with("run")) {
|
||||
if (this->alt_active) {
|
||||
get_anim()->queue("run_to_single");
|
||||
} else {
|
||||
get_anim()->queue("run_to_double");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Revolver::play_equip_anim() {
|
||||
get_anim()->play("equip", 0.0);
|
||||
queue_idle_anim();
|
||||
get_anim()->advance(0.0);
|
||||
}
|
||||
|
||||
void Revolver::shoot() {
|
||||
if (animation_is_idle()) {
|
||||
stop_running();
|
||||
if (this->alt_active) {
|
||||
this->alt_active = false;
|
||||
this->muzzle->set_spread(this->single_action_spread);
|
||||
get_anim()->queue("fire_single");
|
||||
} else {
|
||||
this->muzzle->set_spread(this->double_action_spread);
|
||||
get_anim()->queue("fire_double");
|
||||
}
|
||||
queue_idle_anim();
|
||||
}
|
||||
}
|
||||
|
||||
void Revolver::cock_hammer() {
|
||||
if (!this->alt_active && !is_animating()) {
|
||||
if (!this->alt_active && animation_is_idle()) {
|
||||
stop_running();
|
||||
this->alt_active = true;
|
||||
get_anim()->queue("to_single");
|
||||
get_anim()->queue("idle_single");
|
||||
queue_idle_anim();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +102,18 @@ void Revolver::process(double delta) {
|
|||
double t{ 1.0 - CLAMP(this->recoil_timer / this->recoil_time, 0.0, 1.0) };
|
||||
get_camera()->recoil(Math::lerp((double)this->recoil_force, 0.0, t) * delta);
|
||||
}
|
||||
if (this->run_animation_timer > 0.0) {
|
||||
this->run_animation_timer -= delta;
|
||||
}
|
||||
if (!is_animating() && get_body()->get_is_running()) {
|
||||
start_running();
|
||||
} else if (!get_body()->get_is_running() && get_anim()->get_current_animation() == "run") {
|
||||
queue_idle_anim();
|
||||
}
|
||||
}
|
||||
|
||||
bool Revolver::animation_is_idle() const {
|
||||
return !is_animating() || get_anim()->get_current_animation() == "run";
|
||||
}
|
||||
|
||||
void Revolver::_notification(int what) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
class Revolver : public WeaponBase {
|
||||
GDCLASS(Revolver, WeaponBase);
|
||||
static void _bind_methods();
|
||||
void queue_idle_anim();
|
||||
void start_running();
|
||||
void stop_running();
|
||||
void interrupt_running();
|
||||
void play_equip_anim();
|
||||
void shoot();
|
||||
void cock_hammer();
|
||||
|
|
@ -15,6 +19,8 @@ class Revolver : public WeaponBase {
|
|||
void ready();
|
||||
void process(double delta);
|
||||
|
||||
bool animation_is_idle() const;
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
virtual void notify_selected() override;
|
||||
|
|
@ -34,8 +40,11 @@ private:
|
|||
HitscanMuzzle *muzzle{ nullptr };
|
||||
|
||||
float recoil_force{ 2.f };
|
||||
double recoil_time{ 0.06 };
|
||||
double recoil_time{ 0.1 };
|
||||
double recoil_timer{ 0.0 };
|
||||
|
||||
double run_animation_delay{ 0.3 };
|
||||
double run_animation_timer{ 0.0 };
|
||||
};
|
||||
|
||||
#endif // !WEAPONS_REVOLVER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue