Witam chciałem dodać do mojej gry maszynę stanów, ale przed implementacją w grze chciałem przetestować działanie. Jest masa błędów i nie potrafie zlokalizować ich przyczyny. Kod jest na ten moment mało wymagający, a nie wiem co jest nie tak. Mam klasę gra, która ma dwie grafiki. Jeden stan drukuje jedną grafikę drugi stan drugą, nacisnięcie przycisku myszy powoduję zmianę stanu.
Według mnie kod powinien działać, a błędy wyglądają mniej więcej tak:
Error C2504 'GameState': base class undefined sfml
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Severity Code Description Project File Line Suppression State
Error C2061 syntax error: identifier 'Game' sfml C:\Programowanie\Nauka\sfml\sfml\Pause.h 8
Kod wygląda tak:
Klasa Game
#pragma once
#include <SFML/Graphics.hpp>
#include "GameState.h"
#include "Menu.h"
#include "Pause.h"
class Game
{
public:
sf::RenderWindow* window;
sf::Event evnt;
GameState *state;
sf::Texture text1;
sf::Texture text2;
sf::Sprite sText1;
sf::Sprite sText2;
void start();
void print1();
void print2();
//void pollEvents(); Nie uzywane
void update();
void handleInput();
Game();
};
void Game::start()
{
while (window->isOpen())
{
handleInput();
update();
window->clear();
window->display();
}
}
Game::Game()
{
window= new sf::RenderWindow(sf::VideoMode(1900, 1080), "SFML works!");
text1.loadFromFile("Test.png");
sText1.setTexture(text1);
text2.loadFromFile("background.png");
sText2.setTexture(text1);
state = new Menu();
}
void Game::print1()
{
window->draw(sText1);
}
void Game::update()
{
state->Update(*this);
}
void Game::print2()
{
window->draw(sText2);
}
void Game::handleInput()
{
while (window->pollEvent(evnt))
{
GameState* tmp = state->handleInput(evnt);
if (tmp != NULL)
{
delete state;
state = tmp;
}
}
}
Klasa abstrakcyjna GameState
#pragma once
#include "Game.h"
class GameState
{
protected:
public:
virtual void Update(Game &gra )=0;
virtual GameState* handleInput(sf::Event evnt)=0;
};
Klasa Pauza
#pragma once
#include "GameState.h"
#include "Menu.h"
class Pause:public GameState
{
public:
void Update(Game& gra);
GameState* handleInput(sf::Event evnt);
};
#include "Pause.h"
void Pause::Update(Game& gra)
{
gra.print1();
}
GameState* Pause::handleInput(sf::Event evnt)
{
if (evnt.type == sf::Event::MouseButtonPressed)
{
return new Menu();
}
else
{
return NULL;
}
}
Klasa Menu jest identyczna do klasy Pauza tylko zwraca Pauze