mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
arbre Etat, plus ajout animation player
This commit is contained in:
parent
cd7f1837a4
commit
c85ccf4f8f
@ -0,0 +1,41 @@
|
|||||||
|
[gd_resource type="SpriteFrames" load_steps=22 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental31.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental10.png" type="Texture" id=2]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental32.png" type="Texture" id=3]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental00.png" type="Texture" id=4]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental05.png" type="Texture" id=5]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental01.png" type="Texture" id=6]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental11.png" type="Texture" id=7]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental13.png" type="Texture" id=8]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental29.png" type="Texture" id=9]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental08.png" type="Texture" id=10]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental06.png" type="Texture" id=11]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental03.png" type="Texture" id=12]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental04.png" type="Texture" id=13]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental28.png" type="Texture" id=14]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental30.png" type="Texture" id=15]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental12.png" type="Texture" id=16]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental02.png" type="Texture" id=17]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental09.png" type="Texture" id=18]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental34.png" type="Texture" id=19]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental35.png" type="Texture" id=20]
|
||||||
|
[ext_resource path="res://Character/Fire Elemental Sprite Sheet/fireelemental33.png" type="Texture" id=21]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
animations = [ {
|
||||||
|
"frames": [ ExtResource( 10 ), ExtResource( 18 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 16 ), ExtResource( 8 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "idle",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [ ExtResource( 4 ), ExtResource( 6 ), ExtResource( 17 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 5 ), ExtResource( 11 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "walk",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [ ExtResource( 14 ), ExtResource( 9 ), ExtResource( 15 ), ExtResource( 1 ), ExtResource( 3 ), ExtResource( 21 ), ExtResource( 19 ), ExtResource( 20 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "dead",
|
||||||
|
"speed": 5.0
|
||||||
|
} ]
|
@ -23,7 +23,7 @@ GestionJeu::GestionJeu()
|
|||||||
|
|
||||||
GestionJeu::~GestionJeu()
|
GestionJeu::~GestionJeu()
|
||||||
{
|
{
|
||||||
delete gPlayer;
|
delete gMobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,10 +25,13 @@ void GestionPlayer::_register_methods()
|
|||||||
|
|
||||||
void GestionPlayer::_process(float dt) // dt = deltaTime
|
void GestionPlayer::_process(float dt) // dt = deltaTime
|
||||||
{
|
{
|
||||||
traitementInput(dt);
|
playerState.right = false;
|
||||||
p.velocity = move_and_slide(p.velocity);
|
playerState.left = false;
|
||||||
animation();
|
|
||||||
|
|
||||||
|
traitementInput();
|
||||||
|
|
||||||
|
PlayerLogic(dt);
|
||||||
|
p.velocity = move_and_slide(p.velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestionPlayer::_init()
|
void GestionPlayer::_init()
|
||||||
@ -67,7 +70,7 @@ void GestionPlayer::setupPlayer()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestionPlayer::traitementInput(float dt)
|
void GestionPlayer::traitementInput()
|
||||||
{
|
{
|
||||||
// manage Inputs
|
// manage Inputs
|
||||||
Input* i = Input::get_singleton();
|
Input* i = Input::get_singleton();
|
||||||
@ -75,59 +78,147 @@ void GestionPlayer::traitementInput(float dt)
|
|||||||
// move in X directions
|
// move in X directions
|
||||||
p.velocity.x = 0.0f; // rest x, keyboard action will change this
|
p.velocity.x = 0.0f; // rest x, keyboard action will change this
|
||||||
if (i->is_action_pressed("ui_left"))
|
if (i->is_action_pressed("ui_left"))
|
||||||
gauche();
|
playerState.left = true;
|
||||||
if (i->is_action_pressed("ui_right"))
|
if (i->is_action_pressed("ui_right"))
|
||||||
droit();
|
playerState.right = true;
|
||||||
if (i->is_action_pressed("dash"))
|
if (i->is_action_pressed("dash"))
|
||||||
dash();
|
playerState.dash = true;
|
||||||
if (i->is_action_pressed("attack"))
|
if (i->is_action_pressed("attack"))
|
||||||
attack();
|
playerState.attack = true;
|
||||||
if (i->is_action_pressed("attack2"))
|
if (i->is_action_pressed("attack2"))
|
||||||
bigattack();
|
playerState.bigattack = true;
|
||||||
if (i->is_action_pressed("block"))
|
if (i->is_action_pressed("block"))
|
||||||
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)
|
if (on_ground)
|
||||||
{
|
{
|
||||||
p.velocity.y = 0.0f;
|
PlayerLogic_OnGround(dt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // freefall
|
||||||
|
// attack en l'air
|
||||||
|
PlayerLogic_FreeFall(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GestionPlayer::PlayerLogic_Jump(float dt)
|
||||||
|
{
|
||||||
|
if (on_ground)
|
||||||
|
{
|
||||||
|
p.velocity.y = power_jump;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p.velocity.y += gravity * dt;
|
p.velocity.y += gravity * dt;
|
||||||
}
|
}
|
||||||
|
if (p.velocity.y > 0.0f)
|
||||||
// move in Y directions
|
{
|
||||||
if (i->is_action_pressed("ui_select"))
|
playerState.jump = false;
|
||||||
saut();
|
playerState.freefall = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
void GestionPlayer::animation()
|
|
||||||
{
|
{
|
||||||
|
if (playerState.left)
|
||||||
if (p.velocity.x > 0.0f)
|
|
||||||
{
|
{
|
||||||
sprite_player_ptr->play("Walk");
|
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);
|
sprite_player_ptr->set_flip_h(false);
|
||||||
}
|
}
|
||||||
else if (p.velocity.x < 0.0f)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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->play("Walk");
|
||||||
sprite_player_ptr->set_flip_h(true);
|
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)
|
else if (pv <= 0)
|
||||||
{
|
{
|
||||||
sprite_player_ptr->play("mort");
|
sprite_player_ptr->play("mort");
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite_player_ptr->play("Idle");
|
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)
|
void GestionPlayer::setPosition(int x, int y)
|
||||||
@ -149,7 +240,7 @@ void GestionPlayer::setPosition(int x, int y)
|
|||||||
//init Velocity
|
//init Velocity
|
||||||
p.velocity = Vector2(0.0f, 0.0f);
|
p.velocity = Vector2(0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void GestionPlayer::droit()
|
void GestionPlayer::droit()
|
||||||
{
|
{
|
||||||
Godot::print("Deplacement a droite");
|
Godot::print("Deplacement a droite");
|
||||||
@ -168,10 +259,7 @@ void GestionPlayer::bas()
|
|||||||
|
|
||||||
void GestionPlayer::saut()
|
void GestionPlayer::saut()
|
||||||
{
|
{
|
||||||
if (on_ground)
|
|
||||||
{
|
|
||||||
p.velocity.y = power_jump;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestionPlayer::idle()
|
void GestionPlayer::idle()
|
||||||
@ -199,3 +287,4 @@ void GestionPlayer::bigattack()
|
|||||||
{
|
{
|
||||||
sprite_player_ptr->play("attack2");
|
sprite_player_ptr->play("attack2");
|
||||||
}
|
}
|
||||||
|
*/
|
@ -35,21 +35,27 @@ public:
|
|||||||
Player p;
|
Player p;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void traitementInput(float dt);
|
void traitementInput();
|
||||||
|
|
||||||
void setPosition(int x, int y);
|
void setPosition(int x, int y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void droit();
|
//void droit();
|
||||||
void gauche();
|
//void gauche();
|
||||||
void bas();
|
//void bas();
|
||||||
void saut();
|
//void saut();
|
||||||
void dash();
|
//void dash();
|
||||||
void idle();
|
//void idle();
|
||||||
void attack();
|
//void attack();
|
||||||
void bigattack();
|
//void bigattack();
|
||||||
void animation();
|
//void block();
|
||||||
void block();
|
|
||||||
|
|
||||||
|
void PlayerLogic(float dt);
|
||||||
|
void PlayerLogic_OnGround(float dt);
|
||||||
|
void PlayerLogic_Jump(float dt);
|
||||||
|
void PlayerLogic_FreeFall(float dt);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const float speed = 100.f;
|
const float speed = 100.f;
|
||||||
float pv = 100;
|
float pv = 100;
|
||||||
@ -60,10 +66,22 @@ public:
|
|||||||
bool on_roof = false;
|
bool on_roof = false;
|
||||||
bool on_left_wall = false;
|
bool on_left_wall = false;
|
||||||
bool on_right_wall = false;
|
bool on_right_wall = false;
|
||||||
|
|
||||||
|
|
||||||
|
struct S_PlayerState
|
||||||
|
{
|
||||||
bool right;
|
bool right;
|
||||||
bool left;
|
bool left;
|
||||||
bool jump;
|
bool jump;
|
||||||
|
bool dash;
|
||||||
|
bool idle;
|
||||||
|
bool attack;
|
||||||
|
bool bigattack;
|
||||||
|
bool block;
|
||||||
|
|
||||||
|
bool freefall;
|
||||||
|
|
||||||
|
} playerState;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector2 velocity;
|
Vector2 velocity;
|
||||||
|
Loading…
Reference in New Issue
Block a user