Hi, I'm "doing" a game like practice ... I need to pass by reference a player data type to a function in the enemy class, I can not directly add the "jugador.h"
in "enemy.h"
since it's included in another header, that's why I need to declare it by ifndef
.. here the code
#ifndef JUGADOR_H
#define JUGADOR_H
class Jugador;
class Enemy
{
public:
sf::Texture texturaEnemy;
sf::Sprite spriteEnemy;
sf::IntRect rectEnemy;
sf::Clock clock, frame;
sf::Time time;
sf::Text vidaTexto;
sf::Font vidaFuente;
bool repetir = true;
bool movimiento = true;
int speed = 50;
int orientacion = 0;
int balas = 0;
float x = 0;
float y = 0;
float delta;
public:
Enemy();
void Inicializar();
void EnemyMovement(Jugador &jugador);
void Movement();
void EnemyDraw(sf::RenderWindow &window);
void Collision(Jugador &jugador);
void UpdateEnemy(sf::RenderWindow &window, Jugador &jugador);
};
#endif
As you can see use #ifndef
to include the player class, below you will see the methods of the class enemy
to which I am going by reference the type of data player &jugador
, and here is where I have the problem :
void Enemy::EnemyMovement(Jugador &jugador) {
time = clock.restart();
delta = time.asSeconds();
int diferenciaX = spriteEnemy.getPosition().x - error;
if (diferenciaX > -1 && diferenciaX < 1) {
movimiento = true;
}
else {
movimiento = false;
}
if (spriteEnemy.getPosition().y < error && movimiento) {
rectEnemy.top = 0;
spriteEnemy.setPosition(spriteEnemy.getPosition().x, spriteEnemy.getPosition().y + speed * delta);
if (frame.getElapsedTime().asSeconds() > 0.2f) {
Movement();
}
}
at the time of writing player. I do not get the variables that I have in the player class to be able to modify them from this method ... if anyone knows please thanks