From 735839c50691133098d113ecab18165fb6202df4 Mon Sep 17 00:00:00 2001 From: Amaury Date: Tue, 31 Mar 2020 08:17:14 +0200 Subject: [PATCH] Update --- .../DungeonAndDemaonScript/GestionCollision.h | 2 +- .../DungeonAndDemaonScript/GestionJeu.cpp | 59 +++++++ .../DungeonAndDemaonScript/GestionJeu.h | 27 +++- .../DungeonAndDemaonScript/GestionPlayer.cpp | 150 ++++++++++++------ .../DungeonAndDemaonScript/GestionPlayer.h | 83 ++++------ .../DungeonAndDemaonScript/GodotLibrary.cpp | 3 +- .../DungeonAndDemaonScript/Player.cpp | 10 -- .../DungeonAndDemaonScript/Player.h | 13 +- 8 files changed, 231 insertions(+), 116 deletions(-) diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionCollision.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionCollision.h index 43ca107..62c10a4 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionCollision.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionCollision.h @@ -10,7 +10,7 @@ class GestionCollision public : GestionTerrain gTerrain; GestionMobs gMobs; - + GestionPlayer gPlayer; public: std::vector CheckCollisonSol(); diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp index 0132275..ca3f05f 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp @@ -1 +1,60 @@ #include "GestionJeu.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace godot; + +GestionJeu::GestionJeu() +{ + gPlayer = GestionPlayer::_new(); +} + +GestionJeu::~GestionJeu() +{ + delete gPlayer; +} + + +void GestionJeu::_register_methods() +{ + register_method((char*)"_init", &GestionJeu::_init); + register_method((char*)"_ready", &GestionJeu::_ready); + register_method((char*)"_process", &GestionJeu::_process); +} + +void GestionJeu::_init() +{ + Godot::print("Initialisation..."); + create_scene(); + Godot::print("Initialisation OK !"); +} + +void GestionJeu::_ready() +{ + Godot::print("Ready..."); + setup_scene(); + Godot::print("Ready OK !"); + +} + +void GestionJeu::_process() +{ + +} + +void GestionJeu::create_scene() +{ + add_child(gPlayer); +} + +void GestionJeu::setup_scene() +{ +} + + diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.h index 8259eba..3f25825 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.h @@ -1,4 +1,8 @@ #pragma once +#include +#include +#include + #include "GestionCollision.h" #include "GestionIdentifiant.h" #include "GestionItem.h" @@ -6,14 +10,33 @@ #include "GestionPlayer.h" #include "GestionTerrain.h" -class GestionJeu +using namespace godot; + +class GestionJeu : public Node2D { -public: +private: + GODOT_CLASS(GestionJeu, Node2D) +public: + //Gestion des deifferents parties du jeu + GestionPlayer* gPlayer; GestionMobs gMobs; GestionTerrain gTerrain; GestionCollision gCollision; GestionItem gItem; GestionIdentifiant gId; + +public: + GestionJeu(); + ~GestionJeu(); + + void static _register_methods(); + void _init(); + void _ready(); + void _process(); + +private: + void create_scene(); + void setup_scene(); }; diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp index 37bf070..70e6d4d 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp @@ -1,69 +1,125 @@ #include "GestionPlayer.h" -#include -#include +#include +#include +#include +#include - - - -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() +{ +} diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h index 05bf1e2..cf21f33 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h @@ -1,59 +1,46 @@ - - #pragma once - -#include -#include -#include - -namespace godot { - class GestionPlayer : public KinematicBody2D - { - - // Godot structure - private: - GODOT_CLASS(GestionPlayer, KinematicBody2D) - public: - static void _register_methods(); - void _init(); - void _process(float delta); - - GestionPlayer(); - ~GestionPlayer(); +#include +#include +#include - // Gameplay variables - public: - const int speed = 100; - const int gravity = 90; - const int power_jump = -2500; - bool on_ground = false; - bool right; - bool left; - bool jump; +#include "Player.h" - private: - Vector2 velocity; - Vector2 FLOOR; +using namespace godot; +class GestionPlayer : public KinematicBody2D +{ +public: + Sprite* sprite_player_ptr; + CollisionShape2D* collision_player_ptr; + Ref texture_player_ptr; + Ref shape_player_ptr; +private: + GODOT_CLASS(GestionPlayer, KinematicBody2D) +public: + GestionPlayer(); + + void static _register_methods(); + void _process(float delta); + void _init(); + void _ready(); + void createPlayer(); + void setupPlayer(); +public: + Player p; - // Gameplay methods - public: - void UpdateMotionFromInput(); - - private: - - - - - }; -} - - - - +public: + void traitementInput(); + + void droit(); + void gauche(); + void bas(); + void saut(); + void idle(); + void attack(); +}; \ No newline at end of file diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GodotLibrary.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GodotLibrary.cpp index 5b11e2b..34ee7d1 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GodotLibrary.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GodotLibrary.cpp @@ -1,4 +1,4 @@ -#include "GestionPlayer.h" +#include "GestionJeu.h" using namespace godot; @@ -12,5 +12,6 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt extern "C" void GDN_EXPORT godot_nativescript_init(void* handle) { Godot::nativescript_init(handle); + register_class(); register_class(); } \ No newline at end of file diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.cpp index 96b05f9..3f77019 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.cpp @@ -1,14 +1,4 @@ #include "Player.h" - -void Player::_register_methods() -{ - register_method((char*)"_process", &Player::_process); -} - -void Player::_process(float delta) -{ -} - Player::Player() { } diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.h index a0fb6f7..879047f 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/Player.h @@ -4,16 +4,15 @@ #include #include -class Player : - public Mobs +class Player { // Godot structure -private: - GODOT_CLASS(Player, KinematicBody2D) - public: - void static _register_methods(); - void _process(float delta); + const int speed = 100; + const int gravity = 90; + const int power_jump = -2500; + + godot::Vector2 velocity; public: Player();