Beispiel #1
0
int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
	if ((game->menu.menustate==MENUSTATE_OPTIONS) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) {
		al_play_sample_instance(game->menu.click);
		ChangeMenuState(game,MENUSTATE_PAUSE);
	} else if ((game->menu.menustate==MENUSTATE_VIDEO) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) {
		al_play_sample_instance(game->menu.click);
		ChangeMenuState(game,MENUSTATE_OPTIONS);
		if (game->menu.options.fullscreen!=game->fullscreen) {
			al_toggle_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, game->menu.options.fullscreen);
			al_clear_to_color(al_map_rgb(0,0,0));
			al_flip_display();
			game->fullscreen = game->menu.options.fullscreen;
			if (game->fullscreen) al_hide_mouse_cursor(game->display);
			else al_show_mouse_cursor(game->display);
			Shared_Unload(game);
			al_clear_to_color(al_map_rgb(0,0,0));
			al_flip_display();
			SetupViewport(game);
			Shared_Load(game);

#ifndef __clang__
			void Progress(struct Game *game, float p) {
				al_set_target_bitmap(al_get_backbuffer(game->display));
				al_clear_to_color(al_map_rgb(0,0,0));
				al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), game->viewportWidth*0.0234, game->viewportHeight*0.84, ALLEGRO_ALIGN_LEFT, "Loading...");
				al_draw_filled_rectangle(0, game->viewportHeight*0.985, game->viewportWidth, game->viewportHeight, al_map_rgba(128,128,128,128));
				al_draw_filled_rectangle(0, game->viewportHeight*0.985, p*game->viewportWidth, game->viewportHeight, al_map_rgba(255,255,255,255));
				al_flip_display();
			}
