diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp index 6ebe080..34575f8 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp @@ -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); } @@ -56,55 +56,65 @@ void GestionPlayer::setupPlayer() sprite_player_ptr->set_texture(texture_player_ptr); } -void GestionPlayer::traitementInput() +void GestionPlayer::traitementInput(float dt) { - p.velocity = Vector2(0, 0); - FLOOR = Vector2(0, -1); - + // manage Inputs 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")) gauche(); if (i->is_action_pressed("ui_right")) 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")) saut(); - if (on_ground) { - p.velocity.y += 0; - } - else { - p.velocity.y += gravity; - } } void GestionPlayer::setPosition(int x, int y) { Transform2D t; - Vector2 v; + Vector2 pos; Size2 s; //setup de la size - s.x = 1; - s.y = 1; - v.x = x; - v.y = y; - t.set_origin(v); + s.x = 1.0f; + s.y = 1.0f; + pos.x = x; + pos.y = y; + t.set_origin(pos); t.scale(s); set_transform(t); + + //init Velocity + p.velocity = Vector2(0.0f, 0.0f); } void GestionPlayer::droit() { Godot::print("Deplacement a droite"); - p.velocity.x += speed; + p.velocity.x = speed; } void GestionPlayer::gauche() { Godot::print("Deplacement a gauche"); - p.velocity.x -= speed; + p.velocity.x = -speed; } void GestionPlayer::bas() @@ -113,8 +123,10 @@ void GestionPlayer::bas() void GestionPlayer::saut() { - - p.velocity.y = power_jump; + if (on_ground) + { + p.velocity.y = power_jump; + } } void GestionPlayer::idle()