Compare commits
No commits in common. "7c4c75d193e85af8d248c1f5d50f1daf69d33d87" and "f02dbf44acc958e033a5953a6ddd6a60b75c8930" have entirely different histories.
7c4c75d193
...
f02dbf44ac
|
@ -39,8 +39,7 @@ void HitscanMuzzle::shoot() {
|
||||||
get_tree()->get_current_scene()->add_child(effect);
|
get_tree()->get_current_scene()->add_child(effect);
|
||||||
Vector3 const point{ get_collision_point() };
|
Vector3 const point{ get_collision_point() };
|
||||||
Vector3 const normal{ get_collision_normal() };
|
Vector3 const normal{ get_collision_normal() };
|
||||||
Vector3 const position{ get_global_position() };
|
effect->look_at_from_position(point, point + normal);
|
||||||
effect->look_at_from_position(point, point + normal, (point - position).normalized());
|
|
||||||
} else if (effect_as_node) {
|
} else if (effect_as_node) {
|
||||||
effect_as_node->queue_free();
|
effect_as_node->queue_free();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
#include "core/object/class_db.h"
|
#include "core/object/class_db.h"
|
||||||
#include "wave_survival/health_status.h"
|
|
||||||
#include "wave_survival/hitscan_muzzle.h"
|
#include "wave_survival/hitscan_muzzle.h"
|
||||||
#include "wave_survival/player_body.h"
|
#include "wave_survival/player_body.h"
|
||||||
#include "wave_survival/player_camera.h"
|
#include "wave_survival/player_camera.h"
|
||||||
#include "wave_survival/player_input.h"
|
#include "wave_survival/player_input.h"
|
||||||
#include "wave_survival/state.h"
|
|
||||||
#include "wave_survival/state_machine.h"
|
|
||||||
#include "wave_survival/weapon_base.h"
|
#include "wave_survival/weapon_base.h"
|
||||||
#include "wave_survival/weapon_inventory.h"
|
#include "wave_survival/weapon_inventory.h"
|
||||||
#include "wave_survival/weapons/rifle.h"
|
#include "wave_survival/weapons/rifle.h"
|
||||||
|
@ -23,9 +20,6 @@ void initialize_wave_survival_module(ModuleInitializationLevel p_level) {
|
||||||
GDREGISTER_CLASS(Rifle);
|
GDREGISTER_CLASS(Rifle);
|
||||||
GDREGISTER_CLASS(WeaponInventory);
|
GDREGISTER_CLASS(WeaponInventory);
|
||||||
GDREGISTER_CLASS(HitscanMuzzle);
|
GDREGISTER_CLASS(HitscanMuzzle);
|
||||||
GDREGISTER_CLASS(HealthStatus);
|
|
||||||
GDREGISTER_CLASS(StateMachine);
|
|
||||||
GDREGISTER_CLASS(State);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitialize_wave_survival_module(ModuleInitializationLevel p_level) {
|
void uninitialize_wave_survival_module(ModuleInitializationLevel p_level) {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#include "state.h"
|
|
||||||
|
|
||||||
void State::_bind_methods() {
|
|
||||||
}
|
|
||||||
|
|
||||||
String State::get_next_state() const {
|
|
||||||
return this->get_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
void State::set_state_machine(StateMachine *machine) {
|
|
||||||
this->state_machine = machine;
|
|
||||||
}
|
|
||||||
|
|
||||||
StateMachine *State::get_state_machine() const {
|
|
||||||
return this->state_machine;
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
#ifndef STATE_H
|
|
||||||
#define STATE_H
|
|
||||||
|
|
||||||
#include "core/object/class_db.h"
|
|
||||||
#include "core/object/object.h"
|
|
||||||
class StateMachine;
|
|
||||||
class Node;
|
|
||||||
|
|
||||||
class State : public Object {
|
|
||||||
GDCLASS(State, Object);
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void set_target(Node *target) {}
|
|
||||||
virtual void enter_state() {}
|
|
||||||
virtual void exit_state() {}
|
|
||||||
virtual void process(double delta) {}
|
|
||||||
virtual String get_next_state() const;
|
|
||||||
void set_state_machine(StateMachine *machine);
|
|
||||||
StateMachine *get_state_machine() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
StateMachine *state_machine{ nullptr };
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !STATE_H
|
|
|
@ -1,55 +0,0 @@
|
||||||
#include "state_machine.h"
|
|
||||||
#include "state.h"
|
|
||||||
|
|
||||||
void StateMachine::_bind_methods() {}
|
|
||||||
|
|
||||||
void StateMachine::add_state(State *state) {
|
|
||||||
state->set_state_machine(this);
|
|
||||||
state->set_target(this->get_parent());
|
|
||||||
this->states.insert(state->get_class(), state);
|
|
||||||
if (this->current_state == nullptr) {
|
|
||||||
this->switch_to_state(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StateMachine::switch_to_state(State *state) {
|
|
||||||
if (this->current_state) {
|
|
||||||
this->current_state->exit_state();
|
|
||||||
}
|
|
||||||
this->current_state = state;
|
|
||||||
if (this->current_state) {
|
|
||||||
this->current_state->enter_state();
|
|
||||||
} else {
|
|
||||||
print_error("StateMachine::switch_to_state: New state is nullptr, StateMachine will now stop working");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StateMachine::ready() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void StateMachine::process(double delta) {
|
|
||||||
if (this->current_state) {
|
|
||||||
this->current_state->process(delta);
|
|
||||||
String new_state{ this->current_state->get_next_state() };
|
|
||||||
if (new_state != this->current_state->get_class()) {
|
|
||||||
this->switch_to_state(this->states[new_state]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StateMachine::_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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
#ifndef STATE_MACHINE_H
|
|
||||||
#define STATE_MACHINE_H
|
|
||||||
|
|
||||||
#include "scene/main/node.h"
|
|
||||||
class State;
|
|
||||||
|
|
||||||
class StateMachine : public Node {
|
|
||||||
GDCLASS(StateMachine, Node);
|
|
||||||
static void _bind_methods();
|
|
||||||
void add_state(State *state);
|
|
||||||
void switch_to_state(State *state);
|
|
||||||
void ready();
|
|
||||||
void process(double delta);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void _notification(int what);
|
|
||||||
|
|
||||||
private:
|
|
||||||
State *current_state{ nullptr };
|
|
||||||
HashMap<StringName, State *> states{};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !STATE_MACHINE_H
|
|
Loading…
Reference in a new issue