コード例 #1
0
void AnimateDamage(int x, int y, int damage)
{
	std::ostringstream ss;
	ss << damage;
	std::string s = ss.str();

	int n_steps = duration * fps;
	float angle_delta = 2.0f * pi / n_steps;

	terminal_layer(animation_layer);
	for (int i=0; i<n_steps; i++)
	{
		if (terminal_has_input()) break;
		terminal_clear_area(0, 0, terminal_state(TK_WIDTH), terminal_state(TK_HEIGHT));
		float dx = std::sin(i*angle_delta) * radius * terminal_state(TK_CELL_WIDTH) + i*2;
		float dy = -2.0f * radius * terminal_state(TK_CELL_WIDTH) / n_steps * i - terminal_state(TK_CELL_HEIGHT)/2;
		terminal_color(color_from_argb(255/n_steps*(n_steps-i), 255, 64, 0));
		terminal_printf(x, y, "[offset=%dx%d]%s", (int)dx, (int)dy, s.c_str());
		terminal_refresh();
		terminal_delay(1000/fps);
	}
	terminal_color("white");
}
コード例 #2
0
void TestTilesets()
{
	terminal_set("window.title='Omni: tilesets'");
	terminal_composition(TK_ON);

	// Load tilesets
	terminal_set("U+E100: ../Media/Runic.png, size=8x16");
	terminal_set("U+E200: ../Media/Tiles.png, size=32x32, align=top-left");
	terminal_set("U+E300: ../Media/fontawesome-webfont.ttf, size=24x24, spacing=3x2, codepage=../Media/fontawesome-codepage.txt");
	terminal_set("zodiac font: ../Media/Zodiac-S.ttf, size=24x36, spacing=3x3, codepage=437");

	terminal_clear();
	terminal_color("white");

	terminal_print(2, 1, "[color=orange]1.[/color] Of course, there is default font tileset.");

	terminal_print(2, 3, "[color=orange]2.[/color] You can load some arbitrary tiles and use them as glyphs:");
	terminal_print
	(
		2+3, 4,
		"Fire rune ([color=red][U+E102][/color]), "
		"water rune ([color=lighter blue][U+E103][/color]), "
		"earth rune ([color=darker green][U+E104][/color])"
	);

	terminal_print(2, 6, "[color=orange]3.[/color] Tiles are not required to be of the same size as font symbols:");
	terminal_put(2+3+0, 7, 0xE200+7);
	terminal_put(2+3+5, 7, 0xE200+8);
	terminal_put(2+3+10, 7, 0xE200+9);

	terminal_print(2, 10, "[color=orange]4.[/color] Like font characters, tiles may be freely colored and combined:");
	terminal_put(2+3+0, 11, 0xE200+8);
	terminal_color("lighter orange");
	terminal_put(2+3+5, 11, 0xE200+8);
	terminal_color("orange");
	terminal_put(2+3+10, 11, 0xE200+8);
	terminal_color("dark orange");
	terminal_put(2+3+15, 11, 0xE200+8);

	terminal_color("white");
	std::vector<int> order = {11, 10, 14, 12, 13};
	for (int i=0; i<order.size(); i++)
	{
		terminal_put(2+3+25+i*4, 11, 0xE200+order[i]);
		terminal_put(2+3+25+(order.size()+1)*4, 11, 0xE200+order[i]);
	}
	terminal_put(2+3+25+order.size()*4, 11, 0xE200+15);

	terminal_print(2, 14, "[color=orange]5.[/color] And tiles can even come from TrueType fonts like this:");
	for (int i=0; i<6; i++)
	{
		terminal_put(2+3+i*5, 15, 0xE300+i);
	}

	terminal_print(2+3, 18, "...or like this:\n[font=zodiac]D F G S C");

	terminal_refresh();

	for (int key=0; key!=TK_CLOSE && key!=TK_ESCAPE; key=terminal_read());

	// Clean up
	terminal_set("U+E100: none; U+E200: none; U+E300: none; zodiac font: none");
	terminal_composition(TK_OFF);
}
コード例 #3
0
void TestExtendedInterlayer()
{
	// Setup
	terminal_set("window.title='Omni: extended output / interlayer animation'");
	terminal_composition(TK_ON);

	int map_left = terminal_state(TK_WIDTH)/2 - map_width/2;
	int map_top = terminal_state(TK_HEIGHT)/2 - map_height/2;

	std::srand(std::time(nullptr));
	auto map = PrepareMap();
	PlaceFoe();

	auto Attack = [&]
	{
		int damage = 1+std::rand()%10;
		foe_hp -= damage;
		int x = foe_x, y = foe_y;
		if (foe_hp <= 0)
		{
			map[foe_y*map_width+foe_x] = 1;
			PlaceFoe();
			terminal_clear();
			DrawMap(map_left, map_top, map);
		}
		AnimateDamage(map_left+x, map_top+y, -damage);
	};

	auto Step = [&](int dx, int dy)
	{
		if (player_x+dx == foe_x && player_y+dy == foe_y)
		{
			Attack();
		}
		else if (map[(player_y+dy)*map_width+player_x+dx] <= 1)
		{
			player_x += dx;
			player_y += dy;
		}
	};

	for (bool proceed=true; proceed;)
	{
		terminal_clear();
		DrawMap(map_left, map_top, map);
		terminal_refresh();

		do
		{
			int key = terminal_read();
			if (key == TK_CLOSE || key == TK_ESCAPE)
			{
				proceed = false;
			}
			else if (key == TK_LEFT)
			{
				Step(-1, 0);
			}
			else if (key == TK_UP)
			{
				Step(0, -1);
			}
			else if (key == TK_RIGHT)
			{
				Step(1, 0);
			}
			else if (key == TK_DOWN)
			{
				Step(0, 1);
			}
		}
		while (proceed && terminal_has_input());
	}

	// Clean up
	terminal_composition(TK_OFF);
	terminal_clear();
	terminal_layer(0);
}
コード例 #4
0
void BasicOutput()
{
	terminal_options("title=BearLibTerminal demo: output facilities");
	terminal_options("font.name=default; font.supplement=Media/Omni/supplement-runic.png");

	terminal_blending(BLENDING_ADDITIVE);
	terminal_color(COLOR_WHITE);

	terminal_clear();

	// Simple output with postformatting
	terminal_printf(1, 1, "[color=gray]1. Most basic:[/color] ABC abc");

	// Wide color range
	int n = terminal_printf(1, 3, "[color=gray]2. Colors: ");
	const char long_word[] = "Antidisestablishmentarianism";
	const size_t long_word_length = sizeof(long_word)-1;
	for ( size_t i = 0; i < long_word_length; i++ )
	{
		float factor = float(i)/long_word_length;
		int red = (1.0f - factor) * 255;
		int green = factor * 255;
		terminal_color(color_from_argb(255, red, green, 0));
		terminal_put(n+1+i, 3, long_word[i]);
	}
	terminal_color(color_from_name("white"));

	// Tile backgrounds
	terminal_printf(1, 5, "[color=gray]3. Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red ");

	// Simple unicode output
	terminal_printf(1, 7, "[color=gray]4. Unicode:[/color] Latin Русский Ελληνικά");

	// Composite (overlay) tiles
	n = terminal_printf(1, 9, "[color=gray]5. Tile overlay: ");
	terminal_printf(n+1, 9, "a+  = a, a+  = a, a vs. [color=red]ä");
	terminal_printf(n+1, 9, "[color=red]  /   /    ▔   ▔        [/color]a");

	// Unicode Box Drawing characters
	terminal_printf(1, 11, "[color=gray]6. Box drawing:");
	const char* box_lines[] =
	{
		"       ┌──┬───┐      ╔═════╗ ",
		" ┌───┬─┘  │   ├──┐   ╟──┐  ║ ",
		" └─┐ └─┐  ├───┘  │   ║  └──╢ ",
		"   └───┴──┴──────┘   ╚═════╝ "
	};
	for ( size_t i = 0; i < sizeof(box_lines)/sizeof(box_lines[i]); i++ )
	{
		terminal_printf(1, 12+i, "%s", box_lines[i]);
	}

	// Box drawing + overlay application
	terminal_printf(1, 17, "[color=gray]7. Box drawing + overlay:");
	terminal_color(0xFF006000);
	for ( int y = 0; y < 6; y++ )
	{
		for ( int x = 0; x < 19; x++ )
		{
			terminal_put(1+x, 18+y, 'A'+(x+y)%26);
		}
	}
	DrawOverlayRectangle(3, 19, 15, 4, 0xFFFFFFFF, 0xA0909090);
	terminal_printf(4, 20, "[color=white]Itym:\nHeavy draggon");

	terminal_printf(40, 17, "[color=gray]8. Font supplement:");
	terminal_printf(40, 19, "fire ([color=red][uE001][/color]) - water ([color=lighter blue][uE004][/color]) - earth ([color=dark green][uE00F][/color])");
	terminal_printf(40, 20, "\uE001\uE002\uE003, \uE004\uE005\uE006\uE007\uE008! \uE009\uE00A\uE00B \uE00C \uE00D\uE00E\uE00F\uE010.");

	terminal_refresh();

	int key = 0;
	do
	{
		key = terminal_get();
	}
	while ( key != VK_CLOSE && key != VK_ESCAPE );
}