Ey,
I need some little help with my game. I'm trying to change the gamestate in the intro class but it gives alot of errors.
Intro.h
#pragma once
#include "SpriteBatch.h"
#include "GameState.h"
class Intro
{
public:
Intro();
~Intro();
void Update(GameState* gameState);
void Draw(DirectX::SpriteBatch* spriteBatch);
private:
float _timer = 0.0f;
};
Intro.cpp
#include "Intro.h"
#include "LoadContent.h"
#include "SimpleMath.h"
Intro::Intro()
{
LoadContent::InitIntro();
if (!LoadContent::isLoaded("Block"))
LoadContent::LoadTexture(L"Images/Block.dds", "Block");
}
Intro::~Intro()
{
}
void Intro::Update(GameState* gameState)
{
if (_timer < 10)
_timer += 0.1;
else
gameState->SwitchState(GameState::ScreenType::MenuScreen);
}
void Intro::Draw(DirectX::SpriteBatch* spriteBatch)
{
spriteBatch->Draw(LoadContent::GetTexture("Block"), DirectX::SimpleMath::Vector2(170, 196), DirectX::Colors::White);
}
GameState.h
#pragma once
#include "SpriteBatch.h"
#include "Menu.h"
#include "SwitchScreen.h"
#include "Intro.h"
class GameState
{
public:
GameState();
~GameState();
void Update();
void Draw(DirectX::SpriteBatch* spriteBatch, DirectX::SpriteFont* spriteFont);
public:
enum ScreenType{Direct, MenuScreen, Game};
private:
ScreenType _screenType;
Intro* _screen;
Menu* _menu;
SwitchScreen* _switch;
public:
void GameState::SwitchState(ScreenType switchtype);
};
GameState.cpp
#pragma once
#include "GameState.h"
GameState::GameState()
{
_switch = new SwitchScreen();
_screenType = ScreenType::Direct;
SwitchState(_screenType);
}
GameState::~GameState()
{
}
void GameState::Update()
{
_switch->Update();
switch (_screenType)
{
case GameState::Direct:
_screen->Update(this);
break;
case GameState::MenuScreen:
_menu->Update();
break;
case GameState::Game:
break;
default:
break;
}
}
void GameState::Draw(DirectX::SpriteBatch* spriteBatch, DirectX::SpriteFont* spriteFont)
{
switch (_screenType)
{
case GameState::Direct:
_screen->Draw(spriteBatch);
break;
case GameState::MenuScreen:
_menu->Draw(spriteBatch, spriteFont);
break;
case GameState::Game:
break;
default:
break;
}
_switch->Draw(spriteBatch);
}
void GameState::SwitchState(ScreenType switchtype)
{
if (!_switch->GetUpdate())
{
_switch = new SwitchScreen();
}
else {
if (_switch->GetUpdate())
{
_screen = NULL;
_menu = NULL;
switch (switchtype)
{
case GameState::Direct:
_screen = new Intro();
break;
case GameState::MenuScreen:
_menu = new Menu();
break;
case GameState::Game:
break;
default:
break;
}
//_switch->SetSwitch(false);
}
}
}
Error 1 error C2061: syntax error : identifier 'GameState' \jelly\intro.h 11
Error 2 error C2061: syntax error : identifier 'GameState' \jelly\intro.h 11
Error 6 error C2061: syntax error : identifier 'GameState' \jelly\intro.h 11
Error 3 error C2143: syntax error : missing ';' before '*' \jelly\gamestate.h 23
Error 7 error C2660: 'Intro::Update' : function does not take 1 arguments \jelly\gamestate.cpp 24
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \jelly\gamestate.h 23
Warning 5 warning C4305: '+=' : truncation from 'double' to 'float' \jelly\intro.cpp 21
Thank you