deplacment basique joueur

This commit is contained in:
Estrela Allan p1923381
2020-03-31 09:26:51 +02:00
parent 735839c506
commit be3f291382
6 changed files with 60 additions and 64 deletions

View File

@ -84,27 +84,40 @@ void GestionPlayer::setupPlayer()
void GestionPlayer::traitementInput()
{
p.velocity = Vector2(0, 0);
FLOOR = Vector2(0, -1);
Input* i = Input::get_singleton();
if (i->is_action_pressed("ui_left"))
gauche();
else if (i->is_action_pressed("ui_right"))
if (i->is_action_pressed("ui_right"))
droit();
else if (i->is_key_pressed(0x39))
if (i->is_action_pressed("ui_select"))
saut();
if (is_on_floor()) {
on_ground = true;
p.velocity.y += 0;
}
else {
on_ground = false;
p.velocity.y += gravity;
}
}
void GestionPlayer::droit()
{
Godot::print("Deplacement a droite");
p.velocity.x -= p.speed;
p.velocity.x += speed;
}
void GestionPlayer::gauche()
{
Godot::print("Deplacement a gauche");
p.velocity.x += p.speed;
p.velocity.x -= speed;
}
void GestionPlayer::bas()
@ -114,10 +127,13 @@ void GestionPlayer::bas()
void GestionPlayer::saut()
{
p.velocity.y = power_jump;
}
void GestionPlayer::idle()
{
p.velocity.x = 0.0;
}
void GestionPlayer::attack()

View File

@ -43,4 +43,17 @@ public:
void saut();
void idle();
void attack();
public:
const int speed = 100;
const int gravity = 90;
const int power_jump = -250;
bool on_ground = false;
bool right;
bool left;
bool jump;
private:
Vector2 velocity;
Vector2 FLOOR;
};