Esempio n. 1
0
void GameEngine::GameLoop()
{
    // Set framerate cap
    GLdouble framerate = 999.0;
    GLdouble lastFrameTime = 0, currentFrameTime = 0, fpsLastUpdate = 0;
    gameRunning = true;

    // Main-loop
    while(gameRunning)
    {
        currentFrameTime = glfwGetTime();
        if ((currentFrameTime - lastFrameTime) * 1000.0 < 1000.0 / framerate)
        {
            Sleep(0.0001);
        }
        else
        {
            // Check if a state has been queued
            if (StateManager::GetInstance()->StateHasBeenQueued())
            {
                StateManager *sM = StateManager::GetInstance();
                ResourceManager * rM = ResourceManager::GetInstance();

                // Change state
                rM->UnloadAll();
                sM->ChangeState(sM->GetQueuedState());
                rM->StartLoading();
            }

            // Handle input
            HandleInput();

            // Update
            Update((currentFrameTime - lastFrameTime) * 1000.0);

            // Draw
            Draw();

            // update fps-counter
            GLdouble time = currentFrameTime;
            if (time - fpsLastUpdate >= 1.0)
            {
                GLdouble fps = ((currentFrameTime - lastFrameTime) * 1000.0);
                glfwSetWindowTitle(Context::getWindow(), toString((int)((1000.0 / fps) * 100.0) / 100.0).c_str());
                fpsLastUpdate = time;
            }

            lastFrameTime = currentFrameTime;
        }
    }

    // Cleanup game if loop stops
    Cleanup();
}
Esempio n. 2
0
int main()
{
	SetupCallbacks();

	scePowerSetClockFrequency(333, 333, 166);

	//initialize render manager
	RenderManager::InstancePtr()->Init();
	RenderManager::InstancePtr()->CollectPerformance(true);
	RenderManager::InstancePtr()->InitDebugFont();

	//set perspectives
	RenderManager::InstancePtr()->SetOrtho(0,0,0,0,0,0);
	
	//init and load sounds
	SoundManager::Instance()->Init();

	srand(time(NULL));

	//new state manager
	StateManager stateManager;
	stateManager.Init();

	RenderManager::InstancePtr()->SetClearColour(0xFF000000);

	//splash screens
	SplashScreen *screen = new SplashScreen(TextureHelper::Instance()->GetTexture(TextureHelper::Genesis),0,0,480,272,3);
	screen->ShowSplash();
	delete screen;
	SplashScreen *screen2 = new SplashScreen(TextureHelper::Instance()->GetTexture(TextureHelper::PspTeam),0,0,424,72,3);
	screen2->ShowSplash();
	delete screen2;

	RenderManager::InstancePtr()->SetClearColour(0xFFF5B783);

	//new active state
	StateMenu *statePlay = new StateMenu();
	statePlay->Init();
	stateManager.ChangeState(statePlay);

	//trun
	while ( stateManager.Running() )
	{
		stateManager.HandleEvents();
		stateManager.Update();
		stateManager.Draw();
	}

	sceGuTerm();			// Terminating the Graphics System
	sceKernelExitGame();	// Quits Application

	return 0;
}
Esempio n. 3
0
S3E_MAIN_DECL void IwMain()
{
    strcpy(EVENT_APPLE_DROP, "AppleDrop");
    strcpy(EVENT_NEW_DUMPTRUCK, "NewDumptruck");
    srand(time(null));

    wordBuilder = new WordBuilder;

    GameManager *mgr;
    mgr = new GameManager();

    mgr->SetRequestedFPS(100);

    mgr->GetResourceManager()->RegisterResourceGroup("images.group");

    IMAGE_MAIN_MENU = mgr->GetResourceManager()->RegisterImage("MainMenu");
    IMAGE_CHANGE_PLAYER_BUTTON = mgr->GetResourceManager()->RegisterImage("ChangePlayerButton");
    IMAGE_START_GAME_BUTTON = mgr->GetResourceManager()->RegisterImage("StartGameButton");
    IMAGE_LEVEL_SELECT = mgr->GetResourceManager()->RegisterImage("LevelSelectionScreen");
    IMAGE_PLAY_BUGS_BUTTON = mgr->GetResourceManager()->RegisterImage("BogsIcon");
    IMAGE_PLAY_APPLES_BUTTON = mgr->GetResourceManager()->RegisterImage("ApplesIcon");
    IMAGE_PLAY_SANDBOX_BUTTON = mgr->GetResourceManager()->RegisterImage("SandboxIcon");
    IMAGE_PLAY_WALL_BUTTON = mgr->GetResourceManager()->RegisterImage("WallIcon");
    IMAGE_MAIN_MENU_BUTTON = mgr->GetResourceManager()->RegisterImage("MainMenuButton");

    IMAGE_LADYBUG = mgr->GetResourceManager()->RegisterImage("ladybug");
    IMAGE_SPLAT = mgr->GetResourceManager()->RegisterImage("splat");
    IMAGE_BUGS_BACKGROUND = mgr->GetResourceManager()->RegisterImage("bugs_background");

    IMAGE_APPLES_BACKGROUND = mgr->GetResourceManager()->RegisterImage("apples_background");
    IMAGE_APPLE = mgr->GetResourceManager()->RegisterImage("apple");

    IMAGE_SANDBOX_BACKGROUND = mgr->GetResourceManager()->RegisterImage("sandbox_background");
    IMAGE_SANDCASTLE = mgr->GetResourceManager()->RegisterImage("sandcastle");
    IMAGE_DUMPTRUCK_FULL = mgr->GetResourceManager()->RegisterImage("dumptruck_full");
    IMAGE_DUMPTRUCK_EMPTY = mgr->GetResourceManager()->RegisterImage("dumptruck_empty");

    IMAGE_WALL_BACKGROUND = mgr->GetResourceManager()->RegisterImage("wall_background");
    IMAGE_BRICK1 = mgr->GetResourceManager()->RegisterImage("brick1");
    IMAGE_BRICK2 = mgr->GetResourceManager()->RegisterImage("brick2");
    IMAGE_BRICK3 = mgr->GetResourceManager()->RegisterImage("brick3");
    IMAGE_BRICK_TARGET = mgr->GetResourceManager()->RegisterImage("brick_target");

    IMAGE_STAR_0 = mgr->GetResourceManager()->RegisterImage("star_0");
    IMAGE_STAR_1 = mgr->GetResourceManager()->RegisterImage("star_1");
    IMAGE_STAR_2 = mgr->GetResourceManager()->RegisterImage("star_2");
    IMAGE_STAR_3 = mgr->GetResourceManager()->RegisterImage("star_3");
    IMAGE_STAR_4 = mgr->GetResourceManager()->RegisterImage("star_4");
    IMAGE_STAR_5 = mgr->GetResourceManager()->RegisterImage("star_5");

    FONT_TREB_16 = mgr->GetResourceManager()->RegisterFont("trebuchet16pt");
    FONT_TREB_24 = mgr->GetResourceManager()->RegisterFont("trebuchet24pt");
    FONT_TREB_36 = mgr->GetResourceManager()->RegisterFont("trebuchet36pt");

    FONT_COOPER_18 = mgr->GetResourceManager()->RegisterFont("cooper_18pt");
    FONT_COOPER_24 = mgr->GetResourceManager()->RegisterFont("cooper_24pt");
    FONT_COOPER_48 = mgr->GetResourceManager()->RegisterFont("cooper_48pt");

    SOUND_DING = mgr->GetResourceManager()->RegisterAudio("DING.wav");
    SOUND_BUZZ = mgr->GetResourceManager()->RegisterAudio("BUZZ.wav");

    GameManager::SetDebugFont(mgr->GetResourceManager()->GetFont(FONT_TREB_16));

    StateManager *state = mgr->GetStateManager();

    STATE_STARTUP = state->RegisterGameState("Startup");
    STATE_MAIN_MENU = state->RegisterGameState("MainMenu");
    STATE_LEVEL_SELECT = state->RegisterGameState("LevelSelect");

    STATE_BUGS_PLAYING = state->RegisterGameState("BugsPlaying");
    STATE_BUGS_SUMMARY = state->RegisterGameState("BugsSummary");

    STATE_APPLES_PLAYING = state->RegisterGameState("ApplesPlaying");
    STATE_APPLES_SUMMARY = state->RegisterGameState("ApplesSummary");

    STATE_SANDBOX_PLAYING = state->RegisterGameState("SandboxPlaying");
    STATE_SANDBOX_SUMMARY = state->RegisterGameState("SandboxSummary");

    STATE_WALL_PLAYING = state->RegisterGameState("WallPlaying");
    STATE_WALL_SUMMARY = state->RegisterGameState("WallSummary");

    state->DefineValidStateTransition(STATE_STARTUP, STATE_MAIN_MENU);
    state->DefineValidStateTransition(STATE_MAIN_MENU, STATE_LEVEL_SELECT);
    state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_MAIN_MENU);

    state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_BUGS_PLAYING);
    state->DefineValidStateTransition(STATE_BUGS_PLAYING, STATE_BUGS_SUMMARY);
    state->DefineValidStateTransition(STATE_BUGS_SUMMARY, STATE_LEVEL_SELECT);

    state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_APPLES_PLAYING);
    state->DefineValidStateTransition(STATE_APPLES_PLAYING, STATE_APPLES_SUMMARY);
    state->DefineValidStateTransition(STATE_APPLES_SUMMARY, STATE_LEVEL_SELECT);

    state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_SANDBOX_PLAYING);
    state->DefineValidStateTransition(STATE_SANDBOX_PLAYING, STATE_SANDBOX_SUMMARY);
    state->DefineValidStateTransition(STATE_SANDBOX_SUMMARY, STATE_LEVEL_SELECT);

    state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_WALL_PLAYING);
    state->DefineValidStateTransition(STATE_WALL_PLAYING, STATE_WALL_SUMMARY);
    state->DefineValidStateTransition(STATE_WALL_SUMMARY, STATE_LEVEL_SELECT);

    state->SetInitialState(STATE_STARTUP);

    StateVariable initialValue;

    initialValue.intValue = 0;
    VAR_POINTS = state->RegisterVariable("GamePoints", initialValue);
    VAR_CURRENT_THINGY_COUNT = state->RegisterVariable("CurrentBugCount", initialValue);
    VAR_CURRENT_CORRECT_THINGY_COUNT = state->RegisterVariable("CorrectBugCount", initialValue);

    initialValue.stringValue = null;
    VAR_CURRENT_PHONEME = state->RegisterVariable("CurrentPhoneme", initialValue);

    // These objects do not register, so we have to delete them ourselves
    MainMenu *mainMenu = new MainMenu(mgr);
    LevelSelection *levelSelect = new LevelSelection(mgr);
    BugsLevel *bugsLevel = new BugsLevel(mgr);
    ApplesLevel *applesLevel = new ApplesLevel(mgr);
    SandboxLevel *sandboxLevel = new SandboxLevel(mgr);
    WallLevel *wallLevel = new WallLevel(mgr);

    levelSummary = new LevelSummary(mgr);

    state->ChangeState(STATE_MAIN_MENU);

    mgr->MainLoop();

    delete levelSummary;
    delete wallLevel;
    delete sandboxLevel;
    delete applesLevel;
    delete bugsLevel;
    delete levelSelect;
    delete mainMenu;

    delete mgr;
    delete wordBuilder;
}