From 77ad3c34d404bcd9d203d6c7edb5a2b4f53aa2fb Mon Sep 17 00:00:00 2001 From: gwiz Date: Sat, 2 May 2020 12:31:30 +0200 Subject: [PATCH 1/3] debut mouvement animation player --- .../Hero Knight/HeroKnight/HeroKnight.tres | 132 ++++++++++++++++++ .../DungeonAndDemaonScript/GestionPlayer.cpp | 38 ++++- .../DungeonAndDemaonScript/GestionPlayer.h | 7 +- 3 files changed, 172 insertions(+), 5 deletions(-) create mode 100644 DungeonAndDeamon/Character/Hero Knight/HeroKnight/HeroKnight.tres diff --git a/DungeonAndDeamon/Character/Hero Knight/HeroKnight/HeroKnight.tres b/DungeonAndDeamon/Character/Hero Knight/HeroKnight/HeroKnight.tres new file mode 100644 index 0000000..b82ba79 --- /dev/null +++ b/DungeonAndDeamon/Character/Hero Knight/HeroKnight/HeroKnight.tres @@ -0,0 +1,132 @@ +[gd_resource type="SpriteFrames" load_steps=73 format=2] + +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_07.png" type="Texture" id=1] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_10.png" type="Texture" id=2] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_16.png" type="Texture" id=3] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_04.png" type="Texture" id=4] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_06.png" type="Texture" id=5] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_15.png" type="Texture" id=6] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_02.png" type="Texture" id=7] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_03.png" type="Texture" id=8] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_09.png" type="Texture" id=9] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_14.png" type="Texture" id=10] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_01.png" type="Texture" id=11] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_11.png" type="Texture" id=12] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_13.png" type="Texture" id=13] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_05.png" type="Texture" id=14] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_12.png" type="Texture" id=15] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_17.png" type="Texture" id=16] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_18.png" type="Texture" id=17] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_39.png" type="Texture" id=18] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_44.png" type="Texture" id=19] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_42.png" type="Texture" id=20] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_43.png" type="Texture" id=21] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_40.png" type="Texture" id=22] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_41.png" type="Texture" id=23] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_45.png" type="Texture" id=24] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_64.png" type="Texture" id=25] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_60.png" type="Texture" id=26] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_62.png" type="Texture" id=27] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_61.png" type="Texture" id=28] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_63.png" type="Texture" id=29] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_51.png" type="Texture" id=30] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_56.png" type="Texture" id=31] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_57.png" type="Texture" id=32] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_50.png" type="Texture" id=33] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_65.png" type="Texture" id=34] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_47.png" type="Texture" id=35] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_46.png" type="Texture" id=36] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_55.png" type="Texture" id=37] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_23.png" type="Texture" id=38] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_36.png" type="Texture" id=39] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_31.png" type="Texture" id=40] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_24.png" type="Texture" id=41] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_33.png" type="Texture" id=42] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_37.png" type="Texture" id=43] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_52.png" type="Texture" id=44] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_58.png" type="Texture" id=45] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_22.png" type="Texture" id=46] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_48.png" type="Texture" id=47] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_20.png" type="Texture" id=48] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_32.png" type="Texture" id=49] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_19.png" type="Texture" id=50] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_34.png" type="Texture" id=51] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_35.png" type="Texture" id=52] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_30.png" type="Texture" id=53] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_49.png" type="Texture" id=54] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_21.png" type="Texture" id=55] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_53.png" type="Texture" id=56] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_54.png" type="Texture" id=57] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_68.png" type="Texture" id=58] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_70.png" type="Texture" id=59] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_71.png" type="Texture" id=60] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_77.png" type="Texture" id=61] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_76.png" type="Texture" id=62] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_80.png" type="Texture" id=63] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_73.png" type="Texture" id=64] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_78.png" type="Texture" id=65] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_74.png" type="Texture" id=66] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_69.png" type="Texture" id=67] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_72.png" type="Texture" id=68] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_75.png" type="Texture" id=69] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_79.png" type="Texture" id=70] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_67.png" type="Texture" id=71] +[ext_resource path="res://Character/Hero Knight/HeroKnight/Layer 1_sprite_66.png" type="Texture" id=72] + +[resource] +animations = [ { +"frames": [ ExtResource( 11 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 14 ), ExtResource( 5 ), ExtResource( 1 ) ], +"loop": true, +"name": "Idle", +"speed": 4.0 +}, { +"frames": [ ExtResource( 36 ), ExtResource( 35 ), ExtResource( 47 ), ExtResource( 54 ) ], +"loop": true, +"name": "degat", +"speed": 5.0 +}, { +"frames": [ ExtResource( 33 ), ExtResource( 30 ), ExtResource( 44 ), ExtResource( 56 ), ExtResource( 57 ), ExtResource( 37 ), ExtResource( 31 ), ExtResource( 32 ), ExtResource( 45 ) ], +"loop": true, +"name": "mort", +"speed": 5.0 +}, { +"frames": [ ExtResource( 18 ), ExtResource( 22 ), ExtResource( 23 ) ], +"loop": true, +"name": "Jump Up", +"speed": 5.0 +}, { +"frames": [ ExtResource( 53 ), ExtResource( 40 ), ExtResource( 49 ), ExtResource( 42 ), ExtResource( 51 ), ExtResource( 52 ), ExtResource( 39 ), ExtResource( 43 ) ], +"loop": true, +"name": "attack2", +"speed": 5.0 +}, { +"frames": [ ExtResource( 26 ), ExtResource( 28 ), ExtResource( 27 ), ExtResource( 29 ), ExtResource( 25 ), ExtResource( 34 ), ExtResource( 72 ), ExtResource( 71 ) ], +"loop": true, +"name": "shield", +"speed": 5.0 +}, { +"frames": [ ExtResource( 9 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 15 ), ExtResource( 13 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 3 ), ExtResource( 16 ), ExtResource( 17 ) ], +"loop": true, +"name": "Walk", +"speed": 5.0 +}, { +"frames": [ ExtResource( 20 ), ExtResource( 21 ), ExtResource( 19 ), ExtResource( 24 ) ], +"loop": true, +"name": "jump Down", +"speed": 5.0 +}, { +"frames": [ ExtResource( 50 ), ExtResource( 50 ), ExtResource( 48 ), ExtResource( 55 ), ExtResource( 46 ), ExtResource( 41 ), ExtResource( 38 ) ], +"loop": true, +"name": "attack", +"speed": 5.0 +}, { +"frames": [ ExtResource( 68 ), ExtResource( 64 ), ExtResource( 66 ), ExtResource( 69 ), ExtResource( 62 ), ExtResource( 61 ), ExtResource( 65 ), ExtResource( 70 ), ExtResource( 63 ) ], +"loop": true, +"name": "dash", +"speed": 5.0 +}, { +"frames": [ ExtResource( 58 ), ExtResource( 67 ), ExtResource( 59 ), ExtResource( 60 ) ], +"loop": true, +"name": "block", +"speed": 5.0 +} ] diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp index 34575f8..4124680 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp @@ -1,5 +1,5 @@ #include "GestionPlayer.h" - +#include #include #include #include @@ -7,8 +7,8 @@ GestionPlayer::GestionPlayer() { - sprite_player_ptr = Sprite::_new(); + sprite_player_ptr = AnimatedSprite::_new(); texture_player_ptr.instance(); texture_player_ptr->_new(); } @@ -27,6 +27,7 @@ void GestionPlayer::_process(float dt) // dt = deltaTime { traitementInput(dt); p.velocity = move_and_slide(p.velocity); + animation(); } @@ -53,7 +54,17 @@ void GestionPlayer::setupPlayer() //setup du sprite //Godot::print("SetUp de Sprite"); - sprite_player_ptr->set_texture(texture_player_ptr); + Ref 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) @@ -85,6 +96,27 @@ void GestionPlayer::traitementInput(float dt) } +void GestionPlayer::animation() +{ + + if (p.velocity.x > 0.0f) + { + sprite_player_ptr->play("Walk"); + sprite_player_ptr->set_flip_h(false); + } + else if (p.velocity.x < 0.0f) + { + sprite_player_ptr->play("Walk"); + sprite_player_ptr->set_flip_h(true); + } + else + { + sprite_player_ptr->play("Idle"); + } + + +} + void GestionPlayer::setPosition(int x, int y) { Transform2D t; diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h index 38e18b2..b73f7ca 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h @@ -2,7 +2,7 @@ #include #include #include - +#include #include "Player.h" @@ -12,7 +12,9 @@ using namespace godot; class GestionPlayer : public KinematicBody2D { public: - Sprite* sprite_player_ptr; + + AnimatedSprite* sprite_player_ptr; + Ref texture_player_ptr; @@ -44,6 +46,7 @@ private: void saut(); void idle(); void attack(); + void animation(); public: const float speed = 100.f; const float GamePlayMultiplicator = 100.0f; From cd7f1837a4d388809120835c63b9e4e40cd27719 Mon Sep 17 00:00:00 2001 From: Estrela Allan p1923381 Date: Sat, 2 May 2020 13:47:22 +0200 Subject: [PATCH 2/3] ajout animation mobs+ input player + animation --- DungeonAndDeamon/DungeonAndDaemon.pck | Bin 1482656 -> 1496896 bytes DungeonAndDeamon/project.godot | 20 +++++++ DungeonAndDeamon/root.tscn | 2 +- .../DungeonAndDemaonScript/GestionPlayer.cpp | 32 +++++++++++- .../DungeonAndDemaonScript/GestionPlayer.h | 4 ++ .../MobsCorpACorpIA.cpp | 49 +++++++++++++++--- .../DungeonAndDemaonScript/MobsCorpACorpIA.h | 4 +- 7 files changed, 100 insertions(+), 11 deletions(-) diff --git a/DungeonAndDeamon/DungeonAndDaemon.pck b/DungeonAndDeamon/DungeonAnd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UC81mhxhzl`sZSPa9&_91E)yXEjl8oaZ7CFCV} zLKt6cS*=(D%L&1Ey5x5ZB-(+A8oek)UkfwR?UV}SI>m6tQ7Ip zdJzm`Xf;>xbJUc%Mf5H76MHx2Kf|m~BSd_C5aoOi=iwziQT#bo;{AG-*}jLHmX80pqtp9g3-b2G8g-a$%-N3D@XMvRV3G=m+*$?Z01$k ziS`t27$&Bd;P@u*(ht#3f^WcF%a%RpOz{Vd)T*-Ost)yAT(a$B9WJH3qeH<~m)!HI z4qaPaBASlTtsH3*)E86{$i)?6DuA_)X|2R@603x!p4n}LmxNu26JIMzoosRl5t2Lt z{kK^8WB5tcNzwv`%F-(I6QvsFMy9m|og}awBShMby6t>+00Si4f&3gv6K6gfl?25GYb*I zlco1^WsBfXu^NNKWJg6apKV1qv8gcn*r6HwiL?hp#B>nV-{Ardqn89*F~;|$ zpVEFIy277mr*yn~UCYoh^b7+-VN765WMnZW^}TyNyZ;4Eb@MjYqVlfS3XQY+qWp6# dBa #include #include - +#include GestionPlayer::GestionPlayer() { @@ -78,6 +78,14 @@ void GestionPlayer::traitementInput(float dt) gauche(); if (i->is_action_pressed("ui_right")) droit(); + if (i->is_action_pressed("dash")) + dash(); + if (i->is_action_pressed("attack")) + attack(); + if (i->is_action_pressed("attack2")) + bigattack(); + if (i->is_action_pressed("block")) + block(); // update Velocity @@ -109,6 +117,11 @@ void GestionPlayer::animation() sprite_player_ptr->play("Walk"); sprite_player_ptr->set_flip_h(true); } + else if(pv <= 0) + { + sprite_player_ptr->play("mort"); + } + else { sprite_player_ptr->play("Idle"); @@ -166,6 +179,23 @@ 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"); +} \ No newline at end of file diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h index b73f7ca..1f3b1c7 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h @@ -44,11 +44,15 @@ private: void gauche(); void bas(); void saut(); + void dash(); void idle(); void attack(); + void bigattack(); void animation(); + void block(); 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; diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.cpp index 4ce246f..a6a6dda 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.cpp @@ -1,5 +1,6 @@ #include "MobsCorpACorpIA.h" #include +#include #include #include #include @@ -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 = 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() diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.h index fa48d51..2973e01 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/MobsCorpACorpIA.h @@ -15,7 +15,7 @@ class MobsCorpACorpIA : public KinematicBody2D { public: - Sprite* sprite_MobsCorpACorp_ptr; + AnimatedSprite* sprite_MobsCorpACorp_ptr; CollisionShape2D* collision_MobsCorpACorp_ptr; Ref 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; From c85ccf4f8fda7117dbac8bbf9000f254f9ce3519 Mon Sep 17 00:00:00 2001 From: Estrela Allan p1923381 Date: Sat, 2 May 2020 16:10:48 +0200 Subject: [PATCH 3/3] arbre Etat, plus ajout animation player --- .../fireelement.tres | 41 +++++ .../DungeonAndDemaonScript/GestionJeu.cpp | 2 +- .../DungeonAndDemaonScript/GestionPlayer.cpp | 153 ++++++++++++++---- .../DungeonAndDemaonScript/GestionPlayer.h | 46 ++++-- 4 files changed, 195 insertions(+), 47 deletions(-) create mode 100644 DungeonAndDeamon/Character/Fire Elemental Sprite Sheet/fireelement.tres diff --git a/DungeonAndDeamon/Character/Fire Elemental Sprite Sheet/fireelement.tres b/DungeonAndDeamon/Character/Fire Elemental Sprite Sheet/fireelement.tres new file mode 100644 index 0000000..3fe26c0 --- /dev/null +++ b/DungeonAndDeamon/Character/Fire Elemental Sprite Sheet/fireelement.tres @@ -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 +} ] diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp index d8905f1..8d76eb1 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionJeu.cpp @@ -23,7 +23,7 @@ GestionJeu::GestionJeu() GestionJeu::~GestionJeu() { - delete gPlayer; + delete gMobs; } diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp index cf7b75f..802f7ea 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.cpp @@ -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"); -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h index 1f3b1c7..0496f45 100644 --- a/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h +++ b/DungeonAndDeamonScript/DungeonAndDemaonScript/GestionPlayer.h @@ -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;