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:
parent
15bfb3f6a9
commit
735839c506
@ -10,7 +10,7 @@ class GestionCollision
|
||||
public :
|
||||
GestionTerrain gTerrain;
|
||||
GestionMobs gMobs;
|
||||
|
||||
GestionPlayer gPlayer;
|
||||
|
||||
public:
|
||||
std::vector<Mobs> CheckCollisonSol();
|
||||
|
@ -1 +1,60 @@
|
||||
#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()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,8 @@
|
||||
#pragma once
|
||||
#include <CircleShape2D.hpp>
|
||||
#include <CollisionShape2D.hpp>
|
||||
#include <Sprite.hpp>
|
||||
|
||||
#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();
|
||||
};
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
@ -1,59 +1,46 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <KinematicBody2D.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();
|
||||
#include <CircleShape2D.hpp>
|
||||
#include <CollisionShape2D.hpp>
|
||||
#include <Sprite.hpp>
|
||||
|
||||
|
||||
// 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<Resource> texture_player_ptr;
|
||||
Ref<CircleShape2D> 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();
|
||||
};
|
@ -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<GestionJeu>();
|
||||
register_class<GestionPlayer>();
|
||||
}
|
@ -1,14 +1,4 @@
|
||||
#include "Player.h"
|
||||
|
||||
void Player::_register_methods()
|
||||
{
|
||||
register_method((char*)"_process", &Player::_process);
|
||||
}
|
||||
|
||||
void Player::_process(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
Player::Player()
|
||||
{
|
||||
}
|
||||
|
@ -4,16 +4,15 @@
|
||||
#include <Godot.hpp>
|
||||
#include <KinematicBody2D.hpp>
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user