feat: implemented revolver
This commit is contained in:
		
							parent
							
								
									47970091ff
								
							
						
					
					
						commit
						945baf0994
					
				| 
						 | 
				
			
			@ -5,6 +5,7 @@
 | 
			
		|||
#include "scene/resources/packed_scene.h"
 | 
			
		||||
 | 
			
		||||
void HitscanMuzzle::_bind_methods() {
 | 
			
		||||
	ClassDB::bind_method(D_METHOD("shoot"), &self_type::shoot);
 | 
			
		||||
	BIND_PROPERTY(Variant::FLOAT, spread);
 | 
			
		||||
	BIND_PROPERTY(Variant::INT, damage);
 | 
			
		||||
	BIND_PROPERTY(Variant::INT, ray_count);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,13 @@
 | 
			
		|||
#include "revolver.h"
 | 
			
		||||
#include "scene/animation/animation_player.h"
 | 
			
		||||
#include "wave_survival/macros.h"
 | 
			
		||||
#include "wave_survival/player_camera.h"
 | 
			
		||||
#include "wave_survival/player_input.h"
 | 
			
		||||
 | 
			
		||||
void Revolver::_bind_methods() {
 | 
			
		||||
	ClassDB::bind_method(D_METHOD("start_recoil"), &self_type::start_recoil);
 | 
			
		||||
	BIND_PROPERTY(Variant::FLOAT, single_action_spread);
 | 
			
		||||
	BIND_PROPERTY(Variant::FLOAT, double_action_spread);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::play_equip_anim() {
 | 
			
		||||
| 
						 | 
				
			
			@ -14,14 +18,25 @@ void Revolver::play_equip_anim() {
 | 
			
		|||
 | 
			
		||||
void Revolver::shoot() {
 | 
			
		||||
	if (!is_animating()) {
 | 
			
		||||
		this->muzzle->shoot();
 | 
			
		||||
		if (this->alt_active) {
 | 
			
		||||
			get_anim()->queue("fire_single");
 | 
			
		||||
			get_anim()->queue("idle_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");
 | 
			
		||||
			get_anim()->queue("idle_double");
 | 
			
		||||
		}
 | 
			
		||||
		get_anim()->queue("idle_double");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::cock_hammer() {
 | 
			
		||||
	if (!this->alt_active && !is_animating()) {
 | 
			
		||||
		this->alt_active = true;
 | 
			
		||||
		get_anim()->queue("to_single");
 | 
			
		||||
		get_anim()->queue("idle_single");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +47,9 @@ void Revolver::on_primary_fire(bool pressed) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::on_alt_mode(bool pressed) {
 | 
			
		||||
	this->alt_requested = pressed;
 | 
			
		||||
	if (!this->alt_active && pressed) {
 | 
			
		||||
		cock_hammer();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::ready() {
 | 
			
		||||
| 
						 | 
				
			
			@ -43,11 +60,12 @@ void Revolver::ready() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::process(double delta) {
 | 
			
		||||
	String const current{ get_anim()->get_current_animation() };
 | 
			
		||||
	double animation_time{ get_anim()->get_current_animation_position() };
 | 
			
		||||
	if (current == "fire_single" || current == "fire_double") {
 | 
			
		||||
		double t{ animation_time / this->recoil_time };
 | 
			
		||||
		get_camera()->recoil(Math::lerp((double)this->recoil_force, 0.0, CLAMP(t, 0.0, 1.0)) * delta);
 | 
			
		||||
	//String const current{ get_anim()->get_current_animation() };
 | 
			
		||||
	//double animation_time{ get_anim()->get_current_animation_position() };
 | 
			
		||||
	if (this->recoil_timer > 0.0) {
 | 
			
		||||
		this->recoil_timer -= 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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -71,3 +89,27 @@ void Revolver::_notification(int what) {
 | 
			
		|||
void Revolver::notify_selected() {
 | 
			
		||||
	play_equip_anim();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Revolver::allows_running() const {
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::start_recoil() {
 | 
			
		||||
	this->recoil_timer = this->recoil_time;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::set_single_action_spread(float value) {
 | 
			
		||||
	this->single_action_spread = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float Revolver::get_single_action_spread() const {
 | 
			
		||||
	return this->single_action_spread;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Revolver::set_double_action_spread(float value) {
 | 
			
		||||
	this->double_action_spread = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float Revolver::get_double_action_spread() const {
 | 
			
		||||
	return this->double_action_spread;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,7 @@ class Revolver : public WeaponBase {
 | 
			
		|||
	static void _bind_methods();
 | 
			
		||||
	void play_equip_anim();
 | 
			
		||||
	void shoot();
 | 
			
		||||
	void cock_hammer();
 | 
			
		||||
	void on_primary_fire(bool pressed);
 | 
			
		||||
	void on_alt_mode(bool pressed);
 | 
			
		||||
	void ready();
 | 
			
		||||
| 
						 | 
				
			
			@ -17,14 +18,24 @@ class Revolver : public WeaponBase {
 | 
			
		|||
protected:
 | 
			
		||||
	void _notification(int what);
 | 
			
		||||
	virtual void notify_selected() override;
 | 
			
		||||
	virtual bool allows_running() const override;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	void start_recoil();
 | 
			
		||||
	void set_single_action_spread(float value);
 | 
			
		||||
	float get_single_action_spread() const;
 | 
			
		||||
	void set_double_action_spread(float value);
 | 
			
		||||
	float get_double_action_spread() const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	bool alt_requested{ false };
 | 
			
		||||
	float single_action_spread{ 0.01f };
 | 
			
		||||
	float double_action_spread{ 0.03f };
 | 
			
		||||
	bool alt_active{ false };
 | 
			
		||||
	HitscanMuzzle *muzzle{ nullptr };
 | 
			
		||||
 | 
			
		||||
	float recoil_force{ 2.f };
 | 
			
		||||
	float recoil_time{ 0.06f };
 | 
			
		||||
	double recoil_time{ 0.06 };
 | 
			
		||||
	double recoil_timer{ 0.0 };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // !WEAPONS_REVOLVER_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/equip.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/equip.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/fire_double.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/fire_double.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/fire_single.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/fire_single.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/idle_double.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/idle_double.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/idle_single.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/idle_single.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/to_single.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								project/assets/animations/weapons/revolver/to_single.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in a new issue