*
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
#include "states/StateGame.h"
|
||||
#include "MyGame.h"
|
||||
|
||||
StateGame::StateGame(const String& name, MyGame* engine) : IGameState(name)
|
||||
{
|
||||
pGame = engine;
|
||||
pGame->GetInput()->AddListener(pGame->GetGraphics()->GetGUI());
|
||||
}
|
||||
void StateGame::Update()
|
||||
{
|
||||
playerActions.Reset();
|
||||
//grab input actions
|
||||
|
||||
int num = pGame->GetActionMap()->Size();
|
||||
pGame->GetActionMap()->ResetIterator();
|
||||
for(int i = 0; i< num; i++)
|
||||
{
|
||||
Key k = pGame->GetActionMap()->CurrentKey();
|
||||
GameAction a = pGame->GetActionMap()->CurrentAction();
|
||||
|
||||
if(k == KEY_WHEEL_UP | k == KEY_WHEEL_DOWN)
|
||||
{
|
||||
int state = pGame->GetInput()->GetMouseWheel();
|
||||
if(state > 0 && k == KEY_WHEEL_UP)
|
||||
{
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
else if(state < 0 && k == KEY_WHEEL_DOWN)
|
||||
{
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
}
|
||||
else if(k == KEY_AXIS_X)
|
||||
{
|
||||
int i = pGame->GetInput()->GetMouseRelativeX();
|
||||
if(i)
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
else if(k == KEY_AXIS_Y)
|
||||
{
|
||||
int i = pGame->GetInput()->GetMouseRelativeY();
|
||||
if(i)
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
else if(k > KEY_MOUSE_OFFSET)
|
||||
{
|
||||
if(pGame->GetInput()->MouseButtonPressed(k))
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pGame->GetInput()->KeyPressed(k))
|
||||
{
|
||||
playerActions.AddAction(a);
|
||||
}
|
||||
}
|
||||
pGame->GetActionMap()->MoveNext();
|
||||
}
|
||||
|
||||
if(pGame->player)
|
||||
pGame->player->ProcessActions(&playerActions);
|
||||
|
||||
float moveSpeed = 7.0f;
|
||||
if(pGame->GetInput()->KeyPressed(KEY_ESCAPE))
|
||||
{
|
||||
pGame->Exit();
|
||||
}
|
||||
|
||||
pGame->GetWorld()->Update(pGame->GetGraphics()->GetTimeElapsed());
|
||||
pGame->GetGraphics()->GetGUI()->Update(pGame->GetGraphics()->GetTimeElapsed());
|
||||
pGame->GetPhysics()->Tick(pGame->GetGraphics()->GetTimeElapsed());
|
||||
pGame->GetGraphics()->GetSceneManager()->GetActiveScene()->Update(pGame->GetGraphics()->GetTimeElapsed());
|
||||
/*if(pGame->GetInput()->KeyPressed(KEY_W))
|
||||
{
|
||||
Vec3f pos = pGame->cam.getPosition();
|
||||
Vec3f dir = pGame->cam.getDirection();
|
||||
pos += dir * pGame->GetGraphics()->getTimeElapsed() * moveSpeed;
|
||||
pGame->cam.setPosition(pos);
|
||||
}
|
||||
if(pGame->GetInput()->KeyPressed(KEY_S))
|
||||
{
|
||||
Vec3f pos = pGame->cam.getPosition();
|
||||
Vec3f dir = pGame->cam.getDirection();
|
||||
pos += dir * -pGame->GetGraphics()->getTimeElapsed() * moveSpeed;
|
||||
pGame->cam.setPosition(pos);
|
||||
}
|
||||
if(pGame->GetInput()->KeyPressed(KEY_A))
|
||||
{
|
||||
Vec3f pos = pGame->cam.getPosition();
|
||||
Vec3f dir = pGame->cam.getRight();
|
||||
pos += dir * -pGame->GetGraphics()->getTimeElapsed()* moveSpeed;
|
||||
pGame->cam.setPosition(pos);
|
||||
}
|
||||
if(pGame->GetInput()->KeyPressed(KEY_D))
|
||||
{
|
||||
Vec3f pos = pGame->cam.getPosition();
|
||||
Vec3f dir = pGame->cam.getRight();
|
||||
pos += dir * pGame->GetGraphics()->getTimeElapsed()* moveSpeed;
|
||||
pGame->cam.setPosition(pos);
|
||||
}
|
||||
|
||||
if(pGame->GetInput()->GetMouseRelativeX() != 0)
|
||||
{
|
||||
pGame->cam.Yaw((float)pGame->GetInput()->GetMouseRelativeX() / 300.0f);
|
||||
}
|
||||
if(pGame->GetInput()->GetMouseRelativeY() != 0)
|
||||
{
|
||||
pGame->cam.Pitch((float)pGame->GetInput()->GetMouseRelativeY() / 300.0f);
|
||||
}*/
|
||||
}
|
||||
|
||||
bool StateGame::KeyDown( Key key, unsigned int text, const std::string& str )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateGame::KeyUp( Key key, unsigned int text, const std::string& str )
|
||||
{
|
||||
if(key == KEY_M)
|
||||
{
|
||||
pGame->GetStateManager()->SelectState(AS_STRING("settings_menu"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool StateGame::MouseMove( int absX, int relX, int absY, int relY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateGame::MousePressed(int buttonId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateGame::MouseReleased(int buttonId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StateGame::Render()
|
||||
{
|
||||
//
|
||||
//
|
||||
pGame->GetGraphics()->GetSceneManager()->GetActiveScene()->Render();
|
||||
|
||||
//render physics debug info
|
||||
pGame->DrawDebug();
|
||||
|
||||
//pGame->GetGraphics()->GetGUI()->Render();
|
||||
}
|
||||
void StateGame::ProcessCmd(const String& cmd, void* params)
|
||||
{
|
||||
}
|
||||
void StateGame::OnEnter()
|
||||
{
|
||||
}
|
||||
void StateGame::OnLeave()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "states/StateSettings.h"
|
||||
#include "MyGame.h"
|
||||
|
||||
StateSettings::StateSettings(const String& name, MyGame* engine) : IGameState(name)
|
||||
{
|
||||
pGame = engine;
|
||||
|
||||
pGame->GetGraphics()->GetGUI()->AddOverlay(AS_STRING("settings_menu"));
|
||||
pMenu = pGame->GetGraphics()->GetGUI()->GetOverlay(AS_STRING("settings_menu"));
|
||||
pMenu->drawBackground = true;
|
||||
|
||||
/*GUIButton* button2 = new GUIButton(pGame->GetGraphics()->GetGUI());
|
||||
button2->SetPosition(Vec2i(50,110));
|
||||
button2->SetWidth(200);
|
||||
button2->SetHeight(50);
|
||||
button2->SetBackColor(Vec4f(0.0f,1.0f,0.0f,0.99f));
|
||||
pMenu->AddChild(button2);*/
|
||||
|
||||
GUIComboBox* res = new GUIComboBox(pGame->GetGraphics()->GetGUI());
|
||||
res->SetPosition(Vec2i(100,10));
|
||||
pMenu->AddChild(res);
|
||||
|
||||
/* GUIPlane* plane = new GUIPlane(pGame->GetGraphics()->GetGUI());
|
||||
plane->SetBorderEnabled(true);
|
||||
plane->SetWidth(300);
|
||||
pMenu->AddChild(plane);*/
|
||||
}
|
||||
void StateSettings::Update()
|
||||
{
|
||||
pGame->GetGraphics()->GetGUI()->Update(pGame->GetGraphics()->GetTimeElapsed());
|
||||
}
|
||||
void StateSettings::Render()
|
||||
{
|
||||
pGame->GetGraphics()->GetGUI()->Render();
|
||||
}
|
||||
void StateSettings::OnEnter()
|
||||
{
|
||||
pGame->GetGraphics()->GetGUI()->SelectOverlay(AS_STRING("settings_menu"));
|
||||
}
|
||||
void StateSettings::OnLeave()
|
||||
{
|
||||
}
|
||||
void StateSettings::ProcessCmd(const String& cmd, void* params)
|
||||
{
|
||||
}
|
||||
|
||||
bool StateSettings::KeyDown( Key key, unsigned int text, const std::string& str )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateSettings::KeyUp( Key key, unsigned int text, const std::string& str )
|
||||
{
|
||||
if(key == KEY_M)
|
||||
{
|
||||
pGame->GetStateManager()->SelectState(AS_STRING("gameplay"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool StateSettings::MouseMove( int absX, int relX, int absY, int relY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateSettings::MousePressed(int buttonId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool StateSettings::MouseReleased(int buttonId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user