This commit is contained in:
Amaury 2020-03-31 08:17:14 +02:00
parent 15bfb3f6a9
commit 735839c506
8 changed files with 231 additions and 116 deletions

View File

@ -10,7 +10,7 @@ class GestionCollision
public : public :
GestionTerrain gTerrain; GestionTerrain gTerrain;
GestionMobs gMobs; GestionMobs gMobs;
GestionPlayer gPlayer;
public: public:
std::vector<Mobs> CheckCollisonSol(); std::vector<Mobs> CheckCollisonSol();

View File

@ -1 +1,60 @@
#include "GestionJeu.h" #include "GestionJeu.h"
#include <Sprite.hpp>
#include <CollisionShape2D.hpp>
#include <ResourceLoader.hpp>
#include <CircleShape2D.hpp>
#include <GodotGlobal.hpp>
#include <Texture.hpp>
#include <AnimatedSprite.hpp>
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()
{
}

View File

@ -1,4 +1,8 @@
#pragma once #pragma once
#include <CircleShape2D.hpp>
#include <CollisionShape2D.hpp>
#include <Sprite.hpp>
#include "GestionCollision.h" #include "GestionCollision.h"
#include "GestionIdentifiant.h" #include "GestionIdentifiant.h"
#include "GestionItem.h" #include "GestionItem.h"
@ -6,14 +10,33 @@
#include "GestionPlayer.h" #include "GestionPlayer.h"
#include "GestionTerrain.h" #include "GestionTerrain.h"
class GestionJeu using namespace godot;
{
public:
class GestionJeu : public Node2D
{
private:
GODOT_CLASS(GestionJeu, Node2D)
public:
//Gestion des deifferents parties du jeu
GestionPlayer* gPlayer;
GestionMobs gMobs; GestionMobs gMobs;
GestionTerrain gTerrain; GestionTerrain gTerrain;
GestionCollision gCollision; GestionCollision gCollision;
GestionItem gItem; GestionItem gItem;
GestionIdentifiant gId; GestionIdentifiant gId;
public:
GestionJeu();
~GestionJeu();
void static _register_methods();
void _init();
void _ready();
void _process();
private:
void create_scene();
void setup_scene();
}; };

View File

@ -1,69 +1,125 @@
#include "GestionPlayer.h" #include "GestionPlayer.h"
#include <AnimatedSprite.hpp>
#include <Node2D.hpp>
#include <ConfigFile.hpp>
#include <Input.hpp>
#include <ResourceLoader.hpp>
#include <Texture.hpp>
GestionPlayer::GestionPlayer()
{
sprite_player_ptr = Sprite::_new();
using namespace godot; collision_player_ptr = CollisionShape2D::_new();
texture_player_ptr.instance();
void GestionPlayer::_register_methods() { texture_player_ptr->_new();
register_method((char*)"_process", &GestionPlayer::_process); 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) 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); createPlayer();
FLOOR = Vector2(0, -1); }
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(); Input* i = Input::get_singleton();
if (i->is_action_pressed("ui_left")) if (i->is_action_pressed("ui_left"))
{ gauche();
velocity.x -= speed;
}
else if (i->is_action_pressed("ui_right")) else if (i->is_action_pressed("ui_right"))
velocity.x += speed; droit();
else else if (i->is_key_pressed(0x39))
velocity.x = 0.0; saut();
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;
}
} }
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()
{
}

View File

@ -1,59 +1,46 @@
#pragma once #pragma once
#include <CircleShape2D.hpp>
#include <Godot.hpp> #include <CollisionShape2D.hpp>
#include <KinematicBody2D.hpp> #include <Sprite.hpp>
#include <Input.hpp>
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();
// 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;
private:
Vector2 velocity;
Vector2 FLOOR;
#include "Player.h"
using namespace godot;
class GestionPlayer : public KinematicBody2D
{
public:
Sprite* sprite_player_ptr;
CollisionShape2D* collision_player_ptr;
// Gameplay methods Ref<Resource> texture_player_ptr;
public: Ref<CircleShape2D> shape_player_ptr;
void UpdateMotionFromInput();
private: 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;
}; public:
} void traitementInput();
void droit();
void gauche();
void bas();
void saut();
void idle();
void attack();
};

View File

@ -1,4 +1,4 @@
#include "GestionPlayer.h" #include "GestionJeu.h"
using namespace godot; 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) { extern "C" void GDN_EXPORT godot_nativescript_init(void* handle) {
Godot::nativescript_init(handle); Godot::nativescript_init(handle);
register_class<GestionJeu>();
register_class<GestionPlayer>(); register_class<GestionPlayer>();
} }

View File

@ -1,14 +1,4 @@
#include "Player.h" #include "Player.h"
void Player::_register_methods()
{
register_method((char*)"_process", &Player::_process);
}
void Player::_process(float delta)
{
}
Player::Player() Player::Player()
{ {
} }

View File

@ -4,16 +4,15 @@
#include <Godot.hpp> #include <Godot.hpp>
#include <KinematicBody2D.hpp> #include <KinematicBody2D.hpp>
class Player : class Player
public Mobs
{ {
// Godot structure // Godot structure
private:
GODOT_CLASS(Player, KinematicBody2D)
public: public:
void static _register_methods(); const int speed = 100;
void _process(float delta); const int gravity = 90;
const int power_jump = -2500;
godot::Vector2 velocity;
public: public:
Player(); Player();