reglage probleme animations + commentaire

This commit is contained in:
Estrela Allan p1923381
2020-05-03 15:35:51 +02:00
parent c85ccf4f8f
commit d909ecd889
6 changed files with 206 additions and 155 deletions

View File

@ -16,22 +16,26 @@ GestionPlayer::GestionPlayer()
void GestionPlayer::_register_methods()
{
Godot::print("register Player...");
register_method("_physics_process", &GestionPlayer::_physics_process);
register_method("_process", &GestionPlayer::_process);
register_method("_init", &GestionPlayer::_init);
register_method("_ready", &GestionPlayer::_ready);
Godot::print("register Player OK!");
}
//fonction _pgysics_process meilleur rafraichissement de 60 fps compar<61> <20> 30 pour la fonction _process meilleur pour les mouvements plus fluides du mob
void GestionPlayer::_physics_process(float dt) // dt = deltaTime
{
p.velocity = move_and_slide(p.velocity);
}
void GestionPlayer::_process(float dt) // dt = deltaTime
{
playerState.right = false;
playerState.left = false;
PlayerLogic_AutoReset();
traitementInput();
PlayerLogic(dt);
p.velocity = move_and_slide(p.velocity);
}
void GestionPlayer::_init()
@ -42,6 +46,7 @@ void GestionPlayer::_init()
void GestionPlayer::_ready()
{
setupPlayer();
playerState.Reset();
}
void GestionPlayer::createPlayer()
@ -49,6 +54,8 @@ void GestionPlayer::createPlayer()
add_child(sprite_player_ptr);
}
//setup des textures et des animations avec l'extension .tres qu'on a cr<63><72> gr<67>ce <20> l'interface Godot et les fonctions animated sprite
void GestionPlayer::setupPlayer()
{
//Chargement de la texture
@ -70,6 +77,9 @@ void GestionPlayer::setupPlayer()
}
//Fonction traitement des touches pour le d<>placement du joueur, is_action_pressed fonction godot ou l'on peut changer les contr<74>les dans le menu godot. projet->Parametre du projet ->Contr<74>les
//Traitement des inputs avec des boulleen de la structure du joueur pour cr<63>er un arbre d'<27>tat et simplifier la mise en place des animations
void GestionPlayer::traitementInput()
{
// manage Inputs
@ -78,31 +88,70 @@ void GestionPlayer::traitementInput()
// move in X directions
p.velocity.x = 0.0f; // rest x, keyboard action will change this
if (i->is_action_pressed("ui_left"))
playerState.left = true;
playerState.Flags.left = true;
if (i->is_action_pressed("ui_right"))
playerState.right = true;
playerState.Flags.right = true;
if (i->is_action_pressed("dash"))
playerState.dash = true;
playerState.Flags.dash = true;
if (i->is_action_pressed("attack"))
playerState.attack = true;
playerState.Flags.attack = true;
if (i->is_action_pressed("attack2"))
playerState.bigattack = true;
playerState.Flags.bigattack = true;
if (i->is_action_pressed("block"))
playerState.block = true;
playerState.Flags.block = true;
// move in Y directions
if (i->is_action_pressed("ui_select"))
playerState.jump = true;
playerState.Flags.jump = true;
}
//Fonction pour savoir si les animations sont termin<69> pour <20>viter les loops et les probl<62>mes d'animation non t<>rmin<69>
//mettre en place un flag isInBlockingAnimation
//tant que ce flag est a true on block la player logic pour ne pas interrompre l'animation avec une autre anim(marche / saut par exemple)
//d'o<> le besoin de tester la fin de l'animation dans PlayerLogic_AutoReset) pour debloquer le isInBlockingAnimation = false;
//et au debut de player logic on sort si on est en blocking anim
void GestionPlayer::PlayerLogic_AutoReset()
{
playerState.Flags.right = false;
playerState.Flags.left = false;
if (on_ground)
{
playerState.Flags.jump = false;
playerState.Flags.freefall = false;
}
if (playerState.Flags.isInBlockingAnimation)
{
int64_t frame = sprite_player_ptr->get_frame();
String animation = sprite_player_ptr->get_animation();
CharString name = animation.ascii();
const char* nameascii = name.get_data();
int64_t frame_count = sprite_player_ptr->get_sprite_frames()->get_frame_count(animation);
if (frame == frame_count-1)
{
playerState.Flags.isInBlockingAnimation = false;
}
}
}
//Etat du joueur pour d<>t<EFBFBD>rminer les futurs action, saut, au sol, chute libre et pour g<>rer les diff<66>rentes animations avec les drapeaux
void GestionPlayer::PlayerLogic(float dt)
{
if (playerState.jump)
Godot::print("PlayerLogic");
if (playerState.Flags.isInBlockingAnimation)
{
// do nothing until blocking animation is finished
Godot::print("\t Blocking Animation");
return;
}
if (playerState.Flags.jump)
{
// attack en l'air
PlayerLogic_Jump(dt);
@ -115,15 +164,26 @@ void GestionPlayer::PlayerLogic(float dt)
PlayerLogic_OnGround(dt);
}
else
{ // freefall
// attack en l'air
PlayerLogic_FreeFall(dt);
{ // we fall from the ground
playerState.Flags.freefall = true;
}
}
if(playerState.Flags.freefall)
{
// attack en freefall
PlayerLogic_FreeFall(dt);
}
}
//Fonction g<>rant le saut du joueur et ces animations en fonctions des Flags et si le joueur est en contacte avec le sol ou non
//Fonction g<>rant la gravit<69> avec dt= delta time
//fonction qui gere aussi le sens des aniamtions en fonction de la vitesse
void GestionPlayer::PlayerLogic_Jump(float dt)
{
Godot::print("\t Jump");
if (on_ground)
{
p.velocity.y = power_jump;
@ -134,19 +194,21 @@ void GestionPlayer::PlayerLogic_Jump(float dt)
}
if (p.velocity.y > 0.0f)
{
playerState.jump = false;
playerState.freefall = true;
playerState.Flags.jump = false;
playerState.Flags.freefall = true;
}
else
{
if (playerState.left)
if (playerState.Flags.left)
{
Godot::print("\t\t Jump left");
p.velocity.x = -speed;
sprite_player_ptr->play("Jump Up");
sprite_player_ptr->set_flip_h(true);
}
else if (playerState.right)
else if (playerState.Flags.right)
{
Godot::print("\t\t Jump right");
p.velocity.x = +speed;
sprite_player_ptr->play("Jump Up");
sprite_player_ptr->set_flip_h(false);
@ -154,40 +216,47 @@ void GestionPlayer::PlayerLogic_Jump(float dt)
}
}
//Fonction des animations possibles si le joueur se trouve au sol
//avec les animations qui se trouve dans le fichier "HeroKnight.tres"
//en fonction dss flags des booleens isinblockinganiamtion pour <20>viter toute loop
void GestionPlayer::PlayerLogic_OnGround(float dt)
{
Godot::print("\t OnGround");
p.velocity.y = 0.0f;
if (playerState.attack)
if (playerState.Flags.attack)
{
sprite_player_ptr->play("attack");
playerState.Flags.isInBlockingAnimation = true;
playerState.Flags.attack = false;
}
else if (playerState.bigattack)
else if (playerState.Flags.bigattack)
{
sprite_player_ptr->play("attack2");
p.velocity.y = -5.0f;
playerState.Flags.isInBlockingAnimation = true;
playerState.Flags.bigattack = false;
}
else if (playerState.dash)
else if (playerState.Flags.dash)
{
sprite_player_ptr->play("dash");
p.velocity.x =+ 50;
p.velocity.x =+ 1000.0f;
playerState.Flags.isInBlockingAnimation = true;
playerState.Flags.dash = false;
}
else if (playerState.block)
else if (playerState.Flags.block)
{
sprite_player_ptr->play("shield");
sprite_player_ptr->play("block");
playerState.Flags.isInBlockingAnimation = true;
playerState.Flags.block = false;
}
else if (playerState.left)
else if (playerState.Flags.left)
{
p.velocity.x = -speed;
sprite_player_ptr->play("Walk");
sprite_player_ptr->set_flip_h(true);
}
else if (playerState.right)
else if (playerState.Flags.right)
{
p.velocity.x = +speed;
sprite_player_ptr->play("Walk");
@ -203,17 +272,21 @@ void GestionPlayer::PlayerLogic_OnGround(float dt)
}
}
//Fonction qui gere les animations si le joueur est en chute libre, dans le bon sens en fonction de la velocit<69>
void GestionPlayer::PlayerLogic_FreeFall(float dt)
{
p.velocity.x = +speed;
if (playerState.left)
Godot::print("\t FreeFall");
if (playerState.Flags.left)
{
Godot::print("\t\t tFreeFall left");
p.velocity.x = -speed;
sprite_player_ptr->play("jump Down");
sprite_player_ptr->set_flip_h(true);
}
else if (playerState.right)
else if (playerState.Flags.right)
{
Godot::print("\t\t tFreeFall right");
p.velocity.x = +speed;
sprite_player_ptr->play("jump Down");
sprite_player_ptr->set_flip_h(false);
@ -221,7 +294,9 @@ void GestionPlayer::PlayerLogic_FreeFall(float dt)
p.velocity.y += gravity * dt;
}
void GestionPlayer::setPosition(int x, int y)
//Fonction qui inisalise la position du joueur
void GestionPlayer::setPosition(float x, float y)
{
Transform2D t;
Vector2 pos;
@ -240,51 +315,3 @@ void GestionPlayer::setPosition(int x, int y)
//init Velocity
p.velocity = Vector2(0.0f, 0.0f);
}
/*
void GestionPlayer::droit()
{
Godot::print("Deplacement a droite");
p.velocity.x = speed;
}
void GestionPlayer::gauche()
{
Godot::print("Deplacement a gauche");
p.velocity.x = -speed;
}
void GestionPlayer::bas()
{
}
void GestionPlayer::saut()
{
}
void GestionPlayer::idle()
{
p.velocity.x = 0.0;
}
void GestionPlayer::dash()
{
p.velocity.x =+1000;
sprite_player_ptr->play("dash");
}
void GestionPlayer::attack()
{
sprite_player_ptr->play("attack");
}
void GestionPlayer::block()
{
sprite_player_ptr->play("block");
}
void GestionPlayer::bigattack()
{
sprite_player_ptr->play("attack2");
}
*/