feat: initialized template and wrote first gameplay code
This commit is contained in:
parent
82f2cae0f6
commit
46a958f801
47 changed files with 1093 additions and 33 deletions
76
modules/wave_survival/weapons/rifle.cpp
Normal file
76
modules/wave_survival/weapons/rifle.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#include "rifle.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "wave_survival/player_body.h"
|
||||
#include "wave_survival/player_input.h"
|
||||
|
||||
void Rifle::_bind_methods() {}
|
||||
|
||||
void Rifle::on_primary_fire(bool pressed) {
|
||||
if (pressed && get_anim()->get_queue().size() == 0) {
|
||||
if (this->request_alt_mode) {
|
||||
get_anim()->queue("fire_aim");
|
||||
} else if (get_anim()->get_current_animation() == "") {
|
||||
get_anim()->queue("fire_hip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::on_alt_mode(bool alt_mode) {
|
||||
this->request_alt_mode = alt_mode;
|
||||
}
|
||||
|
||||
void Rifle::on_animation_changed(String new_animation) {
|
||||
if (new_animation == "aim") {
|
||||
this->in_alt_mode = true;
|
||||
get_camera()->set_fov_factor(this->ads_factor);
|
||||
} else if (new_animation == "RESET") {
|
||||
this->in_alt_mode = false;
|
||||
get_camera()->set_fov_factor(1.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::ready() {
|
||||
get_anim()->connect("current_animation_changed", callable_mp(this, &self_type::on_animation_changed));
|
||||
PlayerInput *input{ cast_to<PlayerInput>(get_node(NodePath("%PlayerInput"))) };
|
||||
input->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
|
||||
input->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
|
||||
|
||||
get_anim()->animation_set_next("hip_to_aim", "aim");
|
||||
get_anim()->animation_set_next("fire_aim", "aim");
|
||||
get_anim()->animation_set_next("aim_to_hip", "RESET");
|
||||
get_anim()->animation_set_next("fire_hip", "RESET");
|
||||
}
|
||||
|
||||
void Rifle::process(double delta) {
|
||||
String const current{ get_anim()->get_current_animation() };
|
||||
float const progress{ float(CLAMP(get_anim()->get_current_animation_position() / get_anim()->get_current_animation_length(), 0.0, 1.0)) };
|
||||
if (current == "hip_to_aim") {
|
||||
get_camera()->set_fov_factor(Math::lerp(1.f, this->ads_factor, progress));
|
||||
} else if (current == "aim_to_hip") {
|
||||
get_camera()->set_fov_factor(Math::lerp(this->ads_factor, 1.f, progress));
|
||||
} else if (this->request_alt_mode != this->in_alt_mode && current.is_empty()) {
|
||||
get_anim()->clear_queue();
|
||||
if (this->request_alt_mode) {
|
||||
get_anim()->queue("hip_to_aim");
|
||||
} else {
|
||||
get_anim()->queue("aim_to_hip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
set_process(true);
|
||||
ready();
|
||||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
process(get_process_delta_time());
|
||||
return;
|
||||
}
|
||||
}
|
||||
26
modules/wave_survival/weapons/rifle.h
Normal file
26
modules/wave_survival/weapons/rifle.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef WEAPONS_RIFLE_H
|
||||
#define WEAPONS_RIFLE_H
|
||||
|
||||
#include "wave_survival/player_camera.h"
|
||||
#include "wave_survival/weapon_base.h"
|
||||
class PlayerBody;
|
||||
|
||||
class Rifle : public WeaponBase {
|
||||
GDCLASS(Rifle, WeaponBase);
|
||||
static void _bind_methods();
|
||||
void on_primary_fire(bool down);
|
||||
void on_alt_mode(bool alt_mode);
|
||||
void on_animation_changed(String new_anim);
|
||||
void ready();
|
||||
void process(double delta);
|
||||
|
||||
public:
|
||||
void _notification(int what);
|
||||
|
||||
private:
|
||||
float ads_factor{ 0.5f };
|
||||
bool request_alt_mode{ false };
|
||||
bool in_alt_mode{ false };
|
||||
};
|
||||
|
||||
#endif // !WEAPONS_RIFLE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue