mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
Debut mouvement Mob
This commit is contained in:
parent
97f45944db
commit
6c12f02787
@ -52,6 +52,13 @@ void GestionJeu::_ready()
|
||||
void GestionJeu::_process()
|
||||
{
|
||||
gCollision->CheckCollisonSol();
|
||||
|
||||
|
||||
Vector2 posPlayer = gPlayer->get_position();
|
||||
for (MobsCorpACorpIA* m : gMobs->mobs)
|
||||
{
|
||||
m->UpdateTargetPosition(posPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
void GestionJeu::create_scene()
|
||||
@ -60,11 +67,12 @@ void GestionJeu::create_scene()
|
||||
add_child(gTerrain);
|
||||
gMobs->AjoutMobC2C(10, 20, 5, 0, 1, 25);
|
||||
|
||||
for (KinematicBody2D* m : gMobs->mobs)
|
||||
for (MobsCorpACorpIA* m : gMobs->mobs)
|
||||
{
|
||||
auto mob = (MobsCorpACorpIA*) m;
|
||||
Godot::print("Add child mob");
|
||||
add_child(m);
|
||||
m->setPosition(15, 150);
|
||||
}
|
||||
|
||||
}
|
||||
@ -72,6 +80,7 @@ void GestionJeu::create_scene()
|
||||
void GestionJeu::setup_scene()
|
||||
{
|
||||
gPlayer->setPosition(15, 150);
|
||||
|
||||
gTerrain->GenerationCarte();
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
#include "MobsCorpACorpIA.h"
|
||||
#include "MobsIA.h"
|
||||
|
||||
|
||||
class GestionMobs
|
||||
{
|
||||
public :
|
||||
std::vector<KinematicBody2D*> mobs;
|
||||
std::vector<MobsCorpACorpIA*> mobs;
|
||||
|
||||
public:
|
||||
void AjoutMobC2C(int pvMax, int speed, int degat, int cooldown, int rangeDegat, int rangeAgro);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Texture.hpp>
|
||||
#include "MobsCorpACorp.h"
|
||||
#include "GestionPlayer.h"
|
||||
|
||||
MobsCorpACorpIA::MobsCorpACorpIA()
|
||||
{
|
||||
@ -28,9 +29,9 @@ void MobsCorpACorpIA::_register_methods()
|
||||
|
||||
}
|
||||
|
||||
void MobsCorpACorpIA::_physics_process(float delta)
|
||||
void MobsCorpACorpIA::_physics_process(float dt)
|
||||
{
|
||||
mouvement();
|
||||
mouvement(dt);
|
||||
m.velocity = move_and_slide(m.velocity);
|
||||
}
|
||||
|
||||
@ -82,24 +83,77 @@ void MobsCorpACorpIA::setupMobsCorpACorp()
|
||||
void MobsCorpACorpIA::setPosition(int x, int y)
|
||||
{
|
||||
Transform2D t;
|
||||
Vector2 v;
|
||||
Vector2 pos;
|
||||
Size2 s;
|
||||
|
||||
//setup de la size
|
||||
s.x = 1;
|
||||
s.y = 1;
|
||||
v.x = x;
|
||||
v.y = y;
|
||||
t.set_origin(v);
|
||||
pos.x = x;
|
||||
pos.y = y;
|
||||
t.set_origin(pos);
|
||||
t.scale(s);
|
||||
|
||||
set_transform(t);
|
||||
}
|
||||
|
||||
void MobsCorpACorpIA::mouvement()
|
||||
void MobsCorpACorpIA::mouvement(float dt)
|
||||
{
|
||||
Vector2 pos;
|
||||
|
||||
|
||||
|
||||
m.velocity = Vector2(0, 0);
|
||||
m.velocity.y += gravity;
|
||||
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
//saut();
|
||||
}
|
||||
else if (pos.x > TargetPosition.x) {
|
||||
//bas();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
void MobsCorpACorpIA::saut()
|
||||
{
|
||||
|
||||
m.velocity.y = power_jump;
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ private:
|
||||
|
||||
public:
|
||||
MobsCorpACorp m;
|
||||
GestionPlayer* gPlayer;
|
||||
|
||||
public:
|
||||
MobsCorpACorpIA();
|
||||
|
||||
@ -47,7 +47,9 @@ private:
|
||||
void createMobsCorpACorp();
|
||||
void setupMobsCorpACorp();
|
||||
void mouvement(float dt);
|
||||
void setPosition(int x, int y);
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
bool on_ground = false;
|
||||
@ -63,5 +65,9 @@ public:
|
||||
const float speed = 100.f;
|
||||
const float power_jump = -5.0f * GamePlayMultiplicator;
|
||||
|
||||
|
||||
public:
|
||||
Vector2 TargetPosition;
|
||||
public:
|
||||
void UpdateTargetPosition(Vector2 _TargetPosition) { TargetPosition = _TargetPosition; }
|
||||
void setPosition(int x, int y);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user