Beispiel #1
0
void OEMFMain :: run(void)
{
	unsigned int menuIndex = 0;
	unsigned int frames = 0;
	unsigned int timepassed;
	
	if (musicPlayer->isPlayingSong())
		musicPlayer->stopSong();
	string songfile = PREPATH "boiling.mp3";
	musicPlayer->playSongAtPath(songfile.c_str());
	
	drawIntro();
	
	SDL_Event event;
	int done = 0;
	while ( !done) {
		timepassed = SDL_GetTicks();
	
		OEMF_LOCKSCREEN;
		clearWithColor(0xFF000000, false);
		OEMF_UNLOCKSCREEN;
		blitImage(images[IMG_INTRO], 0, 0);
		for (unsigned int i = 0; i < m_menuCount; i++)
			fonts[FNT_MENU]->blitText(this, m_menuOptions[i].c_str(), 160, 240 + i * 32, 480, false);
		blitImage(images[IMG_OEMFOE], 128, (unsigned int) (240 + menuIndex * 32 + sin(frames / 2.0) * 8));
		SDL_UpdateRect(m_screen, 128, 232, 512, 248);
		
		/* Check for events */
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONDOWN:
					break;
				case SDL_KEYDOWN:
					if (event.key.keysym.sym == SDLK_ESCAPE)
					{	
						done = 1;
					} 
					else if (event.key.keysym.sym == SDLK_UP)
					{
						menuIndex = (menuIndex - 1 + m_menuCount) % m_menuCount;
						musicPlayer->playSound(sounds[SND_TOK]);
					}
					else if (event.key.keysym.sym == SDLK_DOWN)
					{
						menuIndex = (menuIndex + 1) % m_menuCount;
						musicPlayer->playSound(sounds[SND_TOK]);
					}
					else if (event.key.keysym.sym == SDLK_p)
					{
						SDL_SaveBMP(m_screen, "screenshot.bmp");
					}
					else if (event.key.keysym.sym == SDLK_RETURN)
					{
						musicPlayer->playSound(sounds[SND_TIK]);
						if (menuIndex == 4)
						{
							fadeOut();
							done = 1;
						}
						else if (menuIndex == 0) // new game
						{
							fadeOut();
							OEMFGame * game = new OEMFGame(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
							game->run();
							delete game;
							drawIntro();
						}
						else if (menuIndex == 3) // level editor
						{
							fadeOut();
							OEMFLevelEdit * leveledit = new OEMFLevelEdit(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
							leveledit->run();
							delete leveledit;
							drawIntro();
						}
						else if (menuIndex == 2) // options
						{
							unsigned int choice = 0;
							string * options = new string[2];
							while (choice != 2) // not exit
							{
								if (musicEnabled)
									options[0] = "Turn Music Off";
								else
									options[0] = "Turn Music On";
								options[1] = "Toggle Fullscreen";
								drawIntro();
								choice = chooseList(2 /* exit */, "Options", options, 2);
								if (choice == 0)
								{
									musicEnabled = !musicEnabled;
									if (!musicEnabled)
									{
										if (musicPlayer->isPlayingSong())
											musicPlayer->stopSong();
									}
									else
									{
										musicPlayer->playSongAtPath(songfile.c_str());
									}
								}
								else if (choice == 1)
								{
									if (fullscreenMode)
									{
										m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE);
										m_fb = (Uint32 *) m_screen->pixels;
										m_pitch = (Uint32) m_screen->pitch / 4;
										fullscreenMode = false;
									}
									else
									{
										m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE | SDL_FULLSCREEN);
										m_fb = (Uint32 *) m_screen->pixels;
										m_pitch = (Uint32) m_screen->pitch / 4;
										fullscreenMode = true;
									}
									choice = 2;
								}
							}
							drawIntro();
						}
						else
						{
							fadeOut();
							fonts[FNT_MENU]->blitCenterText(this, "NOT AVAILABLE YET", 240, m_screenWidth);
							SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
							SDL_Delay(2000);
							string test = fonts[FNT_MENU]->inputText(this, "default", 32, 32, 10);
							drawIntro();
						}
					}
					break;
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
		}
		frames++;
		
		// 30 FPS
		timepassed = SDL_GetTicks() - timepassed;
		if (timepassed <= 33)
			SDL_Delay(33 - timepassed);
	}
}
Beispiel #2
0
int main(int argc, char **argv)
{
	char nom_du_fichier[300] = "No_File_Loaded";
	if (argc > 1)
	{
		strcpy_s(nom_du_fichier, argv[1]);
	}
	char temp[20] = "";
	SDL_Window *window = nullptr;
	SDL_Renderer *render = nullptr;
	Input INPUT; inputInit(&INPUT);
	SDL_Color WHITE = { 255, 255 , 255 };
	int volume = 70;
	initVid(&window, &render, w_window, h_window);
	SDL_SetWindowTitle(window, "ColdJuke");

	TTF_Init();
	Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024);

	Mix_Music *music = nullptr;
	music = Mix_LoadMUS(nom_du_fichier);
	Mix_PlayMusic(music, -1);
	Mix_VolumeMusic(static_cast<double>(128 / 100)*volume);
	clearWithColor(render, 80, 40, 100, 255);
	SDL_Texture *gui = imgToTex((baseProgramPath + "gui.png").c_str(), render);
	
	sprintf_s(temp, "%d%%", volume);
	SDL_Texture *tex_volume = txtToTex(temp, render, WHITE, 14);
	SDL_Texture *texte = txtToTex(nom_du_fichier, render, WHITE, 14);
	afficherGui(gui, texte, tex_volume, render);

	SDL_RenderPresent(render);
	int FPS(60), TICKS(1000 / FPS);
	long start(SDL_GetTicks()), actual(SDL_GetTicks());
	INPUT.filedrop = "";
	while (!INPUT.quit && !INPUT.key[SDL_SCANCODE_ESCAPE] && !(INPUT.leftclic && INPUT.leftclic_position_x > w_window-32 && INPUT.leftclic_position_y < 32))
	{
		inputReturn(&INPUT);

		actual = SDL_GetTicks();
		if (actual - start > TICKS)
		{
			if (INPUT.key[SDL_SCANCODE_SPACE] || (INPUT.leftclic && INPUT.leftclic_position_x < 64 && INPUT.leftclic_position_y > 64)) // Pause Play
			{
				if (Mix_PausedMusic())
				{
					Mix_ResumeMusic();
					texToRenderPart(gui, render, 100, 0, 64, 64, 64, 32, 0, 64, 64);
					SDL_RenderPresent(render);

				}
				else
				{
					Mix_PauseMusic();
					texToRenderPart(gui, render, 100, 0, 64, 64, 64, 32, 64, 64, 64);
					SDL_RenderPresent(render);

				}
				SDL_Delay(250);
			}
			if (INPUT.wheelup)
			{
				volume += 2;
				if (volume > 100)
					volume = 100;
				Mix_VolumeMusic(static_cast<double>(128 / 100)*volume);
				// Volume 
				texToRenderPart(gui, render, 100, w_window - 64, 64, 64, 64, 96, 0, 64, 64);
				sprintf_s(temp, "%d%%", volume);
				SDL_DestroyTexture(tex_volume);
				tex_volume = txtToTex(temp, render, WHITE, 14);
				// Volume Number
				texToRender(tex_volume, render, 100, w_window - 40, 85);
				SDL_RenderPresent(render);


			}
			if (INPUT.wheeldown)
			{
				volume -= 2;
				if (volume < 0)
					volume = 0;
				Mix_VolumeMusic(static_cast<double>(128 / 100)*volume);
				// Volume 
				texToRenderPart(gui, render, 100, w_window - 64, 64, 64, 64, 96, 0, 64, 64);
				sprintf_s(temp, "%d%%", volume);
				SDL_DestroyTexture(tex_volume);
				tex_volume = txtToTex(temp, render, WHITE, 14);
				// Volume Number
				texToRender(tex_volume, render, 100, w_window - 40, 85);
				SDL_RenderPresent(render);

			}
			if (INPUT.rightclic)
			{
				int x_mouse_screen; int y_mouse_screen;
				SDL_GetGlobalMouseState(&x_mouse_screen,&y_mouse_screen);
				SDL_SetWindowPosition(window, x_mouse_screen-INPUT.rightclic_position_x, y_mouse_screen-INPUT.rightclic_position_y);
				inputReturn(&INPUT);
			}
			if (INPUT.filedrop != "")
			{
				Mix_PauseMusic();
				music = Mix_LoadMUS(INPUT.filedrop);
				strcpy_s(nom_du_fichier, INPUT.filedrop);
				Mix_PlayMusic(music, -1);
				sprintf_s(temp, "%d%%", volume);
				SDL_DestroyTexture(texte);
				texte = txtToTex(nom_du_fichier, render, WHITE, 14);
				afficherGui(gui, texte, tex_volume, render);
				SDL_RenderPresent(render);

			}
			start = actual;
			INPUT.filedrop = "";
			INPUT.wheeldown = 0;
			INPUT.wheelup = 0;
		}
		else
		{
			SDL_Delay(TICKS - (actual - start));
		}
	}

	Mix_CloseAudio();
	TTF_Quit();
	SDL_Quit();
	return 0;
}
Beispiel #3
0
void OEMFMain :: drawIntro(void)
{
	clearWithColor(0xFF000000, false);
	blitImage(images[IMG_INTRO], 0, 0);
	SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
}