• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Adam West

game state management not working?

5 posts in this topic

hey there again,

I am trying to create a game state manager using an input manager where a gui will appear when the user presses escape in game, for some reason its not working :(, any ideas??
main.h
[CODE]
#ifndef MAIN_H_
#define MAIN_H_
#include <irrlicht.h>
#include <iostream>
#include <string.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


//globals
class redNovember
{
public:
// always initialize class-members in the constructor - especially set pointers to 0!
redNovember() : device(0), driver(0), smgr(0),guienv(0)
{}

IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ICameraSceneNode * camera;
IMetaTriangleSelector * meta;
IGPUProgrammingServices* gpu;
scene::IParticleSystemSceneNode* ps;
gui::IGUIInOutFader* fader;

void initIrrlicht();
void initFPSCamera();
void renderScene();
int shutdown();
void inputHandle();
//for the game scenes
void LoadScene(); // const chars for maps
void initSkybox(const char* up,const char* down,const char* left, const char* right, const char* front, const char* back);
void initSkydome(const char* skydomefile);
//shader stuff
void initShader();
void VertexShader(const char* VertexShaderFilename, const char* VertexShaderFunction);
void PixelShader(const char* PixelShaderFilename, const char* PixelShaderFunction);
void GeoShader(const char* GeoShaderFilename, const char* GeoShaderFunction);
void initRain();
void initFog();
void initBloom();
void initHDR();
void initSSAO();
void initBokehDOF();
//user interface and effects
bool showGameMenu;
void fadeInTransition();
void fadeOutTransition();
void showInGameMenu();
void hideInGameMenu();
//material and shader ID's

s32 bloomMaterial;
s32 bokehDOFMaterial;
//s32 CgExampleMaterialType;
//for shaders

// You can put any other variables you want in here.
// For example driver, scenemanger although you can also always get them from device
// Note that the clean solution is making variables private and use public
// get-functions to access them from other classes as you can see when looking at Irrlicht classes.
// You can for example also create a function like that:
//irr::scene::ISceneManager* getSceneManager() const { return device ? device->getSceneManager() : 0; }

};


// every other global you would need can instead of being global just be put in here.
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
#endif
[/CODE]
main.cpp
[CODE]
#include "main.h"
#include "luamanager.h"
#include "physicsmanager.h"
LuaManager * LUA = new LuaManager;
//newtonManager* PHYS = new newtonManager;
redNovember* SYS = new redNovember;
MyEventReceiver receiver;

int redNovember::shutdown()
{
LUA->DropLua();
delete LUA;
//PHYS->drop();
device->drop();

//delete PHYS;
delete SYS;
return 0;
}
int main()
{
SYS->initIrrlicht();

//PHYS->init();
SYS->LoadScene();
SYS->initShader();

SYS->initFPSCamera();



//SYS->initRain();
SYS->initFog();

LUA->loadScript("assets/scripts/test.lua");

///put main shit in here
//put gui loop here

SYS->initSkydome("assets/skydome/storm1.jpg");

/*
SYS->initSkybox("assets/skybox/citystorm/up.jpg",
"assets/skybox/citystorm/down.jpg",
"assets/skybox/citystorm/left.jpg",
"assets/skybox/citystorm/right.jpg",
"assets/skybox/citystorm/back.jpg",
"assets/skybox/citystorm/front.jpg");*/


SYS->renderScene();

SYS->shutdown();
}
void redNovember::initIrrlicht()
{
device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32,
false, false, true, 0);
device->setWindowCaption(L"Project: Red November");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
device->getCursorControl()->setVisible(false); //hide cursor
fader = device->getGUIEnvironment()->addInOutFader();
// Then create the event receiver, giving it that context structure.
// And tell the device to use our custom event receiver.


}

void redNovember::renderScene()
{
int lastFPS = -1;
while(device->run())
{

inputHandle(); //input handler

if(!device->isWindowActive())
{
//add pause functions here

}
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,200,200,200));

smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"[";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
}
void redNovember::inputHandle()
{
//menu key handler
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = true;


//menu shit
if (showGameMenu = true)
{
SYS->showInGameMenu();
}
else
SYS->hideInGameMenu();

};
[/CODE]
gui.cpp
[CODE]
#include "main.h"

void redNovember::fadeInTransition()
{
fader->setColor(video::SColor(0,0,0,0));
fader->fadeOut(4000);
}
void redNovember::fadeOutTransition()
{
fader->setColor(video::SColor(0,0,0,0));
fader->fadeIn(4000);
}
void redNovember::showInGameMenu()
{
std::cout << "on" << std::endl;
}
void redNovember::hideInGameMenu()
{
std::cout << "off" << std::endl;
}
[/CODE]


at the moment it should spam off on the output window and then spam on when the escape key is pressed... the output only spams on though
0

Share this post


Link to post
Share on other sites
Define "its not working". Compiler error? Runtime crash? Unexpected behaviour? Gremlins escape from your computer?

In redNovember::inputHandle(), you are using an assignment in a conditional expression:
[code]
if (showGameMenu = true)
{
SYS->showInGameMenu();
}
else
SYS->hideInGameMenu();
[/code]
The first line sets showGameMenu to true, then tests if it is true (which it must be), and then executes shwoInGameMenu(). This is assuming you have no memory related errors, such as calling inputHandle() on an invalid object or uninitialised pointer.

Consider increasing your warning level until the compiler outputs a message about this. Also in future, try to fully describe the problematic behaviour. If you are getting errors or warnings, post them. If you are getting strange behaviour, post both what you expect to happen and what actually happened. Should gremlins emerge from your computer, give an estimate as to how many, what size they were and what colour.
2

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1338808974' post='4946073']
Define "its not working". Compiler error? Runtime crash? Unexpected behaviour? Gremlins escape from your computer?
[/quote]

if you read the code and the statement, the problem is it only spams the function which causes it to show, it should be off then on when escape is pressed.
0

Share this post


Link to post
Share on other sites
[quote]
if you read the code and the statement...
[/quote]
There is a lot of code, and I am not familiar with Irrlicht. I don't have a large amount of time, so I skimmed the code.

[quote]
... the problem is it only spams the function which causes it to show, it should be off then on when escape is pressed.
[/quote]
Sorry, I did miss the final sentence in your original post. Still, I cannot parse that sentence. I don't know what "to spam" a function means.

Are you trying to say that the escape key is supposed to toggle the menu? Presumably, if you are saying that then the actual behaviour is different. This is what I want to see - a clear description of what the problem is.

As I mentioned, the code as you posted will always show the menu, because you unconditionally assign showGameMenu to "true". As Matthew Wood states, you can fix it by using the double equals comparison operator. Alternatively, you can just write:
[code]
if(showGameMenu) {
// Show the menu
} else {
// Hide the menu
}
[/code] Edited by rip-off
1

Share this post


Link to post
Share on other sites
Thanks guys, both answers are super helpful.
[img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0