feat: implemented rifle reload with placeholder anim
This commit is contained in:
parent
150231c67c
commit
68abfdd383
25 changed files with 26775 additions and 3 deletions
|
|
@ -9,6 +9,9 @@ void WeaponBase::_bind_methods() {
|
|||
BIND_HPROPERTY(Variant::OBJECT, anim, PROPERTY_HINT_NODE_TYPE, AnimationPlayer::get_class_static());
|
||||
BIND_PROPERTY(Variant::INT, max_ammo);
|
||||
BIND_PROPERTY(Variant::INT, loaded_ammo);
|
||||
ClassDB::bind_method(D_METHOD("reload_full"), &self_type::reload_full);
|
||||
ClassDB::bind_method(D_METHOD("reload_num", "num"), &self_type::reload_num);
|
||||
ClassDB::bind_method(D_METHOD("ammo_empty"), &self_type::ammo_empty);
|
||||
}
|
||||
|
||||
void WeaponBase::ready() {
|
||||
|
|
@ -91,3 +94,19 @@ bool WeaponBase::try_use_ammo(int amount) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool WeaponBase::ammo_empty() const {
|
||||
return this->loaded_ammo <= 0;
|
||||
}
|
||||
|
||||
void WeaponBase::reload_full() {
|
||||
// TODO: take difference between loaded and max out of inventory
|
||||
set_loaded_ammo(this->max_ammo);
|
||||
}
|
||||
|
||||
void WeaponBase::reload_num(int num) {
|
||||
int const space{ this->max_ammo - this->loaded_ammo };
|
||||
num = MIN(num, space);
|
||||
// TODO: take num out of ammo inventory
|
||||
set_loaded_ammo(this->loaded_ammo + num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ public:
|
|||
void set_loaded_ammo(int amount);
|
||||
int get_loaded_ammo() const;
|
||||
bool try_use_ammo(int amount = 1);
|
||||
bool ammo_empty() const;
|
||||
void reload_full();
|
||||
void reload_num(int num);
|
||||
|
||||
virtual bool allows_running() const { return false; }
|
||||
virtual bool allows_jumping() const { return true; }
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void Rifle::exit_run() {
|
|||
}
|
||||
|
||||
void Rifle::shoot() {
|
||||
if (!is_animating()) {
|
||||
if (!is_animating() && try_use_ammo()) {
|
||||
this->muzzle->shoot();
|
||||
if (this->request_alt_mode) {
|
||||
get_anim()->queue("fire_aim");
|
||||
|
|
@ -52,6 +52,16 @@ void Rifle::shoot() {
|
|||
}
|
||||
}
|
||||
|
||||
void Rifle::start_reload_animation() {
|
||||
if (!is_animating() && get_loaded_ammo() != get_max_ammo()) {
|
||||
if (this->in_alt_mode) {
|
||||
get_anim()->queue("aim_to_hip");
|
||||
}
|
||||
get_anim()->queue("reload");
|
||||
get_anim()->queue("hip");
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::play_equip_anim() {
|
||||
get_anim()->play("equip", 0.0);
|
||||
get_anim()->queue("hip");
|
||||
|
|
@ -68,6 +78,10 @@ void Rifle::on_alt_mode(bool alt_mode) {
|
|||
this->request_alt_mode = alt_mode;
|
||||
}
|
||||
|
||||
void Rifle::on_reload() {
|
||||
start_reload_animation();
|
||||
}
|
||||
|
||||
void Rifle::on_animation_changed(String new_animation) {
|
||||
if (new_animation == "aim") {
|
||||
this->in_alt_mode = true;
|
||||
|
|
@ -85,6 +99,7 @@ void Rifle::ready() {
|
|||
get_anim()->connect("current_animation_changed", callable_mp(this, &self_type::on_animation_changed));
|
||||
get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
|
||||
get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
|
||||
get_input()->connect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));
|
||||
play_equip_anim();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,12 @@ class Rifle : public WeaponBase {
|
|||
void queue_enter_run();
|
||||
void exit_run();
|
||||
void shoot();
|
||||
void start_reload_animation();
|
||||
void play_equip_anim();
|
||||
void on_primary_fire(bool down);
|
||||
void on_alt_mode(bool alt_mode);
|
||||
void on_reload();
|
||||
void on_animation_changed(String new_anim);
|
||||
void on_run_input(bool run);
|
||||
void ready();
|
||||
void process(double delta);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue