我现在正在对 sfml 中的碰撞进行测试。但是,当我运行程序时出现错误。
这是我的代码编辑:新代码
主文件
#include "Collision.h"
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML TEST");
window.setFramerateLimit(30);
sf::RectangleShape rectangle(sf::Vector2f(50, 120));
rectangle.setPosition(300, 300);
sf::View view;
view.setCenter(sf::Vector2f(300, 300));
view.setSize(sf::Vector2f(250, 250));
int moveRight = 0;
int posX;
int posY;
Collision ct();
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
//movement just right for this instance
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
moveRight = 3;
for(moveRight; moveRight > 0; moveRight--)
{
rectangle.move(1, 0);
posX = rectangle.getPosition().x;
posY = rectangle.getPosition().y;
if(ct.throneRoom(posX, posY) == true)
{
rectangle.move(1, 0);
moveRight = 0;
}
else
{
view.move(1, 0);
}
}
}
window.setView(view);
window.clear();
window.draw(rectangle);
window.display();
}
}
碰撞.h
#ifndef COLLISION_H
#define COLLISION_H
class Collision
{
public:
Collision();
bool throneRoom(int xPos, int yPos);
protected:
private:
};
#endif // COLLISION_H
碰撞.cpp
#include "Collision.h"
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace std;
Collision::Collision()
{
}
bool Collision::throneRoom(int xPos, int yPos)
{
if(xPos > 500)
return true;
else
return false;
}
我得到的错误说:
warning: error: request for member 'throneRoom' in 'ct', which is of non-class type 'Collision()'
仍然不知道发生了什么。