Exhibition Letter Entry Demo

Projects meant as a technical demonstrator or instructional tutorial.

DCurrent

Site Owner, OpenBOR Project Leader
Staff member
So after reading the Assigning any name to a character in-engine post by mishadude, I really liked the idea, but think it could be done more eloquently.

My idea is to place the character set into an array, and then draw them to the screen directly using a grid. Then capture the player key and get character based on their location within the grid. The advantage over your entity per character method is it will be far simpler and less resource intensive, plus you can replace characters on the fly and don't need to worry at all about arranging spawns.

First draft is underway - the visual display. This script accepts the X/Y sector size and Left/right/Top/Bottom margins. It then builds a grid, and prints the number of each sector. The next step will be to pull in characters from an array instead of the sector number. Then I'll work on detection. Note the checkerboard grid won't be visible when complete, it's just there to debug right now.

BOR - 0001.png

C:
void dc_grid_spawn()
{
	#define FONT		1
	#define ALPHA		6
	#define COLOR		1 // Color index for line.
	#define LAYER_FRONT openborconstant("FRONTPANEL_Z") + 20000 
	#define MARGIN_LEFT 50
	#define MARGIN_RIGHT 50
	#define	MARGIN_TOP 50
	#define MARGIN_BOTTOM 100
	#define DEFAULT_SECTOR_SIZE_X 25
	#define DEFAULT_SECTOR_SIZE_Y 25
	
	// Size of each grid portion.
	int sector_size_y = DEFAULT_SECTOR_SIZE_Y;
	int sector_size_x = DEFAULT_SECTOR_SIZE_X;

	int scroll_min_z;
	int scroll_max_z;

	// Loop cursors.
	int cursor_x;
	int cursor_y;
	int count;
	int count_row;
	int count_col;
	
	// Grid debug
	int color;
	char grid_text;
	
	if (!openborvariant("in_level"))
	{
		return;
	}
	
	float pos_x_start	= 0.0 + MARGIN_LEFT;
	float pos_x_end		= openborvariant("hresolution") - (MARGIN_RIGHT + sector_size_x);
	float pos_y_start = openborvariant("scrollminz") + MARGIN_TOP;
	float pos_y_end = openborvariant("scrollmaxz") - MARGIN_BOTTOM;
		
	// Reset counters.
	count_row = 0;
	count_col = 0;
	count = 0;
	
	// Loop rows.
	for (cursor_y = pos_y_start; cursor_y < pos_y_end; cursor_y += sector_size_y)
	{	
		count_row++;

		// Loop columns.
		for (cursor_x = pos_x_start; cursor_x < pos_x_end; cursor_x += sector_size_x)
		{	
			count_col++;

			count++;

			// Alternate the color sector count is even/odd.
			if (count_row % 2 == count_col % 2)
			{
				color = rgbcolor(255, 0, 0);
			}
			else
			{
				color = rgbcolor(0, 0, 255);
			}

			// Draw grid and text.
			drawstring(cursor_x + (sector_size_x * 0.1), cursor_y + (sector_size_y / 2), FONT, count);
			drawbox(cursor_x, cursor_y, sector_size_x, sector_size_y, LAYER_FRONT, color, ALPHA);
		}
	}
	
	#undef FONT
	#undef ALPHA
	#undef COLOR
	#undef LAYER_FRONT
}

Once that's done it can be made more organic than a straight up grid. I already have a script that when given a set of margins and text, will auto line break and individually center each row. The cool part is it automatically adapts to the letter size of whatever font you are using (OpenBOR is aware of font size and it's available to script). It's how the name displays work in my Fatal Fury project. Shouldn't be too hard to implement in the letter entry system.

bor - 0061.png

