From 0114c85da19b22ec073b855abdab6b45b07b112e Mon Sep 17 00:00:00 2001 From: gwiz Date: Wed, 29 Apr 2020 20:23:19 +0200 Subject: [PATCH] =?UTF-8?q?Changement=20fluidit=C3=A9=20saut=20+=20changem?= =?UTF-8?q?ent=20gravit=C3=A9=20et=20acc=C3=A9l=C3=A9ration.=20Rendre=20to?= =?UTF-8?q?ut=20plus=20correct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DungeonAndDemaonScript/GestionPlayer.cpp | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) 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()