dungeonanddeamon/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp
2020-03-28 12:53:53 +01:00

70 lines
1021 B
C++

#include "GestionPlayer.h"
#include <AnimatedSprite.hpp>
#include <Node2D.hpp>
using namespace godot;
void GestionPlayer::_register_methods() {
register_method((char*)"_process", &GestionPlayer::_process);
}
void GestionPlayer::_init() {}
GestionPlayer::GestionPlayer() {
velocity = Vector2(0, 0);
}
GestionPlayer::~GestionPlayer() {}
void GestionPlayer::_process(float delta)
{
UpdateMotionFromInput();
velocity = move_and_slide(velocity, FLOOR);
}
void GestionPlayer::UpdateMotionFromInput()
{
velocity = Vector2(0, 0);
FLOOR = Vector2(0, -1);
Input* i = Input::get_singleton();
if (i->is_action_pressed("ui_left"))
{
velocity.x -= speed;
}
else if (i->is_action_pressed("ui_right"))
velocity.x += speed;
else
velocity.x = 0.0;
if (i->is_action_pressed("ui_select")) {
if (on_ground == true) {
velocity.y = power_jump;
on_ground = false;
}
}
if (is_on_floor()) {
on_ground = true;
velocity.y += 0;
}
else {
on_ground = false;
velocity.y += gravity;
}
}