diff --git a/modules/wave_survival/player_input.cpp b/modules/wave_survival/player_input.cpp index 6aa1ae65..4ddce21c 100644 --- a/modules/wave_survival/player_input.cpp +++ b/modules/wave_survival/player_input.cpp @@ -10,6 +10,7 @@ String PlayerInput::sig_run{ "run" }; String PlayerInput::sig_jump{ "jump" }; String PlayerInput::sig_crouch{ "crouch" }; String PlayerInput::sig_activate{ "activate" }; +String PlayerInput::sig_reload{ "reload" }; void PlayerInput::_bind_methods() { ADD_SIGNAL(MethodInfo(sig_movement_input, PropertyInfo(Variant::VECTOR2, "axes"))); @@ -21,6 +22,7 @@ void PlayerInput::_bind_methods() { ADD_SIGNAL(MethodInfo(sig_jump)); ADD_SIGNAL(MethodInfo(sig_crouch, PropertyInfo(Variant::BOOL, "is_crouching"))); ADD_SIGNAL(MethodInfo(sig_activate)); + ADD_SIGNAL(MethodInfo(sig_reload)); } void PlayerInput::normalize_input() { @@ -88,4 +90,7 @@ void PlayerInput::unhandled_input(Ref const &event) { if (event->is_action("activate") && event->is_pressed()) { emit_signal(sig_activate); } + if (event->is_action("reload") && event->is_pressed()) { + emit_signal(sig_reload); + } } diff --git a/modules/wave_survival/player_input.h b/modules/wave_survival/player_input.h index 3132e98e..83c11c9f 100644 --- a/modules/wave_survival/player_input.h +++ b/modules/wave_survival/player_input.h @@ -20,6 +20,7 @@ public: static String sig_jump; static String sig_crouch; static String sig_activate; + static String sig_reload; private: bool was_paused{ false }; diff --git a/modules/wave_survival/weapon_base.cpp b/modules/wave_survival/weapon_base.cpp index 604122a9..2dadf269 100644 --- a/modules/wave_survival/weapon_base.cpp +++ b/modules/wave_survival/weapon_base.cpp @@ -7,6 +7,8 @@ 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); } void WeaponBase::ready() { @@ -64,3 +66,28 @@ void WeaponBase::set_body(PlayerBody *body) { PlayerBody *WeaponBase::get_body() const { return this->body; } + +void WeaponBase::set_max_ammo(int amount) { + this->max_ammo = amount; +} + +int WeaponBase::get_max_ammo() const { + return MAX(0, this->max_ammo); +} + +void WeaponBase::set_loaded_ammo(int amount) { + this->loaded_ammo = CLAMP(amount, 0, this->max_ammo); +} + +int WeaponBase::get_loaded_ammo() const { + return this->loaded_ammo; +} + +bool WeaponBase::try_use_ammo(int amount) { + if (this->loaded_ammo >= amount) { + loaded_ammo -= amount; + return true; + } else { + return false; + } +} diff --git a/modules/wave_survival/weapon_base.h b/modules/wave_survival/weapon_base.h index 4d46558a..94ba4b5c 100644 --- a/modules/wave_survival/weapon_base.h +++ b/modules/wave_survival/weapon_base.h @@ -26,6 +26,12 @@ public: void set_body(PlayerBody *body); PlayerBody *get_body() const; + void set_max_ammo(int amount); + int get_max_ammo() const; + void set_loaded_ammo(int amount); + int get_loaded_ammo() const; + bool try_use_ammo(int amount = 1); + virtual bool allows_running() const { return false; } virtual bool allows_jumping() const { return true; } virtual void notify_selected() {} @@ -35,6 +41,9 @@ private: AnimationPlayer *anim{ nullptr }; PlayerCamera *camera{ nullptr }; PlayerBody *body{ nullptr }; + + int loaded_ammo{ 0 }; + int max_ammo{ 1 }; }; #endif // !WEAPON_BASE_H diff --git a/modules/wave_survival/weapon_inventory.h b/modules/wave_survival/weapon_inventory.h index 92d7e3ff..b2335e1a 100644 --- a/modules/wave_survival/weapon_inventory.h +++ b/modules/wave_survival/weapon_inventory.h @@ -35,6 +35,9 @@ private: WeaponBase *current_weapon{ nullptr }; Ref starting_weapon{}; + + int pistol_ammo{ 60 }; + int rifle_ammo{ 0 }; }; #endif // !WEAPON_INVENTORY_H diff --git a/modules/wave_survival/weapons/revolver.cpp b/modules/wave_survival/weapons/revolver.cpp index f541b515..decff438 100644 --- a/modules/wave_survival/weapons/revolver.cpp +++ b/modules/wave_survival/weapons/revolver.cpp @@ -26,6 +26,11 @@ void Revolver::queue_idle_anim() { void Revolver::start_running() { if (this->run_animation_timer <= 0.0) { + if (this->alt_active) { + get_anim()->queue("single_to_run"); + } else { + get_anim()->queue("double_to_run"); + } get_anim()->queue("run"); } } @@ -36,7 +41,7 @@ void Revolver::stop_running() { if (current == "run") { get_anim()->stop(); } - if (current.begins_with("run")) { + if (current.begins_with("run") || current.ends_with("run")) { if (this->alt_active) { get_anim()->queue("run_to_single"); } else { @@ -87,10 +92,14 @@ void Revolver::on_alt_mode(bool pressed) { } } +void Revolver::on_reload() { +} + void Revolver::ready() { this->muzzle = cast_to(get_node(NodePath("%HitscanMuzzle"))); 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(); } diff --git a/modules/wave_survival/weapons/revolver.h b/modules/wave_survival/weapons/revolver.h index fddbc2e6..23a9a907 100644 --- a/modules/wave_survival/weapons/revolver.h +++ b/modules/wave_survival/weapons/revolver.h @@ -16,6 +16,7 @@ class Revolver : public WeaponBase { void cock_hammer(); void on_primary_fire(bool pressed); void on_alt_mode(bool pressed); + void on_reload(); void ready(); void process(double delta); @@ -43,7 +44,7 @@ private: double recoil_time{ 0.1 }; double recoil_timer{ 0.0 }; - double run_animation_delay{ 0.3 }; + double run_animation_delay{ 0.8 }; double run_animation_timer{ 0.0 }; }; diff --git a/project/assets/animations/weapons/revolver/equip.res b/project/assets/animations/weapons/revolver/equip.res index 46321af7..2c0209c5 100644 Binary files a/project/assets/animations/weapons/revolver/equip.res and b/project/assets/animations/weapons/revolver/equip.res differ diff --git a/project/assets/animations/weapons/revolver/fire_double.res b/project/assets/animations/weapons/revolver/fire_double.res index cd11fa3c..3380315c 100644 Binary files a/project/assets/animations/weapons/revolver/fire_double.res and b/project/assets/animations/weapons/revolver/fire_double.res differ diff --git a/project/assets/animations/weapons/revolver/fire_single.res b/project/assets/animations/weapons/revolver/fire_single.res index 95b43885..ed38652e 100644 Binary files a/project/assets/animations/weapons/revolver/fire_single.res and b/project/assets/animations/weapons/revolver/fire_single.res differ diff --git a/project/assets/animations/weapons/revolver/idle_double.res b/project/assets/animations/weapons/revolver/idle_double.res index fb5c3d4f..94e274ed 100644 Binary files a/project/assets/animations/weapons/revolver/idle_double.res and b/project/assets/animations/weapons/revolver/idle_double.res differ diff --git a/project/assets/animations/weapons/revolver/idle_single.res b/project/assets/animations/weapons/revolver/idle_single.res index ea0f063a..9721d0ab 100644 Binary files a/project/assets/animations/weapons/revolver/idle_single.res and b/project/assets/animations/weapons/revolver/idle_single.res differ diff --git a/project/assets/animations/weapons/revolver/to_single.res b/project/assets/animations/weapons/revolver/to_single.res index eee2a188..6ac86514 100644 Binary files a/project/assets/animations/weapons/revolver/to_single.res and b/project/assets/animations/weapons/revolver/to_single.res differ diff --git a/project/assets/models/weapons/revolver.blend b/project/assets/models/weapons/revolver.blend index 7cb825cb..cf630756 100644 Binary files a/project/assets/models/weapons/revolver.blend and b/project/assets/models/weapons/revolver.blend differ diff --git a/project/assets/models/weapons/revolver.blend1 b/project/assets/models/weapons/revolver.blend1 index 27b723dc..f37dc158 100644 Binary files a/project/assets/models/weapons/revolver.blend1 and b/project/assets/models/weapons/revolver.blend1 differ diff --git a/project/objects/weapons/revolver.tscn b/project/objects/weapons/revolver.tscn index 83a825b9..7262dc90 100644 --- a/project/objects/weapons/revolver.tscn +++ b/project/objects/weapons/revolver.tscn @@ -16,36 +16,6 @@ double_action_spread = 0.02 [node name="revolver" parent="." instance=ExtResource("1_5ynga")] -[node name="Skeleton3D" parent="revolver/Character" index="0"] -bones/1/position = Vector3(0.077683, 0.15356629, 0.22951864) -bones/1/rotation = Quaternion(0.5851843, 0.4764963, 0.47324383, -0.45447868) -bones/2/rotation = Quaternion(-0.37339994, -0.012608625, 0.4248388, 0.8245759) -bones/3/rotation = Quaternion(0.13469099, 0.084066905, 0.5777786, 0.8006018) -bones/4/rotation = Quaternion(0.2787549, 0.10335517, 0.061925787, 0.9527742) -bones/5/rotation = Quaternion(-0.16385715, 0.07371643, -0.117167264, 0.9767234) -bones/6/rotation = Quaternion(-0.10018807, 0.001737441, -0.017251449, 0.99481744) -bones/7/rotation = Quaternion(-5.5135492e-06, -8.1514554e-07, -0.000472692, 0.9999999) -bones/8/rotation = Quaternion(-0.67974395, 0.15276042, 0.07346374, 0.7135934) -bones/9/rotation = Quaternion(-0.52413255, -0.0052551557, 0.008540811, 0.85157764) -bones/10/rotation = Quaternion(-0.45302963, 0.0016381529, -0.0032266718, 0.89148813) -bones/11/rotation = Quaternion(-0.6447599, 0.17695156, 0.030249279, 0.74300593) -bones/12/rotation = Quaternion(-0.61815894, -0.0058423695, 0.008146204, 0.78598917) -bones/13/rotation = Quaternion(-0.28957173, 0.0008908786, -0.0035062442, 0.95714945) -bones/14/rotation = Quaternion(-0.4137267, 0.18337816, -0.055713132, 0.88999933) -bones/15/rotation = Quaternion(-0.56248397, 0.008516232, 0.01857911, 0.82655555) -bones/16/rotation = Quaternion(-0.5171131, -0.003298891, -0.013025877, 0.8558117) -bones/17/position = Vector3(-0.035217345, 0.031610142, 0.010926659) -bones/17/rotation = Quaternion(-0.23086587, 0.40491727, 0.5210391, 0.7150253) -bones/18/rotation = Quaternion(-0.027613077, -0.014708879, 0.040168725, 0.998703) -bones/19/rotation = Quaternion(0.008477317, 0.0136856465, -0.3318223, 0.9432046) -bones/20/rotation = Quaternion(0.5851843, -0.4764963, -0.47324383, -0.45447868) -bones/39/position = Vector3(0.09835215, -0.26794472, -0.3457696) -bones/39/rotation = Quaternion(0.24137872, 3.1304803e-18, 1.1981784e-16, 0.9704311) -bones/40/position = Vector3(0.015597563, 0.030223738, 0.0061558606) -bones/40/rotation = Quaternion(-0.5071953, 0.4361461, -0.43880603, 0.5999824) -bones/43/rotation = Quaternion(0.16942807, 1.17632844e-07, -1.932268e-08, 0.98554254) -bones/44/rotation = Quaternion(0.9970487, -9.152002e-09, 1.18857486e-07, -0.0767723) - [node name="Body" parent="revolver/Character/Skeleton3D" index="0"] layers = 2 @@ -53,7 +23,7 @@ layers = 2 layers = 2 [node name="BoneAttachment3D" type="BoneAttachment3D" parent="revolver/Character/Skeleton3D" index="2"] -transform = Transform3D(1, -2.3103859e-16, 6.391877e-17, 2.3406112e-16, 0.8834727, -0.46848273, 5.176711e-17, 0.46848273, 0.8834727, 0.09835215, -0.26794472, -0.3457696) +transform = Transform3D(1, -6.350722e-17, 4.732016e-17, 4.732016e-17, 0.95822614, 0.28601173, -6.350722e-17, -0.28601173, 0.95822614, -1.1196792e-16, -0.03667751, 0.009908612) bone_name = "root" bone_idx = 39 diff --git a/project/project.godot b/project/project.godot index ba365857..d54b99ae 100644 --- a/project/project.godot +++ b/project/project.godot @@ -87,6 +87,11 @@ activate={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) ] } +reload={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) +] +} [layer_names]