mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
Update
This commit is contained in:
@ -1,69 +1,125 @@
|
||||
#include "GestionPlayer.h"
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Node2D.hpp>
|
||||
|
||||
#include <ConfigFile.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Texture.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void GestionPlayer::_register_methods() {
|
||||
register_method((char*)"_process", &GestionPlayer::_process);
|
||||
GestionPlayer::GestionPlayer()
|
||||
{
|
||||
sprite_player_ptr = Sprite::_new();
|
||||
collision_player_ptr = CollisionShape2D::_new();
|
||||
texture_player_ptr.instance();
|
||||
texture_player_ptr->_new();
|
||||
shape_player_ptr.instance();
|
||||
shape_player_ptr->_new();
|
||||
}
|
||||
|
||||
void GestionPlayer::_init() {}
|
||||
void GestionPlayer::_register_methods()
|
||||
{
|
||||
Godot::print("register Player...");
|
||||
register_method("_process", &GestionPlayer::_process);
|
||||
register_method("_init", &GestionPlayer::_init);
|
||||
register_method("_ready", &GestionPlayer::_ready);
|
||||
Godot::print("register Player OK!");
|
||||
|
||||
GestionPlayer::GestionPlayer() {
|
||||
velocity = Vector2(0, 0);
|
||||
}
|
||||
|
||||
GestionPlayer::~GestionPlayer() {}
|
||||
|
||||
void GestionPlayer::_process(float delta)
|
||||
{
|
||||
traitementInput();
|
||||
p.velocity = move_and_slide(p.velocity);
|
||||
|
||||
UpdateMotionFromInput();
|
||||
|
||||
velocity = move_and_slide(velocity, FLOOR);
|
||||
}
|
||||
|
||||
void GestionPlayer::UpdateMotionFromInput()
|
||||
void GestionPlayer::_init()
|
||||
{
|
||||
velocity = Vector2(0, 0);
|
||||
FLOOR = Vector2(0, -1);
|
||||
createPlayer();
|
||||
}
|
||||
|
||||
void GestionPlayer::_ready()
|
||||
{
|
||||
setupPlayer();
|
||||
}
|
||||
|
||||
void GestionPlayer::createPlayer()
|
||||
{
|
||||
add_child(sprite_player_ptr);
|
||||
add_child(collision_player_ptr);
|
||||
}
|
||||
|
||||
void GestionPlayer::setupPlayer()
|
||||
{
|
||||
Transform2D t;
|
||||
Vector2 v;
|
||||
Size2 s;
|
||||
|
||||
//setup de la size
|
||||
s.x = 1;
|
||||
s.y = 1;
|
||||
v.x = 10;
|
||||
v.y = 500;
|
||||
t.set_origin(v);
|
||||
t.scale(s);
|
||||
|
||||
set_transform(t);
|
||||
|
||||
//Setup du shape
|
||||
//Godot::print("SetUp de Shape");
|
||||
shape_player_ptr.ptr()->_new();
|
||||
|
||||
//Chargement de la texture
|
||||
//Godot::print("SetUp de Texture");
|
||||
texture_player_ptr = ResourceLoader::get_singleton()->load("res://Character/Hero Knight/HeroKnight/Layer 1_sprite_01.png");
|
||||
|
||||
//setup du sprite
|
||||
//Godot::print("SetUp de Sprite");
|
||||
sprite_player_ptr->set_texture(texture_player_ptr);
|
||||
|
||||
//setup du collision Shape
|
||||
//Godot::print("SetUp de CollisionShape");
|
||||
collision_player_ptr->set_shape(shape_player_ptr);
|
||||
}
|
||||
|
||||
void GestionPlayer::traitementInput()
|
||||
{
|
||||
p.velocity = Vector2(0, 0);
|
||||
|
||||
Input* i = Input::get_singleton();
|
||||
|
||||
if (i->is_action_pressed("ui_left"))
|
||||
{
|
||||
velocity.x -= speed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gauche();
|
||||
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;
|
||||
}
|
||||
droit();
|
||||
else if (i->is_key_pressed(0x39))
|
||||
saut();
|
||||
}
|
||||
|
||||
void GestionPlayer::droit()
|
||||
{
|
||||
Godot::print("Deplacement a droite");
|
||||
p.velocity.x -= p.speed;
|
||||
}
|
||||
|
||||
void GestionPlayer::gauche()
|
||||
{
|
||||
Godot::print("Deplacement a gauche");
|
||||
p.velocity.x += p.speed;
|
||||
}
|
||||
|
||||
void GestionPlayer::bas()
|
||||
{
|
||||
}
|
||||
|
||||
void GestionPlayer::saut()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::idle()
|
||||
{
|
||||
}
|
||||
|
||||
void GestionPlayer::attack()
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user