コード例 #1
0
ファイル: MainMenu.c プロジェクト: pdetagyos/Brogue-iPad
void initializeMenuFlames(boolean includeTitle,
						  color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)],
						  signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4],
						  signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3],
						  unsigned char mask[COLS][ROWS]) {
	short i, j, k, colorSourceCount;
	const char title[MENU_TITLE_HEIGHT][MENU_TITLE_WIDTH+1] = {
		"########   ########       ######         #######   ####     ###  #########",
		" ##   ###   ##   ###    ##     ###     ##      ##   ##       #    ##     #",
		" ##    ##   ##    ##   ##       ###   ##        #   ##       #    ##     #",
		" ##    ##   ##    ##   #    #    ##   #         #   ##       #    ##      ",
		" ##    ##   ##    ##  ##   ##     ## ##             ##       #    ##    # ",
		" ##   ##    ##   ##   ##   ###    ## ##             ##       #    ##    # ",
		" ######     ## ###    ##   ####   ## ##             ##       #    ####### ",
		" ##    ##   ##  ##    ##   ####   ## ##             ##       #    ##    # ",
		" ##     ##  ##   ##   ##    ###   ## ##      #####  ##       #    ##    # ",
		" ##     ##  ##   ##   ###    ##   ## ###       ##   ##       #    ##      ",
		" ##     ##  ##    ##   ##    #    #   ##       ##   ##       #    ##      ",
		" ##     ##  ##    ##   ###       ##   ###      ##   ###      #    ##     #",
		" ##    ##   ##     ##   ###     ##     ###    ###    ###    #     ##     #",
		"########   ####    ###    ######         #####        ######     #########",
		"                            ##                                            ",
		"                        ##########                                        ",
		"                            ##                                            ",
		"                            ##                                            ",
		"                           ####                                           ",
	};
	
	for (i=0; i<COLS; i++) {
		for (j=0; j<ROWS; j++) {
			mask[i][j] = 0;
		}
	}
	
	for (i=0; i<COLS; i++) {
		for (j=0; j<(ROWS + MENU_FLAME_ROW_PADDING); j++) {
			colors[i][j] = NULL;
			for (k=0; k<3; k++) {
				flames[i][j][k] = 0;
			}
		}
	}
	
	// Seed source color random components.
	for (i=0; i<MENU_FLAME_COLOR_SOURCE_COUNT; i++) {
		for (k=0; k<4; k++) {
			colorSources[i][k] = rand_range(0, 1000);
		}
	}
	
	// Put some flame source along the bottom row.
	colorSourceCount = 0;
	for (i=0; i<COLS; i++) {
		colors[i][(ROWS + MENU_FLAME_ROW_PADDING)-1] = &flameSourceColor;
		colorSourceCount++;
	}
	
	if (includeTitle) {
		// Wreathe the title in flames, and mask it in black.
		for (i=0; i<MENU_TITLE_WIDTH; i++) {
			for (j=0; j<MENU_TITLE_HEIGHT; j++) {
				if (title[j][i] != ' ') {
					colors[(COLS - MENU_TITLE_WIDTH)/2 + i + MENU_TITLE_OFFSET_X][(ROWS - MENU_TITLE_HEIGHT)/2 + j + MENU_TITLE_OFFSET_Y] = &flameTitleColor;
					colorSourceCount++;
					mask[(COLS - MENU_TITLE_WIDTH)/2 + i + MENU_TITLE_OFFSET_X][(ROWS - MENU_TITLE_HEIGHT)/2 + j + MENU_TITLE_OFFSET_Y] = 100;
				}
			}
		}
		
		// Anti-alias the mask.
		antiAlias(mask);
	}
	
#ifdef BROGUE_ASSERTS
	assert(colorSourceCount <= MENU_FLAME_COLOR_SOURCE_COUNT);
#endif
	
	// Simulate the background flames for a while
	for (i=0; i<100; i++) {
		updateMenuFlames(colors, colorSources, flames);
	}
	
}
コード例 #2
0
ファイル: MainMenu.c プロジェクト: pdetagyos/Brogue-iPad
void titleMenu() {
	signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3]; // red, green and blue
	signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4]; // red, green, blue, and rand, one for each color source (no more than MENU_FLAME_COLOR_SOURCE_COUNT).
	color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)];
	unsigned char mask[COLS][ROWS];
	boolean controlKeyWasDown = false;
	
	short i, b, x, y, button;
	buttonState state;
	brogueButton buttons[6];
	char whiteColorEscape[10] = "";
	char goldColorEscape[10] = "";
	char newGameText[100] = "", customNewGameText[100] = "";
	rogueEvent theEvent;
	enum NGCommands buttonCommands[6] = {NG_NEW_GAME, NG_OPEN_GAME, NG_VIEW_RECORDING, NG_HIGH_SCORES, NG_QUIT};
	
	cellDisplayBuffer shadowBuf[COLS][ROWS];
	
	// Initialize the RNG so the flames aren't always the same.
	
	seedRandomGenerator(0);
	
	// Empty nextGamePath and nextGameSeed so that the buttons don't try to load an old game path or seed.
	rogue.nextGamePath[0] = '\0';
	rogue.nextGameSeed = 0;
	
	// Initialize the title menu buttons.
	encodeMessageColor(whiteColorEscape, 0, &white);
    encodeMessageColor(goldColorEscape, 0, KEYBOARD_LABELS ? &itemMessageColor : &white);
	sprintf(newGameText, "      %sN%sew Game      ", goldColorEscape, whiteColorEscape);
	sprintf(customNewGameText, " %sN%sew Game (custom) ", goldColorEscape, whiteColorEscape);
	b = 0;
	button = -1;
	
	initializeButton(&(buttons[b]));
	strcpy(buttons[b].text, newGameText);
	buttons[b].hotkey[0] = 'n';
	buttons[b].hotkey[1] = 'N';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, "     %sO%spen Game      ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'o';
	buttons[b].hotkey[1] = 'O';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, "   %sV%siew Recording   ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'v';
	buttons[b].hotkey[1] = 'V';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, "    %sH%sigh Scores     ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'h';
	buttons[b].hotkey[1] = 'H';
	b++;
	
    // Seth:
/*	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, "        %sQ%suit        ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'q';
	buttons[b].hotkey[1] = 'Q';
	b++;*/
	
	x = COLS - 1 - 20 - 2;
	y = ROWS - 1;
	for (i = b-1; i >= 0; i--) {
		y -= 2;
		buttons[i].x = x;
		buttons[i].y = y;
		buttons[i].buttonColor = titleButtonColor;
		buttons[i].flags |= B_WIDE_CLICK_AREA;
	}
	
	blackOutScreen();
	clearDisplayBuffer(shadowBuf);
	initializeButtonState(&state, buttons, b, x, y, 20, b*2-1);
	rectangularShading(x, y, 20, b*2-1, &black, INTERFACE_OPACITY, shadowBuf);
	drawButtonsInState(&state);
    
	initializeMenuFlames(true, colors, colorSources, flames, mask);
    rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack
	
	do {
		if (!controlKeyWasDown && controlKeyIsDown()) {
			strcpy(state.buttons[0].text, customNewGameText);
			drawButtonsInState(&state);
			buttonCommands[0] = NG_NEW_GAME_WITH_SEED;
			controlKeyWasDown = true;
		} else if (controlKeyWasDown && !controlKeyIsDown()) {
			strcpy(state.buttons[0].text, newGameText);
			drawButtonsInState(&state);
			buttonCommands[0] = NG_NEW_GAME;
			controlKeyWasDown = false;
		}
		
		// Update the display.
		updateMenuFlames(colors, colorSources, flames);
		drawMenuFlames(flames, mask);
		overlayDisplayBuffer(shadowBuf, NULL);
		overlayDisplayBuffer(state.dbuf, NULL);
		
		// Pause briefly.
		if (pauseBrogue(MENU_FLAME_UPDATE_DELAY)) {
			// There was input during the pause! Get the input.
			nextBrogueEvent(&theEvent, true, false, true);
			
			// Process the input.
			button = processButtonInput(&state, NULL, &theEvent);
		}
		
		// Revert the display.
		overlayDisplayBuffer(state.rbuf, NULL);
		
	} while (button == -1 && rogue.nextGame == NG_NOTHING);
	drawMenuFlames(flames, mask);
	if (button != -1) {
		rogue.nextGame = buttonCommands[button];
	}
}
コード例 #3
0
ファイル: MainMenu.c プロジェクト: jagt/brogue-chs-translate
void titleMenu() {
	signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3]; // red, green and blue
	signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4]; // red, green, blue, and rand, one for each color source (no more than MENU_FLAME_COLOR_SOURCE_COUNT).
	color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)];
	unsigned char mask[COLS][ROWS];
	boolean controlKeyWasDown = false;
	
	short i, b, x, y, button;
	buttonState state;
	brogueButton buttons[6];
	char whiteColorEscape[10] = "";
	char goldColorEscape[10] = "";
	char newGameText[100] = "", customNewGameText[100] = "";
	rogueEvent theEvent;
	enum NGCommands buttonCommands[6] = {NG_NEW_GAME, NG_OPEN_GAME, NG_VIEW_RECORDING, NG_HIGH_SCORES, NG_QUIT};
	BROGUE_WINDOW *root, *window, *title_window, *button_window;
	BROGUE_DRAW_CONTEXT *context, *title_context, *button_context;
	BROGUE_EFFECT *button_effect;
	BROGUE_GRAPHIC *title_graphic;
	
	// Initialize the RNG so the flames aren't always the same.
	
	seedRandomGenerator(0);
	
	// Empty nextGamePath and nextGameSeed so that the buttons don't try to load an old game path or seed.
	rogue.nextGamePath[0] = '\0';
	rogue.nextGameSeed = 0;
	
	// Initialize the title menu buttons.
	encodeMessageColor(whiteColorEscape, 0, &white);
	encodeMessageColor(goldColorEscape, 0, &itemMessageColor);
	sprintf(newGameText, " %s(N)%s 开始新游戏", goldColorEscape, whiteColorEscape);
	sprintf(customNewGameText, " %s(N)%s 生成新游戏", goldColorEscape, whiteColorEscape);
	b = 0;
	button = -1;
	
	initializeButton(&(buttons[b]));
	strcpy(buttons[b].text, newGameText);
	buttons[b].hotkey[0] = 'n';
	buttons[b].hotkey[1] = 'N';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, " %s(O)%s 读取存档   ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'o';
	buttons[b].hotkey[1] = 'O';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, " %s(V)%s 观看录像   ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'v';
	buttons[b].hotkey[1] = 'V';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, " %s(H)%s 最高分      ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'h';
	buttons[b].hotkey[1] = 'H';
	b++;
	
	initializeButton(&(buttons[b]));
	sprintf(buttons[b].text, " %s(Q)%s 退出游戏   ", goldColorEscape, whiteColorEscape);
	buttons[b].hotkey[0] = 'q';
	buttons[b].hotkey[1] = 'Q';
	b++;
	
	x = COLS - 1 - 20 - 2;
	y = ROWS - 3;
	for (i = b-1; i >= 0; i--) {
		y -= 2;

		buttons[i].x = 1;
		buttons[i].y = 1 + 2 * i;
		buttons[i].buttonColor = interfaceButtonColor;
		buttons[i].flags |= B_WIDE_CLICK_AREA;
	}

	title_graphic = BrogueGraphic_open("svg/title.svg");

	root = ioGetRoot();
	window = BrogueWindow_open(root, 0, 0, COLS, ROWS);
	context = BrogueDrawContext_open(window);

	title_window = BrogueWindow_open(window, 0, 0, COLS, ROWS);
	title_context = BrogueDrawContext_open(title_window);
	if (title_graphic != NULL)
	{
		BrogueDrawContext_drawGraphic(title_context, 0, 0, COLS, ROWS, 
									  title_graphic);
	}

	button_window = BrogueWindow_open(window, x, y, 22, b * 2 + 1);
	BrogueWindow_setColor(button_window, windowColor);
	button_context = BrogueDrawContext_open(button_window);
	button_effect = BrogueEffect_open(button_context, BUTTON_EFFECT_NAME);
	
	blackOutScreen();
	initializeButtonState(&state, buttons, b, button_context, button_effect, 
						  x, y, 20, b*2-1);
	drawButtonsInState(button_context, button_effect, &state);

	initializeMenuFlames(true, colors, colorSources, flames, mask);
    rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack
	
	do {
		if (!controlKeyWasDown && controlKeyIsDown()) {
			strcpy(state.buttons[0].text, customNewGameText);
			drawButtonsInState(button_context, button_effect, &state);
			buttonCommands[0] = NG_NEW_GAME_WITH_SEED;
			controlKeyWasDown = true;
		} else if (controlKeyWasDown && !controlKeyIsDown()) {
			strcpy(state.buttons[0].text, newGameText);
			drawButtonsInState(button_context, button_effect, &state);
			buttonCommands[0] = NG_NEW_GAME;
			controlKeyWasDown = false;
		}
		
		// Update the display.
		updateMenuFlames(colors, colorSources, flames);
		drawMenuFlames(context, flames);
		
		// Pause briefly.
		if (pauseBrogue(MENU_FLAME_UPDATE_DELAY)) {
			// There was input during the pause! Get the input.
			nextBrogueEvent(&theEvent, true, false, true);
			
			// Process the input.
			button = processButtonInput(button_context, button_effect, 
										&state, NULL, &theEvent);
		}
	} while (button == -1 && rogue.nextGame == NG_NOTHING);
	drawMenuFlames(context, flames);
	if (button != -1) {
		rogue.nextGame = buttonCommands[button];
	}

	BrogueWindow_close(window);
	BrogueGraphic_close(title_graphic);
}