C:
// Caskey, Damon V.
// 2019-02-22
//
// Draws names of characters during select screen.
void dc_draw_select_names()
{
	// Don't waste any more cycles if we aren't 
	// in select screen.
	if (!openborvariant("in_selectscreen"))
	{
		return;
	}

	int i;
	int maxplayers;
	char name_full;
	char name_last;
	char name_first;

	int font;
	int x_base;
	int x_pos;
	int y_pos;
	int string_width;

	int section_size;
	int section_half;

	int elapsed_time;
	int select_time;

	void screen;

	int screen_scale_x;
	int screen_scale_y;

	int scale_add;

	int screen_width;
	int screen_height;


	elapsed_time = openborvariant("elapsed_time");
	maxplayers = openborvariant("maxplayers");

	// Divide up the screen into even sections for each player.
	section_size = openborvariant("hresolution") / maxplayers;
	section_half = section_size / 2;

	for (i = 0; i < maxplayers; i++)
	{		
		// Get to start of our section, and add half to find the center.
		x_base = (dc_player_multiplier(i) * section_size) + section_half;

		name_full = getplayerproperty(i, "name");
		name_last = strinfirst(name_full, SPACE_CHAR);

		// No last name?
		if (name_last == -1)
		{
			x_pos = dc_center_string_x(x_base, name_full, WAIT_NAME_FONT);
			y_pos = dc_center_string_y(SELECT_Y_BASE, name_full, FONT_Y);

			screen_width = strwidth(name_full, WAIT_NAME_FONT);
			screen_height = FONT_Y;			

			drawstring(x_pos, y_pos, WAIT_NAME_FONT, name_full);
			//drawstringtoscreen(screen, x_pos, y_pos, WAIT_NAME_FONT, name_full);			
		}
		else
		{			
			// Get a Y center based on two lines (first name, last name).
			y_pos = dc_center_string_y(SELECT_Y_BASE, name_last, FONT_Y * 2);

			// Get first name string and center x position.
			name_first = strleft(name_full, strlength(name_full) - strlength(name_last));
			x_pos = dc_center_string_x(x_base, name_first, WAIT_NAME_FONT);

			drawstring(x_pos, y_pos, WAIT_NAME_FONT, name_first);
			//drawstringtoscreen(screen, x_pos, y_pos, WAIT_NAME_FONT, name_first);

			// Remove sapce character from last name.
			name_last = strright(name_last, 1);

			x_pos = dc_center_string_x(x_base, name_last, WAIT_NAME_FONT);

			// Add vertical font space.
			y_pos += FONT_Y;

			drawstring(x_pos, y_pos, WAIT_NAME_FONT, name_last);
			//drawstringtoscreen(screen, x_pos, y_pos, WAIT_NAME_FONT, name_last);

			screen_width = strwidth(name_first, WAIT_NAME_FONT);
			screen_height = FONT_Y;
		}

		//string_width = 20;
		//log("\n str w(" + i +"): +" + screen_width);
		//screen = dc_get_screen(i, screen_width, screen_height);
		//dc_draw_text_screen(screen, screen_scale_x, screen_scale_y);
	}

#undef SELECT_NAME_FONT
#undef SELECT_NAME_FONT_Y
#undef SELECT_Y_BASE
}

DC
 
Last edited:
Great, You think it could be done using very compact code  to actually move on the grid and change the name ? I mean if You want to have name change for players and maybe for some ingame things you will find, you dont have to create two sets of files  as it would use one array for naming players or other stuff like npcs/animals.
There were various different asthetic methods of changing name in games.I think most of them did not show lifebars and took place on separate sreen just for this.
At first i thought id want it to be done on actual name spot above the lifebar during gameplay when its paused  or kinda like when you input your initials in hall of fame in arcade games.It would show text above player's head, or just simply change name and show letters where your name is supposed to be, starting from A and ending on END
Fullscreen grid with all the letters and maybe bg graphics would look nice, also sound when changing letters, maybe beep, beep2 or custom.
1gd3s5qp2dc11.png
PowerFest94NameEntry.png
7-capture_008_17072012_205130.png
2-name.png
58283-ca6bd170b705897bed90088d0df74750.jpg
4038.jpg
 
bWWd said:

bWWd when I say array, I'm referring to a static array that holds your character choices, which are then displayed on the grid for selection. Let's say you want the characters in a qwerty layout. The array would be something like this...

Code:
Array(0, 'Q')
Array(1, 'W')
Array(2, 'E')
...

If you want an alphabetical order, just swap out the characters in array and it's done.

By doing this, a character in the grid doesn't even have to be a single character. You could do also have something like this in it and configure the script to act accordingly:

Code:
...
Array(31, 'Space')
Array(32, 'Del')
Array(33, 'Finish')
...

But so far as functionality goes, my system doesn't do anything on its own other than build and output a string from the characters as user selects them.

Your scripts will take the completed string and go from there. Changing names, high scoring entry, or whatever else.

DC
 
YEah, and that second part is something id like to make very compact and universal so i dont have to copy multiple files to make it work.
 
O Ilusionista, #define doesn't use any resources at all, but I #undefine just to make sure there aren't any conflicts downstream.

DC
 
Whats the script command to remove one letter from string ? Last one.
For example i have p1name globalvar that keeps name , id like to remove last letter, kinda like delete key.
Any ideas ?
 
There isn't any such command. You have to very carefully work it out with length and string portion functions like left.

Dc
 
strlength(str) - 1 maybe combine with
strleft(STRING, INDEX):
But it will require to account for all lengths, and i need it for every letter, that will make the script long
-

ok that works
Code:
setglobalvar ("p1name", strleft(p1name, strlength(p1name) - 1));

but i need to figure out something from removing even last letter
-- solved it
Code:
if(Cframe==202 && del && strlength(p1name) > 1) { setglobalvar ("p1name", strleft(p1name, strlength(p1name) - 1));updateframe(self,101);}
 
Back
Top Bottom