mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -24,10 +24,14 @@ GestionJeu::GestionJeu()
|
||||
|
||||
GestionJeu::~GestionJeu()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
delete gTerrain;
|
||||
delete gPlayer;
|
||||
delete gMobs;
|
||||
delete gCollision;
|
||||
=======
|
||||
delete gMobs;
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include "GestionPlayer.h"
|
||||
|
||||
#include <SpriteFrames.hpp>
|
||||
#include <ConfigFile.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Texture.hpp>
|
||||
|
||||
#include <InputEventKey.hpp>
|
||||
GestionPlayer::GestionPlayer()
|
||||
{
|
||||
sprite_player_ptr = Sprite::_new();
|
||||
|
||||
sprite_player_ptr = AnimatedSprite::_new();
|
||||
texture_player_ptr.instance();
|
||||
texture_player_ptr->_new();
|
||||
}
|
||||
@ -25,9 +25,13 @@ void GestionPlayer::_register_methods()
|
||||
|
||||
void GestionPlayer::_process(float dt) // dt = deltaTime
|
||||
{
|
||||
traitementInput(dt);
|
||||
p.velocity = move_and_slide(p.velocity);
|
||||
playerState.right = false;
|
||||
playerState.left = false;
|
||||
|
||||
traitementInput();
|
||||
|
||||
PlayerLogic(dt);
|
||||
p.velocity = move_and_slide(p.velocity);
|
||||
}
|
||||
|
||||
void GestionPlayer::_init()
|
||||
@ -53,10 +57,20 @@ void GestionPlayer::setupPlayer()
|
||||
|
||||
//setup du sprite
|
||||
//Godot::print("SetUp de Sprite");
|
||||
sprite_player_ptr->set_texture(texture_player_ptr);
|
||||
Ref<SpriteFrames> spriteFrames = ResourceLoader::get_singleton()->load("res://Character/Hero Knight/HeroKnight/HeroKnight.tres");
|
||||
sprite_player_ptr->set_sprite_frames(spriteFrames);
|
||||
|
||||
PoolStringArray AnimNames = spriteFrames->get_animation_names();
|
||||
PoolStringArray::Read r = AnimNames.read();
|
||||
Godot::print("Animations Names");
|
||||
for (int i = 0; i < AnimNames.size(); ++i)
|
||||
{
|
||||
Godot::print(r[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::traitementInput(float dt)
|
||||
void GestionPlayer::traitementInput()
|
||||
{
|
||||
// manage Inputs
|
||||
Input* i = Input::get_singleton();
|
||||
@ -64,25 +78,147 @@ void GestionPlayer::traitementInput(float dt)
|
||||
// move in X directions
|
||||
p.velocity.x = 0.0f; // rest x, keyboard action will change this
|
||||
if (i->is_action_pressed("ui_left"))
|
||||
gauche();
|
||||
playerState.left = true;
|
||||
if (i->is_action_pressed("ui_right"))
|
||||
droit();
|
||||
playerState.right = true;
|
||||
if (i->is_action_pressed("dash"))
|
||||
playerState.dash = true;
|
||||
if (i->is_action_pressed("attack"))
|
||||
playerState.attack = true;
|
||||
if (i->is_action_pressed("attack2"))
|
||||
playerState.bigattack = true;
|
||||
if (i->is_action_pressed("block"))
|
||||
playerState.block = true;
|
||||
|
||||
|
||||
// update Velocity
|
||||
|
||||
|
||||
// move in Y directions
|
||||
if (i->is_action_pressed("ui_select"))
|
||||
playerState.jump = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::PlayerLogic(float dt)
|
||||
{
|
||||
if (playerState.jump)
|
||||
{
|
||||
// attack en l'air
|
||||
PlayerLogic_Jump(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// attack au sol
|
||||
if (on_ground)
|
||||
{
|
||||
PlayerLogic_OnGround(dt);
|
||||
}
|
||||
else
|
||||
{ // freefall
|
||||
// attack en l'air
|
||||
PlayerLogic_FreeFall(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GestionPlayer::PlayerLogic_Jump(float dt)
|
||||
{
|
||||
if (on_ground)
|
||||
{
|
||||
p.velocity.y = 0.0f;
|
||||
p.velocity.y = power_jump;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.velocity.y += gravity * dt;
|
||||
}
|
||||
if (p.velocity.y > 0.0f)
|
||||
{
|
||||
playerState.jump = false;
|
||||
playerState.freefall = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerState.left)
|
||||
{
|
||||
p.velocity.x = -speed;
|
||||
sprite_player_ptr->play("Jump Up");
|
||||
sprite_player_ptr->set_flip_h(true);
|
||||
}
|
||||
else if (playerState.right)
|
||||
{
|
||||
p.velocity.x = +speed;
|
||||
sprite_player_ptr->play("Jump Up");
|
||||
sprite_player_ptr->set_flip_h(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// move in Y directions
|
||||
if (i->is_action_pressed("ui_select"))
|
||||
saut();
|
||||
void GestionPlayer::PlayerLogic_OnGround(float dt)
|
||||
{
|
||||
p.velocity.y = 0.0f;
|
||||
if (playerState.attack)
|
||||
{
|
||||
sprite_player_ptr->play("attack");
|
||||
}
|
||||
else if (playerState.bigattack)
|
||||
{
|
||||
|
||||
sprite_player_ptr->play("attack2");
|
||||
|
||||
}
|
||||
else if (playerState.dash)
|
||||
{
|
||||
|
||||
sprite_player_ptr->play("dash");
|
||||
p.velocity.x =+ 50;
|
||||
|
||||
}
|
||||
else if (playerState.block)
|
||||
{
|
||||
|
||||
sprite_player_ptr->play("shield");
|
||||
|
||||
|
||||
}
|
||||
else if (playerState.left)
|
||||
{
|
||||
p.velocity.x = -speed;
|
||||
sprite_player_ptr->play("Walk");
|
||||
sprite_player_ptr->set_flip_h(true);
|
||||
}
|
||||
else if (playerState.right)
|
||||
{
|
||||
p.velocity.x = +speed;
|
||||
sprite_player_ptr->play("Walk");
|
||||
sprite_player_ptr->set_flip_h(false);
|
||||
}
|
||||
else if (pv <= 0)
|
||||
{
|
||||
sprite_player_ptr->play("mort");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite_player_ptr->play("Idle");
|
||||
}
|
||||
}
|
||||
|
||||
void GestionPlayer::PlayerLogic_FreeFall(float dt)
|
||||
{
|
||||
p.velocity.x = +speed;
|
||||
if (playerState.left)
|
||||
{
|
||||
p.velocity.x = -speed;
|
||||
sprite_player_ptr->play("jump Down");
|
||||
sprite_player_ptr->set_flip_h(true);
|
||||
}
|
||||
else if (playerState.right)
|
||||
{
|
||||
p.velocity.x = +speed;
|
||||
sprite_player_ptr->play("jump Down");
|
||||
sprite_player_ptr->set_flip_h(false);
|
||||
}
|
||||
p.velocity.y += gravity * dt;
|
||||
}
|
||||
|
||||
void GestionPlayer::setPosition(int x, int y)
|
||||
@ -104,7 +240,7 @@ void GestionPlayer::setPosition(int x, int y)
|
||||
//init Velocity
|
||||
p.velocity = Vector2(0.0f, 0.0f);
|
||||
}
|
||||
|
||||
/*
|
||||
void GestionPlayer::droit()
|
||||
{
|
||||
Godot::print("Deplacement a droite");
|
||||
@ -123,10 +259,7 @@ void GestionPlayer::bas()
|
||||
|
||||
void GestionPlayer::saut()
|
||||
{
|
||||
if (on_ground)
|
||||
{
|
||||
p.velocity.y = power_jump;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::idle()
|
||||
@ -134,6 +267,24 @@ void GestionPlayer::idle()
|
||||
p.velocity.x = 0.0;
|
||||
}
|
||||
|
||||
void GestionPlayer::dash()
|
||||
{
|
||||
p.velocity.x =+1000;
|
||||
sprite_player_ptr->play("dash");
|
||||
}
|
||||
|
||||
void GestionPlayer::attack()
|
||||
{
|
||||
sprite_player_ptr->play("attack");
|
||||
}
|
||||
|
||||
void GestionPlayer::block()
|
||||
{
|
||||
sprite_player_ptr->play("block");
|
||||
}
|
||||
|
||||
void GestionPlayer::bigattack()
|
||||
{
|
||||
sprite_player_ptr->play("attack2");
|
||||
}
|
||||
*/
|
@ -2,7 +2,7 @@
|
||||
#include <CircleShape2D.hpp>
|
||||
#include <CollisionShape2D.hpp>
|
||||
#include <Sprite.hpp>
|
||||
|
||||
#include <AnimatedSprite.hpp>
|
||||
|
||||
|
||||
#include "Player.h"
|
||||
@ -12,7 +12,9 @@ using namespace godot;
|
||||
class GestionPlayer : public KinematicBody2D
|
||||
{
|
||||
public:
|
||||
Sprite* sprite_player_ptr;
|
||||
|
||||
AnimatedSprite* sprite_player_ptr;
|
||||
|
||||
|
||||
Ref<Resource> texture_player_ptr;
|
||||
|
||||
@ -33,19 +35,30 @@ public:
|
||||
Player p;
|
||||
|
||||
public:
|
||||
void traitementInput(float dt);
|
||||
void traitementInput();
|
||||
|
||||
void setPosition(int x, int y);
|
||||
|
||||
private:
|
||||
void droit();
|
||||
void gauche();
|
||||
void bas();
|
||||
void saut();
|
||||
void idle();
|
||||
void attack();
|
||||
//void droit();
|
||||
//void gauche();
|
||||
//void bas();
|
||||
//void saut();
|
||||
//void dash();
|
||||
//void idle();
|
||||
//void attack();
|
||||
//void bigattack();
|
||||
//void block();
|
||||
|
||||
|
||||
void PlayerLogic(float dt);
|
||||
void PlayerLogic_OnGround(float dt);
|
||||
void PlayerLogic_Jump(float dt);
|
||||
void PlayerLogic_FreeFall(float dt);
|
||||
|
||||
public:
|
||||
const float speed = 100.f;
|
||||
float pv = 100;
|
||||
const float GamePlayMultiplicator = 100.0f;
|
||||
const float gravity = 9.8f * GamePlayMultiplicator;
|
||||
const float power_jump = -5.0f * GamePlayMultiplicator;
|
||||
@ -53,10 +66,22 @@ public:
|
||||
bool on_roof = false;
|
||||
bool on_left_wall = false;
|
||||
bool on_right_wall = false;
|
||||
bool right;
|
||||
bool left;
|
||||
bool jump;
|
||||
|
||||
|
||||
struct S_PlayerState
|
||||
{
|
||||
bool right;
|
||||
bool left;
|
||||
bool jump;
|
||||
bool dash;
|
||||
bool idle;
|
||||
bool attack;
|
||||
bool bigattack;
|
||||
bool block;
|
||||
|
||||
bool freefall;
|
||||
|
||||
} playerState;
|
||||
|
||||
private:
|
||||
Vector2 velocity;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "MobsCorpACorpIA.h"
|
||||
#include <ConfigFile.hpp>
|
||||
#include <SpriteFrames.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Texture.hpp>
|
||||
@ -8,7 +9,7 @@
|
||||
|
||||
MobsCorpACorpIA::MobsCorpACorpIA()
|
||||
{
|
||||
sprite_MobsCorpACorp_ptr = Sprite::_new();
|
||||
sprite_MobsCorpACorp_ptr = AnimatedSprite::_new();
|
||||
collision_MobsCorpACorp_ptr = CollisionShape2D::_new();
|
||||
texture_MobsCorpACorp_ptr.instance();
|
||||
texture_MobsCorpACorp_ptr->_new();
|
||||
@ -37,6 +38,7 @@ void MobsCorpACorpIA::_physics_process(float dt)
|
||||
|
||||
void MobsCorpACorpIA::_process(float delta)
|
||||
{
|
||||
animation();
|
||||
}
|
||||
|
||||
void MobsCorpACorpIA::_init()
|
||||
@ -63,20 +65,25 @@ void MobsCorpACorpIA::setupMobsCorpACorp()
|
||||
|
||||
|
||||
//Setup du shape
|
||||
Godot::print("SetUp de Shape Mobs");
|
||||
shape_MobsCorpACorp_ptr.ptr()->_new();
|
||||
|
||||
|
||||
//Chargement de la texture
|
||||
Godot::print("SetUp de Texture Mobs");
|
||||
texture_MobsCorpACorp_ptr = ResourceLoader::get_singleton()->load("res://Character/Fire Elemental Sprite Sheet/fireelemental00.png");
|
||||
|
||||
//setup du sprite
|
||||
Godot::print("SetUp de Sprite Mobs");
|
||||
sprite_MobsCorpACorp_ptr->set_texture(texture_MobsCorpACorp_ptr);
|
||||
//Godot::print("SetUp de Sprite");
|
||||
Ref<SpriteFrames> spriteFrames = ResourceLoader::get_singleton()->load("res://Character/Fire Elemental Sprite Sheet/fireelement.tres");
|
||||
sprite_MobsCorpACorp_ptr->set_sprite_frames(spriteFrames);
|
||||
|
||||
PoolStringArray AnimNames = spriteFrames->get_animation_names();
|
||||
PoolStringArray::Read r = AnimNames.read();
|
||||
Godot::print("Animations Names");
|
||||
for (int i = 0; i < AnimNames.size(); ++i)
|
||||
{
|
||||
Godot::print(r[i]);
|
||||
}
|
||||
|
||||
//setup du collision Shape
|
||||
Godot::print("SetUp de CollisionShape Mobs");
|
||||
collision_MobsCorpACorp_ptr->set_shape(shape_MobsCorpACorp_ptr);
|
||||
}
|
||||
|
||||
|
||||
@ -133,6 +140,32 @@ void MobsCorpACorpIA::mouvement(float dt)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MobsCorpACorpIA::animation()
|
||||
{
|
||||
|
||||
if (m.velocity.x > 0.0f)
|
||||
{
|
||||
sprite_MobsCorpACorp_ptr->play("walk");
|
||||
sprite_MobsCorpACorp_ptr->set_flip_h(false);
|
||||
}
|
||||
else if (m.velocity.x < 0.0f)
|
||||
{
|
||||
sprite_MobsCorpACorp_ptr->play("walk");
|
||||
sprite_MobsCorpACorp_ptr->set_flip_h(true);
|
||||
}
|
||||
else if (pv <=0 )
|
||||
{
|
||||
sprite_MobsCorpACorp_ptr->play("dead");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite_MobsCorpACorp_ptr->play("idle");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MobsCorpACorpIA::droit()
|
||||
|
@ -15,7 +15,7 @@ class MobsCorpACorpIA : public KinematicBody2D
|
||||
{
|
||||
|
||||
public:
|
||||
Sprite* sprite_MobsCorpACorp_ptr;
|
||||
AnimatedSprite* sprite_MobsCorpACorp_ptr;
|
||||
CollisionShape2D* collision_MobsCorpACorp_ptr;
|
||||
|
||||
Ref<Resource> texture_MobsCorpACorp_ptr;
|
||||
@ -35,6 +35,7 @@ public:
|
||||
void _process(float delta);
|
||||
void _init();
|
||||
void _ready();
|
||||
void animation();
|
||||
|
||||
private:
|
||||
void droit();
|
||||
@ -61,6 +62,7 @@ public:
|
||||
public:
|
||||
void Action();
|
||||
const float GamePlayMultiplicator = 100.0f;
|
||||
float pv = 100.0f;
|
||||
const float gravity = 9.8f * GamePlayMultiplicator;
|
||||
const float speed = 50.f;
|
||||
const float power_jump = -2.0f * GamePlayMultiplicator;
|
||||
|
Reference in New Issue
Block a user