Changement fluidité saut + changement gravité et accélération.

Rendre tout plus correct
This commit is contained in:
gwiz
2020-04-29 20:23:19 +02:00
parent 73809ea0db
commit 0114c85da1

View File

@ -23,9 +23,9 @@ void GestionPlayer::_register_methods()
} }
void GestionPlayer::_process(float delta) void GestionPlayer::_process(float dt) // dt = deltaTime
{ {
traitementInput(); traitementInput(dt);
p.velocity = move_and_slide(p.velocity); p.velocity = move_and_slide(p.velocity);
} }
@ -56,55 +56,65 @@ void GestionPlayer::setupPlayer()
sprite_player_ptr->set_texture(texture_player_ptr); sprite_player_ptr->set_texture(texture_player_ptr);
} }
void GestionPlayer::traitementInput() void GestionPlayer::traitementInput(float dt)
{ {
p.velocity = Vector2(0, 0); // manage Inputs
FLOOR = Vector2(0, -1);
Input* i = Input::get_singleton(); Input* i = Input::get_singleton();
// move in X directions
p.velocity.x = 0.0f; // rest x, keyboard action will change this
if (i->is_action_pressed("ui_left")) if (i->is_action_pressed("ui_left"))
gauche(); gauche();
if (i->is_action_pressed("ui_right")) if (i->is_action_pressed("ui_right"))
droit(); droit();
// update Velocity
if (on_ground)
{
p.velocity.y = 0.0f;
}
else
{
p.velocity.y += gravity * dt;
}
// move in Y directions
if (i->is_action_pressed("ui_select")) if (i->is_action_pressed("ui_select"))
saut(); saut();
if (on_ground) {
p.velocity.y += 0;
}
else {
p.velocity.y += gravity;
}
} }
void GestionPlayer::setPosition(int x, int y) void GestionPlayer::setPosition(int x, int y)
{ {
Transform2D t; Transform2D t;
Vector2 v; Vector2 pos;
Size2 s; Size2 s;
//setup de la size //setup de la size
s.x = 1; s.x = 1.0f;
s.y = 1; s.y = 1.0f;
v.x = x; pos.x = x;
v.y = y; pos.y = y;
t.set_origin(v); t.set_origin(pos);
t.scale(s); t.scale(s);
set_transform(t); set_transform(t);
//init Velocity
p.velocity = Vector2(0.0f, 0.0f);
} }
void GestionPlayer::droit() void GestionPlayer::droit()
{ {
Godot::print("Deplacement a droite"); Godot::print("Deplacement a droite");
p.velocity.x += speed; p.velocity.x = speed;
} }
void GestionPlayer::gauche() void GestionPlayer::gauche()
{ {
Godot::print("Deplacement a gauche"); Godot::print("Deplacement a gauche");
p.velocity.x -= speed; p.velocity.x = -speed;
} }
void GestionPlayer::bas() void GestionPlayer::bas()
@ -113,8 +123,10 @@ void GestionPlayer::bas()
void GestionPlayer::saut() void GestionPlayer::saut()
{ {
if (on_ground)
p.velocity.y = power_jump; {
p.velocity.y = power_jump;
}
} }
void GestionPlayer::idle() void GestionPlayer::idle()