mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
195 lines
3.4 KiB
C++
195 lines
3.4 KiB
C++
#include "MobsCorpACorpIA.h"
|
|
#include <ConfigFile.hpp>
|
|
#include <SpriteFrames.hpp>
|
|
#include <Input.hpp>
|
|
#include <ResourceLoader.hpp>
|
|
#include <Texture.hpp>
|
|
#include "MobsCorpACorp.h"
|
|
#include "GestionPlayer.h"
|
|
|
|
MobsCorpACorpIA::MobsCorpACorpIA()
|
|
{
|
|
sprite_MobsCorpACorp_ptr = AnimatedSprite::_new();
|
|
collision_MobsCorpACorp_ptr = CollisionShape2D::_new();
|
|
texture_MobsCorpACorp_ptr.instance();
|
|
texture_MobsCorpACorp_ptr->_new();
|
|
shape_MobsCorpACorp_ptr.instance();
|
|
shape_MobsCorpACorp_ptr->_new();
|
|
|
|
|
|
}
|
|
|
|
void MobsCorpACorpIA::_register_methods()
|
|
{
|
|
Godot::print("register Mobs...");
|
|
register_method("_physics_process", &MobsCorpACorpIA::_physics_process);
|
|
register_method("_process", &MobsCorpACorpIA::_process);
|
|
register_method("_init", &MobsCorpACorpIA::_init);
|
|
register_method("_ready", &MobsCorpACorpIA::_ready);
|
|
Godot::print("register Mobs OK!");
|
|
|
|
}
|
|
|
|
void MobsCorpACorpIA::_physics_process(float dt)
|
|
{
|
|
mouvement(dt);
|
|
m.velocity = move_and_slide(m.velocity);
|
|
}
|
|
|
|
void MobsCorpACorpIA::_process(float delta)
|
|
{
|
|
animation();
|
|
}
|
|
|
|
void MobsCorpACorpIA::_init()
|
|
{
|
|
Godot::print("init Mobs");
|
|
createMobsCorpACorp();
|
|
}
|
|
|
|
void MobsCorpACorpIA::createMobsCorpACorp()
|
|
{
|
|
add_child(sprite_MobsCorpACorp_ptr);
|
|
add_child(collision_MobsCorpACorp_ptr);
|
|
Godot::print("Creation mobs");
|
|
|
|
}
|
|
void MobsCorpACorpIA::_ready()
|
|
{
|
|
setupMobsCorpACorp();
|
|
|
|
}
|
|
|
|
void MobsCorpACorpIA::setupMobsCorpACorp()
|
|
{
|
|
|
|
|
|
//Setup du shape
|
|
|
|
|
|
//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");
|
|
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]);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void MobsCorpACorpIA::setPosition(int x, int y)
|
|
{
|
|
Transform2D t;
|
|
Vector2 pos;
|
|
Size2 s;
|
|
|
|
//setup de la size
|
|
s.x = 1;
|
|
s.y = 1;
|
|
pos.x = x;
|
|
pos.y = y;
|
|
t.set_origin(pos);
|
|
t.scale(s);
|
|
|
|
set_transform(t);
|
|
}
|
|
|
|
void MobsCorpACorpIA::mouvement(float dt)
|
|
{
|
|
|
|
Vector2 pos = get_position();
|
|
|
|
|
|
|
|
m.velocity = Vector2(0, 0);
|
|
|
|
|
|
|
|
|
|
if (on_ground)
|
|
{
|
|
m.velocity.y = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
//m.velocity.y += gravity * dt;
|
|
}
|
|
|
|
if (pos.x < TargetPosition.x) {
|
|
droit();
|
|
}else if (pos.x > TargetPosition.x) {
|
|
gauche();
|
|
}
|
|
|
|
if (pos.y < TargetPosition.y) {
|
|
|
|
bas();
|
|
}
|
|
else if (pos.x > TargetPosition.x) {
|
|
saut();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
{
|
|
Godot::print("Deplacement mob a droite");
|
|
m.velocity.x = speed;
|
|
}
|
|
|
|
void MobsCorpACorpIA::gauche()
|
|
{
|
|
Godot::print("Deplacement mob a gauche");
|
|
m.velocity.x = -speed;
|
|
}
|
|
|
|
void MobsCorpACorpIA::bas()
|
|
{
|
|
m.velocity.y = -power_jump;
|
|
}
|
|
|
|
void MobsCorpACorpIA::saut()
|
|
{
|
|
|
|
m.velocity.y = power_jump;
|
|
|
|
}
|
|
|