//-------------------- CheckMenuItemAppropriately ----------------------------
//
//  if b is true MenuItem is checked, otherwise it is unchecked
//-----------------------------------------------------------------------------
void CheckMenuItemAppropriately(HWND hwnd, UINT MenuItem, bool b)
{
  if (b)
  {
    ChangeMenuState(hwnd, MenuItem, MFS_CHECKED);
  }
  else
  {
    ChangeMenuState(hwnd, MenuItem, MFS_UNCHECKED);
  }
}
Beispiel #3
0
void Pause_Load(struct Game* game) {
	ALLEGRO_BITMAP *fade = al_create_bitmap(game->viewportWidth, game->viewportHeight);
	al_set_target_bitmap(fade);
	al_clear_to_color(al_map_rgb(0,0,0));
	al_set_target_bitmap(al_get_backbuffer(game->display));
	//game->pause.bitmap = fade;
	ChangeMenuState(game,MENUSTATE_PAUSE);
	PrintConsole(game,"Game paused.");
	al_play_sample_instance(game->menu.click);
}
Beispiel #4
0
void Menu_Load(struct Game *game) {
	if (!game->menu.loaded) return;

	game->menu.cloud_position = 100;
	game->menu.cloud2_position = 100;
	ChangeMenuState(game,MENUSTATE_MAIN);

	al_play_sample_instance(game->menu.music);
	al_play_sample_instance(game->menu.rain_sound);
	FadeGameState(game, true);
}
Beispiel #5
0
void Gamestate_Start(struct Game *game, struct MenuResources* data) {

	data->title_pos = 0;
	data->screen_pos = 180;
	data->invisible = true;
	data->monster_pos = -202;
	data->starting = false;

	ChangeMenuState(game,data,MENUSTATE_HIDDEN);
	al_play_sample_instance(data->music);

}
Beispiel #6
0
void UpdateMenu()
{
	if (startbutton())
	{
		ChangeMenuState();
		delay(mMenuDelay);
	}
	RefreshCurSelection();

	UpdateDisplay();

	delay(mUpdateDelay);
}
Beispiel #7
0
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {

	if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
		game->menu.selected--;
		if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected--;
		al_play_sample_instance(game->menu.click);
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
		game->menu.selected++;
		if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected++;
		al_play_sample_instance(game->menu.click);
	}

	if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) {
		char *text;
		al_play_sample_instance(game->menu.click);
		switch (game->menu.menustate) {
			case MENUSTATE_MAIN:
				switch (game->menu.selected) {
					case 0:
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_DISCLAIMER;
						break;
					case 1:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					case 2:
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_ABOUT;
						break;
					case 3:
						return 1;
						break;
				}
				break;
			case MENUSTATE_AUDIO:
				text = malloc(255*sizeof(char));
				switch (game->menu.selected) {
					case 0:
						game->music--;
						if (game->music<0) game->music=10;
						sprintf(text, "%d", game->music);
						SetConfigOption("SuperDerpy", "music", text);
						al_set_mixer_gain(game->audio.music, game->music/10.0);
						break;
					case 1:
						game->fx--;
						if (game->fx<0) game->fx=10;
						sprintf(text, "%d", game->fx);
						SetConfigOption("SuperDerpy", "fx", text);
						al_set_mixer_gain(game->audio.fx, game->fx/10.0);
						break;
					case 2:
						game->voice--;
						if (game->voice<0) game->voice=10;
						sprintf(text, "%d", game->voice);
						SetConfigOption("SuperDerpy", "voice", text);
						al_set_mixer_gain(game->audio.voice, game->voice/10.0);
						break;
					case 3:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
				}
				free(text);
				break;
			case MENUSTATE_OPTIONS:
				switch (game->menu.selected) {
					case 0:
						ChangeMenuState(game,MENUSTATE_CONTROLS);
						break;
					case 1:
						ChangeMenuState(game,MENUSTATE_VIDEO);
						break;
					case 2:
						ChangeMenuState(game,MENUSTATE_AUDIO);
						break;
					case 3:
						ChangeMenuState(game,MENUSTATE_MAIN);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_PAUSE:
				switch (game->menu.selected){
					case 0:
						PrintConsole(game,"Game resumed.");
						al_destroy_bitmap(game->pause.bitmap);
						game->pause.bitmap = NULL;
						ResumeGameState(game);
						game->gamestate = game->loadstate;
						break;
					case 1:
						game->gamestate=game->loadstate;
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_MAP;
						break;
					case 2:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					case 3:
						return 1;
					default:
						break;
				}
				break;
			case MENUSTATE_CONTROLS:
				switch (game->menu.selected) {
					case 3:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_VIDEO:
				switch (game->menu.selected) {
					case 0:
						game->menu.options.fullscreen = !game->menu.options.fullscreen;
						if (game->menu.options.fullscreen)
							SetConfigOption("SuperDerpy", "fullscreen", "1");
						else
							SetConfigOption("SuperDerpy", "fullscreen", "0");
						break;
					case 3:
						if ((game->menu.options.fullscreen==game->fullscreen) && (game->menu.options.fps==game->fps) && (game->menu.options.width==game->width) && (game->menu.options.height==game->height)) {
							ChangeMenuState(game,MENUSTATE_OPTIONS);
						} else {
							PrintConsole(game, "video settings changed, restarting...");
							game->restart = true;
							return 1;
						}
						break;
					default:
						break;
				}
				break;
			default:
				return 1;
				break;
		}
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) {
		switch (game->menu.menustate) {
			case MENUSTATE_OPTIONS:
				ChangeMenuState(game,MENUSTATE_MAIN);
				break;
			case MENUSTATE_VIDEO:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_AUDIO:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_CONTROLS:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_PAUSE:
				PrintConsole(game,"Game resumed.");
				al_destroy_bitmap(game->pause.bitmap);
				game->pause.bitmap = NULL;
				ResumeGameState(game);
				game->gamestate = game->loadstate;
				break;
			default:
				return 1;
				break;
		}
	}

	if (game->menu.selected==-1) game->menu.selected=3;
	if (game->menu.selected==4) game->menu.selected=0;
	return 0;
}
Beispiel #8
0
LRESULT CALLBACK WindowProc (HWND   hwnd,
							 UINT   msg,
							 WPARAM wParam,
							 LPARAM lParam)
{
	//these hold the dimensions of the client window area
	static int cxClient, cyClient; 

	//used to create the back buffer
	static HDC		hdcBackBuffer;
	static HBITMAP	hBitmap;
	static HBITMAP	hOldBitmap;

	switch (msg)
	{

		//A WM_CREATE msg is sent when your application window is first
		//created
	case WM_CREATE:
		{
			//to get get the size of the client window first we need  to create
			//a RECT and then ask Windows to fill in our RECT structure with
			//the client window size. Then we assign to cxClient and cyClient 
			//accordingly
			RECT rect;

			GetClientRect(hwnd, &rect);

			cxClient = rect.right;
			cyClient = rect.bottom;

			//seed random number generator
			srand((unsigned) time(NULL));  


			//---------------create a surface to render to(backbuffer)

			//create a memory device context
			hdcBackBuffer = CreateCompatibleDC(NULL);

			//get the DC for the front buffer
			HDC hdc = GetDC(hwnd);

			hBitmap = CreateCompatibleBitmap(hdc,
				cxClient,
				cyClient);


			//select the bitmap into the memory device context
			hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap);

			//don't forget to release the DC
			ReleaseDC(hwnd, hdc); 

			g_GameWorld = new GameWorld(cxClient, cyClient);

			ChangeMenuState(hwnd, IDR_PRIORITIZED, MFS_CHECKED);
			ChangeMenuState(hwnd, ID_VIEW_FPS, MFS_CHECKED);

		}

		break;

	case WM_COMMAND:
		{
			g_GameWorld->HandleMenuItems(wParam, hwnd); 
		}

		break;


	case WM_LBUTTONUP:
		{
			g_GameWorld->SetCrosshair(MAKEPOINTS(lParam));
		}

		break;

	case WM_KEYUP:
		{
			switch(wParam)
			{
			case VK_ESCAPE:
				{             
					SendMessage(hwnd, WM_DESTROY, NULL, NULL);
				}

				break;

			case 'R':
				{
					delete g_GameWorld;

					g_GameWorld = new GameWorld(cxClient, cyClient);
				}

				break;


			}//end switch

			//handle any others
			g_GameWorld->HandleKeyPresses(wParam);

		}//end WM_KEYUP

		break;


	case WM_PAINT:
		{

			PAINTSTRUCT ps;

			BeginPaint (hwnd, &ps);

			//fill our backbuffer with white
			BitBlt(hdcBackBuffer,
				0,
				0,
				cxClient,
				cyClient,
				NULL,
				NULL,
				NULL,
				WHITENESS);


			gdi->StartDrawing(hdcBackBuffer);

			g_GameWorld->Render();

			gdi->StopDrawing(hdcBackBuffer);



			//now blit backbuffer to front
			BitBlt(ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY); 

			EndPaint (hwnd, &ps);

		}

		break;



	case WM_DESTROY:
		{

			//clean up our backbuffer objects
			SelectObject(hdcBackBuffer, hOldBitmap);

			DeleteDC(hdcBackBuffer);
			DeleteObject(hBitmap); 



			// kill the application, this sends a WM_QUIT message  
			PostQuitMessage (0);
		}

		break;

	}//end switch

	//this is where all the messages not specifically handled by our 
	//winproc are sent to be processed
	return DefWindowProc (hwnd, msg, wParam, lParam);
}
Beispiel #9
0
LRESULT CALLBACK WindowProc( HWND hwnd,
			     UINT msg,
			     WPARAM wParam,
			     LPARAM lParam ){
  
  static int cxClient, cyClient;
  
  static HDC hdcBackBuffer;
  static HBITMAP hBitmap = NULL;
  static HBITMAP hOldBitmap = NULL;
  
  static TCHAR filename[MAX_PATH], titlename[MAX_PATH];
  static RECT rectClientWindow;
  static int currentSearchButton = 0;
  
  static int ToolBarHeight;
  
  switch(msg){
    
  case WM_CREATE:{
    srand((unsigned) time(NULL));
    hdcBackBuffer = CreateCompatibleDC(NULL);

	//get the DC for front buffer
    HDC hdc = GetDC(hwnd);
    
    hBitmap = CreateCompatibleBitmap( hdc,
				      cxClient,
				      cyClient);

    hOldBitmap = (HBITMAP)SelectObject( hdcBackBuffer, hBitmap );

    ReleaseDC(hwnd, hdc);

    g_pathFinder = new PathFinder();

    CheckMenuItemAppropriately( hwnd, IDM_VIEW_TILES, g_pathFinder->IsShowTilesOn());
    CheckMenuItemAppropriately( hwnd, IDM_VIEW_GRAPH, g_pathFinder->IsShowGraphOn());
  }
    break;

  case UM_TOOLBAR_HAS_BEEN_CREATED:{
    RECT rectToolbar;
    GetWindowRect( g_hwndToolbar, &rectToolbar);
    ToolBarHeight = abs(rectToolbar.bottom - rectToolbar.top);

    rectClientWindow.left = 0;
    rectClientWindow.right = CLIENTWIDTH;
    rectClientWindow.top = 0;
    rectClientWindow.bottom = CLIENTHEIGHT + INFOWINDOWHEIGHT;

    ResizeToCorrectClientArea( hwnd, ToolBarHeight, rectClientWindow );

    SendMessage( g_hwndToolbar, WM_SIZE, wParam, lParam );

    GetClientRect( hwnd, &rectClientWindow );
    rectClientWindow.bottom = CLIENTHEIGHT - ToolBarHeight - 1;

    hdcBackBuffer = CreateCompatibleDC(NULL);

    HDC hdc = GetDC(hwnd);

    hBitmap = CreateCompatibleBitmap( hdc,
				      rectClientWindow.right,
				      rectClientWindow.bottom );

    hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap);

    ReleaseDC(hwnd, hdc);
  }
    break;

  case WM_KEYUP:{

    switch(wParam){
    case VK_ESCAPE:
      SendMessage( hwnd, WM_DESTROY, NULL, NULL ); break;
    case 'G':
      g_pathFinder->ToggleShowGraph(); break;
    case 'T':
      g_pathFinder->ToggleShowTiles(); break;
    } // switch

    RedrawWindowRect( hwnd, false, rectClientWindow ); 
  }
    break;

  case WM_LBUTTONDOWN:{
    g_pathFinder->PaintTerrain(MAKEPOINTS(lParam));
    RedrawWindowRect( hwnd, false, rectClientWindow );
  }
    break;

  case WM_MOUSEMOVE:{
    switch(wParam){
    case MK_LBUTTON:{
      g_pathFinder->PaintTerrain(MAKEPOINTS(lParam));
      RedrawWindowRect( hwnd, false, rectClientWindow );
    }
      break;
    }
  }
   // break;

  case WM_COMMAND:{

    switch(wParam){

    case ID_BUTTON_STOP:
      g_pathFinder->ChangeBrush( PathFinder::TARGET );      break;
    case ID_BUTTON_START:
      g_pathFinder->ChangeBrush( PathFinder::SOURCE );      break;
    case ID_BUTTON_OBSTACLE:
      g_pathFinder->ChangeBrush( PathFinder::OBSTACLE );    break;
    case ID_BUTTON_WATER:
      g_pathFinder->ChangeBrush( PathFinder::WATER );       break;
    case ID_BUTTON_MUD:
      g_pathFinder->ChangeBrush( PathFinder::MUD );         break;
    case ID_BUTTON_NORMAL:
      g_pathFinder->ChangeBrush( PathFinder::NORMAL );      break;
    case ID_BUTTON_DFS:
      g_pathFinder->CreatePathDFS();
      currentSearchButton = ID_BUTTON_DFS;    break;
    case ID_BUTTON_BFS:
      g_pathFinder->CreatePathBFS();
      currentSearchButton = ID_BUTTON_BFS;    break;
    case ID_BUTTON_DIJKSTRA:
      g_pathFinder->CreatePathDijkstra();
      currentSearchButton = ID_BUTTON_DIJKSTRA; break;
    case ID_BUTTON_ASTAR:
      g_pathFinder->CreatePathAStar();
      currentSearchButton = ID_BUTTON_ASTAR;  break;

    case ID_MENU_LOAD:
      FileOpenDlg( hwnd, filename, titlename, "PathFinder Files (*.map)", "map" );
      if(strlen(titlename) > 0)
		  g_pathFinder->Load(titlename);

      SendMessage( g_hwndToolbar, TB_CHECKBUTTON, (WPARAM)currentSearchButton, (LPARAM)false );
      break;

    case ID_MENU_SAVEAS:
      FileSaveDlg( hwnd, filename, titlename, "PathFinder Files (*.map)", "map" );
      if(strlen(titlename) > 0)
		  g_pathFinder->Save(titlename);
      break;

    case ID_MENU_NEW:
      g_pathFinder->CreateGraph( NUMCELLSX, NUMCELLSY );
      SendMessage( g_hwndToolbar, TB_CHECKBUTTON, (WPARAM)currentSearchButton, (LPARAM)false );
      break;

    case IDM_VIEW_GRAPH:
      if(GetMenuState(GetMenu(hwnd), IDM_VIEW_GRAPH, MFS_CHECKED) && MF_CHECKED){
	ChangeMenuState( hwnd, IDM_VIEW_GRAPH, MFS_UNCHECKED );
	g_pathFinder->SwitchGraphOff();
      }
      else{
	ChangeMenuState( hwnd, IDM_VIEW_GRAPH, MFS_CHECKED );
	g_pathFinder->SwitchGraphOn();
      }
      break;

    case IDM_VIEW_TILES:
      if(GetMenuState(GetMenu(hwnd), IDM_VIEW_TILES, MFS_CHECKED) && MF_CHECKED){
	ChangeMenuState( hwnd, IDM_VIEW_TILES, MFS_UNCHECKED );
	g_pathFinder->SwitchTilesOff();
      }
      else{
	ChangeMenuState( hwnd, IDM_VIEW_TILES, MFS_CHECKED );
	g_pathFinder->SwitchTilesOn();
      }
      break;
    } // switch

    RedrawWindowRect( hwnd, false, rectClientWindow );
  }

  case WM_PAINT:{

    PAINTSTRUCT ps;

    BeginPaint(hwnd, &ps);

    BitBlt( hdcBackBuffer, 0, 0, cxClient, cyClient, NULL, NULL, NULL, WHITENESS );

    wpgdi->StartDrawing(hdcBackBuffer);

    g_pathFinder->Render();

    wpgdi->StopDrawing(hdcBackBuffer);

    BitBlt( ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY );

    EndPaint(hwnd, &ps);
  }
    break;

  case WM_SIZE:{
    cxClient = LOWORD(lParam);
    cyClient = HIWORD(lParam);

    SelectObject(hdcBackBuffer, hOldBitmap);

    DeleteObject(hBitmap);

    HDC hdc = GetDC(hwnd);

    hBitmap = CreateCompatibleBitmap( hdc,
				      rectClientWindow.right,
				      rectClientWindow.bottom );

    ReleaseDC(hwnd, hdc);
    SelectObject(hdcBackBuffer, hBitmap);
  }
    break;

  case WM_DESTROY:{
    SelectObject(hdcBackBuffer, hOldBitmap);

    DeleteDC(hdcBackBuffer);
    DeleteObject(hBitmap);
    DeleteObject(hOldBitmap);

    PostQuitMessage(0);
  }
    break;
  } // end switch

  return DefWindowProc( hwnd, msg, wParam, lParam );		      
}
Beispiel #10
0
void Gamestate_ProcessEvent(struct Game *game, struct MenuResources* data, ALLEGRO_EVENT *ev) {

	if ((data->menustate == MENUSTATE_ABOUT) && (ev->type == ALLEGRO_EVENT_KEY_DOWN)) {
		ChangeMenuState(game, data, MENUSTATE_MAIN);
		return;
	}

	if (ev->type != ALLEGRO_EVENT_KEY_DOWN) return;

	if (data->starting) return;

	if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
		data->selected--;
		if ((data->selected == 2) && ((data->menustate==MENUSTATE_VIDEO) || (data->menustate==MENUSTATE_OPTIONS) || (data->menustate==MENUSTATE_AUDIO))) {
			data->selected --;
		}
		if ((data->menustate==MENUSTATE_VIDEO) && (data->selected==1) && (data->options.fullscreen)) data->selected--;
		al_play_sample_instance(data->click);
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
		data->selected++;
		if ((data->menustate==MENUSTATE_VIDEO) && (data->selected==1) && (data->options.fullscreen)) data->selected++;
		if ((data->selected == 2) && ((data->menustate==MENUSTATE_VIDEO) || (data->menustate==MENUSTATE_OPTIONS) || (data->menustate==MENUSTATE_AUDIO))) {
			data->selected ++;
		}


		al_play_sample_instance(data->click);
	}

	if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) {
		char *text;
		al_play_sample_instance(data->click);
		switch (data->menustate) {
			case MENUSTATE_MAIN:
				switch (data->selected) {
					case 0:
						StartGame(game, data);
						break;
					case 1:
						ChangeMenuState(game,data,MENUSTATE_OPTIONS);
						break;
					case 2:
						ChangeMenuState(game,data,MENUSTATE_ABOUT);
						break;
					case 3:
						UnloadGamestate(game, "menu");
						break;
				}
				break;
			case MENUSTATE_HIDDEN:
				ChangeMenuState(game,data,MENUSTATE_MAIN);
				break;
			case MENUSTATE_AUDIO:
				text = malloc(255*sizeof(char));
				switch (data->selected) {
					case 0:
						game->config.music--;
						if (game->config.music<0) game->config.music=10;
						snprintf(text, 255, "%d", game->config.music);
						SetConfigOption(game, "SuperDerpy", "music", text);
						al_set_mixer_gain(game->audio.music, game->config.music/10.0);
						break;
					case 1:
						game->config.fx--;
						if (game->config.fx<0) game->config.fx=10;
						snprintf(text, 255, "%d", game->config.fx);
						SetConfigOption(game, "SuperDerpy", "fx", text);
						al_set_mixer_gain(game->audio.fx, game->config.fx/10.0);
						break;
					case 2:
						game->config.voice--;
						if (game->config.voice<0) game->config.voice=10;
						snprintf(text, 255, "%d", game->config.voice);
						SetConfigOption(game, "SuperDerpy", "voice", text);
						al_set_mixer_gain(game->audio.voice, game->config.voice/10.0);
						break;
					case 3:
						ChangeMenuState(game,data,MENUSTATE_OPTIONS);
						break;
				}
				free(text);
				break;
			case MENUSTATE_OPTIONS:
				switch (data->selected) {
					case 0:
						ChangeMenuState(game,data,MENUSTATE_VIDEO);
						break;
					case 1:
						ChangeMenuState(game,data,MENUSTATE_AUDIO);
						break;
					case 3:
						ChangeMenuState(game,data,MENUSTATE_MAIN);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_VIDEO:
				switch (data->selected) {
					case 0:
						data->options.fullscreen = !data->options.fullscreen;
						if (data->options.fullscreen)
							SetConfigOption(game, "SuperDerpy", "fullscreen", "1");
						else
							SetConfigOption(game, "SuperDerpy", "fullscreen", "0");
						al_set_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, data->options.fullscreen);
						SetupViewport(game);
						PrintConsole(game, "Fullscreen toggled");
						break;
					case 1:
						data->options.resolution++;

						int max = 0, i = 0;

						for (i=0; i < al_get_num_video_adapters(); i++) {
							ALLEGRO_MONITOR_INFO aminfo;
							al_get_monitor_info(i , &aminfo);
							int desktop_width = aminfo.x2 - aminfo.x1 + 1;
							int desktop_height = aminfo.y2 - aminfo.y1 + 1;
							int localmax = desktop_width / 320;
							if (desktop_height / 180 < localmax) localmax = desktop_height / 180;
							if (localmax > max) max = localmax;
						}


						if (data->options.resolution > max) data->options.resolution = 1;
						text = malloc(255*sizeof(char));
						snprintf(text, 255, "%d", data->options.resolution * 320);
						SetConfigOption(game, "SuperDerpy", "width", text);
						snprintf(text, 255, "%d", data->options.resolution * 180);
						SetConfigOption(game, "SuperDerpy", "height", text);
						free(text);
						al_resize_display(game->display, data->options.resolution * 320, data->options.resolution * 180);

						if ((al_get_display_width(game->display) < (data->options.resolution * 320)) || (al_get_display_height(game->display) < (data->options.resolution * 180))) {
							SetConfigOption(game, "SuperDerpy", "width", "320");
							SetConfigOption(game, "SuperDerpy", "height", "180");
							data->options.resolution = 1;
							al_resize_display(game->display, 320, 180);
						}

						SetupViewport(game);
						PrintConsole(game, "Resolution changed");
						break;
					case 3:
						ChangeMenuState(game,data,MENUSTATE_OPTIONS);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_ABOUT:
				break;
			default:
				UnloadGamestate(game, "menu");
				return;
				break;
		}
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) {
		switch (data->menustate) {
			case MENUSTATE_OPTIONS:
				ChangeMenuState(game,data,MENUSTATE_MAIN);
				break;
			case MENUSTATE_ABOUT:
				ChangeMenuState(game,data,MENUSTATE_MAIN);
				break;
			case MENUSTATE_HIDDEN:
				UnloadGamestate(game, "menu");
				break;
			case MENUSTATE_VIDEO:
				ChangeMenuState(game,data,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_AUDIO:
				ChangeMenuState(game,data,MENUSTATE_OPTIONS);
				break;
			default:
				ChangeMenuState(game,data,MENUSTATE_HIDDEN);
				data->selected = -1;
				data->title_pos = 0;
				return;
		}
	}

	if (data->selected==-1) data->selected=3;
	if (data->selected==4) data->selected=0;
	return;
}
Beispiel #11
0
void StartGame(struct Game *game, struct MenuResources *data) {
	ChangeMenuState(game,data,MENUSTATE_HIDDEN);
	data->starting = true;
}