mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
ajout animation mobs+ input player + animation
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
#include <Input.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Texture.hpp>
|
||||
|
||||
#include <InputEventKey.hpp>
|
||||
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");
|
||||
}
|
@ -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;
|
||||
|
@ -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