feat: fully implemented checkpoint
This commit is contained in:
parent
ae57c0b7d0
commit
d64c8d2b61
23 changed files with 677 additions and 105 deletions
|
|
@ -52,3 +52,15 @@ void CheckpointArea::on_body_entered(Node3D *body) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ReloadArea::_notification(int what) {
|
||||
if(!Engine::get_singleton()->is_editor_hint() && what == NOTIFICATION_READY) {
|
||||
this->connect(this->body_entered, callable_mp(this, &ReloadArea::on_body_entered));
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadArea::on_body_entered(Node3D *body) {
|
||||
if(PlayerBody *player{Object::cast_to<PlayerBody>(body)}) {
|
||||
player->load_checkpoint();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,12 @@ class CheckpointArea : public Area3D {
|
|||
StringName body_entered{"body_entered"};
|
||||
};
|
||||
|
||||
class ReloadArea : public Area3D {
|
||||
GDCLASS(ReloadArea, Area3D);
|
||||
static void _bind_methods() {}
|
||||
void _notification(int what);
|
||||
void on_body_entered(Node3D *body);
|
||||
StringName body_entered{"body_entered"};
|
||||
};
|
||||
|
||||
#endif // !CHECKPOINT_H
|
||||
|
|
|
|||
|
|
@ -131,9 +131,12 @@ void SplitStepState::state_entered() {
|
|||
|
||||
void SplitStepState::process(double delta) {
|
||||
this->timer -= delta;
|
||||
this->jump |= Input::get_singleton()->is_action_pressed("jump");
|
||||
}
|
||||
|
||||
void SplitStepState::physics_process(double delta) {
|
||||
this->get_body()->set_velocity(this->get_body()->get_velocity()
|
||||
.move_toward(Vector3(), this->get_body()->get_target_speed() / this->get_body()->get_split_step_stop_time() * delta));
|
||||
this->jump |= Input::get_singleton()->is_action_pressed("jump");
|
||||
}
|
||||
|
||||
void SplitStepState::state_exited() {
|
||||
|
|
@ -159,29 +162,13 @@ PlayerState::StateID FallingState::get_next_state() const {
|
|||
}
|
||||
|
||||
void FallingState::state_entered() {
|
||||
this->game_over_timer = 0.0;
|
||||
this->get_body()->get_anim()->play("falling", 0.1);
|
||||
}
|
||||
|
||||
void FallingState::process(double delta) {
|
||||
void FallingState::physics_process(double delta) {
|
||||
Vector3 const current{this->get_body()->get_velocity()};
|
||||
Vector3 const flattened{current.x, 0.f, current.z};
|
||||
this->get_body()->set_velocity((flattened - (flattened * 0.015f)) + Vector3{0.f, current.y - float(9.8 * delta), 0.f});
|
||||
if(this->can_game_over_falling) {
|
||||
this->game_over_timer += delta * this->get_body()->get_game_over_speed();
|
||||
if(this->game_over_timer > 1.0) {
|
||||
RenderingServer::get_singleton()->global_shader_parameter_set(this->game_over_param, 0.0);
|
||||
this->get_body()->load_checkpoint();
|
||||
} else {
|
||||
RenderingServer::get_singleton()->global_shader_parameter_set(this->game_over_param, float(this->game_over_timer));
|
||||
this->game_over_timer = MIN(this->game_over_timer, 1.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FallingState::state_exited() {
|
||||
RenderingServer::get_singleton()->global_shader_parameter_set(this->game_over_param, 0.0);
|
||||
this->can_game_over_falling = true;
|
||||
this->get_body()->set_velocity((flattened - (flattened * 2.0f * delta)) + Vector3{0.f, current.y - float(9.8 * delta), 0.f});
|
||||
}
|
||||
|
||||
PlayerState::StateID JumpingState::get_next_state() const {
|
||||
|
|
@ -201,7 +188,7 @@ void JumpingState::state_entered() {
|
|||
this->get_body()->get_anim()->play("jump");
|
||||
}
|
||||
|
||||
void JumpingState::process(double delta) {
|
||||
void JumpingState::physics_process(double delta) {
|
||||
Vector3 const current{this->get_body()->get_velocity()};
|
||||
Vector3 const flattened{current.x, 0.f, current.z};
|
||||
this->get_body()->set_velocity((flattened - (flattened * 0.015f)) + Vector3{0.f, current.y - float(9.8 * delta), 0.f});
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public:
|
|||
virtual StateID get_next_state() const override;
|
||||
virtual void state_entered() override;
|
||||
virtual void process(double delta) override;
|
||||
virtual void physics_process(double delta) override;
|
||||
virtual void state_exited() override;
|
||||
private:
|
||||
Vector3 last_velocity{0.f, 0.f, 0.f};
|
||||
|
|
@ -68,12 +69,7 @@ class FallingState : public PlayerState {
|
|||
public:
|
||||
virtual StateID get_next_state() const override;
|
||||
virtual void state_entered() override;
|
||||
virtual void process(double delta) override;
|
||||
virtual void state_exited() override;
|
||||
private:
|
||||
bool can_game_over_falling{false};
|
||||
double game_over_timer{0.0};
|
||||
StringName game_over_param{"game_over_percentage"};
|
||||
virtual void physics_process(double delta) override;
|
||||
};
|
||||
|
||||
class JumpingState : public PlayerState {
|
||||
|
|
@ -81,7 +77,7 @@ class JumpingState : public PlayerState {
|
|||
public:
|
||||
virtual StateID get_next_state() const override;
|
||||
virtual void state_entered() override;
|
||||
virtual void process(double delta) override;
|
||||
virtual void physics_process(double delta) override;
|
||||
};
|
||||
|
||||
class PlayerStateMachine : public Node {
|
||||
|
|
@ -115,7 +111,7 @@ void PlayerStateMachine::add_state() {
|
|||
template <class TState>
|
||||
void PlayerStateMachine::force_state() {
|
||||
PlayerState::StateID next{TState::get_class_static()};
|
||||
if(next != this->current_state->get_class()) {
|
||||
if(!next.is_empty()) {
|
||||
this->current_state->state_exited();
|
||||
this->current_state = this->states[TState::get_class_static()];
|
||||
this->current_state->state_entered();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ void initialize_going_module(ModuleInitializationLevel p_level) {
|
|||
ClassDB::register_class<GameUI>();
|
||||
ClassDB::register_class<Checkpoint>();
|
||||
ClassDB::register_class<CheckpointArea>();
|
||||
ClassDB::register_class<ReloadArea>();
|
||||
}
|
||||
|
||||
void uninitialize_going_module(ModuleInitializationLevel p_level) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue