diff options
| -rw-r--r-- | game/player/PlayerEndScript.cpp | 52 | ||||
| -rw-r--r-- | game/player/PlayerEndScript.h | 4 | 
2 files changed, 30 insertions, 26 deletions
diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index c0b4e74..37b870c 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -10,19 +10,22 @@ using namespace crepe;  using namespace std;  void PlayerEndScript::init() { -	BoxCollider jetpack_coll = this->get_components_by_name<BoxCollider>("player").back(); -	CircleCollider head_coll = this->get_components_by_name<CircleCollider>("player").back(); -	jetpack_coll.active = false; -	head_coll.active = false; +	Rigidbody & rb_player = this->get_components_by_name<Rigidbody>("player").front(); +	rb_player.data.elasticity_coefficient = 0.7; + +	subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { +		return this->on_collision(ev); +	});  } -void PlayerEndScript::fixed_update(crepe::duration_t dt) { -	Transform & transform_player = this->get_components_by_name<Transform>("player").front(); -	RefVector<Animator> anim_player = this->get_components_by_name<Animator>("player"); -	Rigidbody & rb_player = this->get_components_by_name<Rigidbody>("player").front(); -	Rigidbody & rb_camera = this->get_components_by_name<Rigidbody>("camera").front(); +bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { +	if (ev.info.other.metadata.name == "floor") { +		Transform & transform_player +			= this->get_components_by_name<Transform>("player").front(); +		RefVector<Animator> anim_player = this->get_components_by_name<Animator>("player"); +		Rigidbody & rb_player = this->get_components_by_name<Rigidbody>("player").front(); +		Rigidbody & rb_camera = this->get_components_by_name<Rigidbody>("camera").front(); -	if (transform_player.position.y >= 194) {  		if (jump == 0 || jump == 1) {  			int random_number = rand() % 4;  			for (Animator & anim : anim_player) { @@ -32,29 +35,28 @@ void PlayerEndScript::fixed_update(crepe::duration_t dt) {  					anim.next_anim();  				}  			} -		} else if (jump == 2) { -			for (Animator & anim : anim_player) { -				anim.active = false; -				anim.set_anim(7); -			} -			rb_player.data.angular_velocity = 0; -			transform_player.rotation = 90;  		} +  		if (jump == 0) { -			rb_player.data.linear_velocity = vec2(100, -150);  			rb_player.data.angular_velocity = 320; -			rb_player.data.angular_velocity_coefficient = 0.8; +			rb_player.data.angular_velocity_coefficient = 0.7;  			jump++; -		} else if (jump == 1) { -			rb_player.data.linear_velocity = vec2(100, -125); -			rb_player.data.angular_velocity = 300; -			rb_player.data.angular_velocity_coefficient = 0.8; -			jump++; -		} else if (jump == 2) { +		} else if (jump == 1 && transform_player.rotation > 65 +				   && transform_player.rotation < 115) { +			rb_player.data.angular_velocity = 0; +			rb_player.data.elasticity_coefficient = 0;  			rb_player.data.linear_velocity = vec2(100, 0);  			rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5);  			rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); +			for (Animator & anim : anim_player) { +				anim.active = false; +				anim.set_anim(7); +			}  			jump++;  		} + +		return true;  	} + +	return false;  } diff --git a/game/player/PlayerEndScript.h b/game/player/PlayerEndScript.h index 240ab7c..03ea8a9 100644 --- a/game/player/PlayerEndScript.h +++ b/game/player/PlayerEndScript.h @@ -5,7 +5,9 @@  class PlayerEndScript : public crepe::Script {  public:  	void init(); -	void fixed_update(crepe::duration_t dt); + +private: +	bool on_collision(const crepe::CollisionEvent & ev);  private:  	int jump = 0;  |