我有 6 个未解决的外部问题。我知道这意味着什么,但我不知道如何解决它。
碰撞.cpp
#include "Collision.h"
void Collision::Collide(Entity &entity1, Entity &entity2)
{
if(entity1.getX() + entity1.getWidth() > entity2.getX() ||
entity1.getX() < entity2.getX() + entity2.getWidth() ||
entity1.getY() + entity1.getHeight() > entity2.getY() ||
entity1.getY() < entity2.getY() + entity2.getHeight())
{
entity1.setX(entity1.getX());
entity1.setY(entity1.getY());
}
}
碰撞.h
#ifndef COLLISION_H
#define COLLISION_H
#include "Map.h"
#include "Animation.h"
#include "Entity.h"
class Collision
{
public:
void Collide(Entity &entity1, Entity &entity2);
protected:
Map map;
};
#endif
碰撞被称为
collision.Collide(player, enemy);
实体.h
#ifndef Entity_H
#define Entity_H
#include<SFML/Graphics.hpp>
#include"Animation.h"
#include"Camera.h"
class Entity
{
public:
void Initialize();
void LoadContent();
void Update(sf::RenderWindow &Window);
void Draw(sf::RenderWindow &window);
void setX(float newX);
void setY(float newY);
int getHeight();
int getWidth();
float getX();
float getY();
private:
Camera camera;
float x, y;
int currentFrameX, currentFrameY;
sf::Clock clock;
};
#endif // Entity_H
未解决的外部
1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setX(float)" (?setX@Entity@@QAEXM@Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setY(float)" (?setY@Entity@@QAEXM@Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getHeight(void)" (?getHeight@Entity@@QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getWidth(void)" (?getWidth@Entity@@QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getX(void)" (?getX@Entity@@QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getY(void)" (?getY@Entity@@QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
我认为没有正确重载 Player/Enemy 类中的 Entity getX() 等是一个问题。