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()
|
||||
{
|
||||
delete gPlayer;
|
||||
delete gMobs;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,10 +25,13 @@ void GestionPlayer::_register_methods()
|
||||
|
||||
void GestionPlayer::_process(float dt) // dt = deltaTime
|
||||
{
|
||||
traitementInput(dt);
|
||||
p.velocity = move_and_slide(p.velocity);
|
||||
animation();
|
||||
playerState.right = false;
|
||||
playerState.left = false;
|
||||
|
||||
traitementInput();
|
||||
|
||||
PlayerLogic(dt);
|
||||
p.velocity = move_and_slide(p.velocity);
|
||||
}
|
||||
|
||||
void GestionPlayer::_init()
|
||||
@ -67,7 +70,7 @@ void GestionPlayer::setupPlayer()
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::traitementInput(float dt)
|
||||
void GestionPlayer::traitementInput()
|
||||
{
|
||||
// manage Inputs
|
||||
Input* i = Input::get_singleton();
|
||||
@ -75,59 +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"))
|
||||
dash();
|
||||
playerState.dash = true;
|
||||
if (i->is_action_pressed("attack"))
|
||||
attack();
|
||||
playerState.attack = true;
|
||||
if (i->is_action_pressed("attack2"))
|
||||
bigattack();
|
||||
playerState.bigattack = true;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// move in Y directions
|
||||
if (i->is_action_pressed("ui_select"))
|
||||
saut();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GestionPlayer::animation()
|
||||
void GestionPlayer::PlayerLogic_OnGround(float dt)
|
||||
{
|
||||
|
||||
if (p.velocity.x > 0.0f)
|
||||
p.velocity.y = 0.0f;
|
||||
if (playerState.attack)
|
||||
{
|
||||
sprite_player_ptr->play("Walk");
|
||||
sprite_player_ptr->set_flip_h(false);
|
||||
sprite_player_ptr->play("attack");
|
||||
}
|
||||
else if (p.velocity.x < 0.0f)
|
||||
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(pv <= 0)
|
||||
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)
|
||||
@ -149,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");
|
||||
@ -168,10 +259,7 @@ void GestionPlayer::bas()
|
||||
|
||||
void GestionPlayer::saut()
|
||||
{
|
||||
if (on_ground)
|
||||
{
|
||||
p.velocity.y = power_jump;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GestionPlayer::idle()
|
||||
@ -198,4 +286,5 @@ void GestionPlayer::block()
|
||||
void GestionPlayer::bigattack()
|
||||
{
|
||||
sprite_player_ptr->play("attack2");
|
||||
}
|
||||
}
|
||||
*/
|
@ -35,21 +35,27 @@ 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 dash();
|
||||
void idle();
|
||||
void attack();
|
||||
void bigattack();
|
||||
void animation();
|
||||
void block();
|
||||
//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;
|
||||
@ -60,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;
|
||||
|
Loading…
Reference in New Issue
Block a user