Characters and Words Tool

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
NinjaKat_
Posts: 2
Joined: June 11th, 2017, 4:45 pm

Characters and Words Tool

Post by NinjaKat_ » June 20th, 2017, 2:45 pm

Before I begin, if, by the time you finish reading you want to download the package, get "characters2.zip" as that is the updated version.

How to Install
Download the "characters2.zip" file and place the "characters.h" and "characters.cpp" files contained within inside the "engine" folder of the project you wish to implement this in. The remaining two files are external tools that will be explained later. Now simply create an object for the "characters.h" file and initialize it by passing in the graphics object.

Function Usage and Syntax
There are two functions that are added in by the "characters.h" file, those are "scribe()" and "word_scribe()".

The Scribe Function
This function allows you to draw individual characters onto the screen. The syntax is as follows:
[object name].scribe([charCode], x, y, [color], [scalar]);
  • charCode: The numerical index of the character (index can be found at the bottom of post).
  • color: Kind of self-explanatory, the color of the entire character.
  • scalar: The scaling factor for the character (eg. 2, 3, 4) as the original size is a puny 5px x 5px.
The Word_Scribe Function
This function allows you to draw entire words at a time onto the screen. The syntax is as follows:
[object name].word_scribe([wordCode], x, y, color, scalar, [gap], [length]);
  • wordCode: The numerical index of the word (more on this in the "external tools" section).
  • gap: The spacing, in pixels, between characters in the word.
  • length: The length of the word (eg. hello = 5).
External Tools
The two other files in the package are external tools that can be used to make your own custom fonts and add words to the word list for usage with "word_scribe()". Double-clicking either will cause them to open in your preferred browser.

charmaker.html
This tool enables you to create your own fonts (albeit limited to a 5x5 grid so I don't see a lot of deviation possible here). You can click on a square in the grid to add a pixel there and right-click to remove it. After you're done creating an image for a character simply click "Add or Edit". The character menu allows you to choose which character you are adding/editing. When you're done with everything, click "Process" and copy the code that appears in the textbox. Paste this code into the "characters.h" file underneath "//Charset Goes Here:", making sure to replace any preexisting charset code.

wordmaker.html
This tool creates a word list (found in "characters.h" underneath the charset) which is necessary if you wish to use the "word_scribe" function. A word may only be added once to the word list. Once you are done with the word list, click "Compile" and the program will automatically output an array ready-for-use. Copy this and paste it underneath "//Word List:", making sure to replace any preexisting code. Now, if you wish to use "word_scribe", keep in mind that each sub-array in the "words" array is an individual word. It's index is the aforementioned "wordCode".

Character Code Index
Spoiler:
  • A: 0
  • B: 1
  • C: 2
  • ...
  • Z: 25
  • 1: 26
  • 2: 27
  • ...
  • 0: 35
  • (.): 36
  • (?): 37
  • (!): 38
  • (-): 39
  • (_): 40
  • (+): 41
  • ('): 42
  • (/): 43
  • (\): 44
  • ("): 45
  • (:): 46
  • ((): 47
  • ()): 48
Final Notes
I'm not entirely satisfied with the package so I might continue updating it. Moreover, I will listen to any suggestions and will try to respond to them promptly. Thanks.

-NinjaKat_
Attachments
characters2.zip
This is the latest version.
(5.64 KiB) Downloaded 108 times
Last edited by NinjaKat_ on June 26th, 2017, 5:46 am, edited 4 times in total.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Easy Characters and Words w/ Custom Font

Post by albinopapa » June 20th, 2017, 6:14 pm

I suppose you should also mention that the: int words[ 0 ][ 0 ] = {};
needs to be changed to account for how many words are in the word list array and the length of each word in the word list array.

As for the constructor, I'm assuming you want to be able to store a reference to the Graphics object.

Code: Select all

class characters
{
public:
	// First you need to create a constructor that takes in the reference or pointer
	characters( Graphics &Gfx );
private:
	// You also need to store the reference
	Graphics &gfx;
};

// character.cpp
// Now you must initialize the member reference in the constructor
character::character( Graphics &Gfx )
	:
	gfx( Gfx )
{}

You can do the same using a pointer to the Graphics object instead of a reference. The downside to using a reference is you can't have a default constructor "character() = default" since references have to be initialized when created...they can't be changed later. If users use this anywhere that has the Graphics object ( gfx ), then there's no problem. I think passing it in to the function the way it is though, is fine.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

NinjaKat_
Posts: 2
Joined: June 11th, 2017, 4:45 pm

Re: Easy Characters and Words w/ Custom Font

Post by NinjaKat_ » June 20th, 2017, 7:36 pm

albinopapa wrote:I suppose you should also mention that the: int words[ 0 ][ 0 ] = {};
needs to be changed to account for how many words are in the word list array and the length of each word in the word list array.

As for the constructor, I'm assuming you want to be able to store a reference to the Graphics object.

Code: Select all

class characters
{
public:
	// First you need to create a constructor that takes in the reference or pointer
	characters( Graphics &Gfx );
private:
	// You also need to store the reference
	Graphics &gfx;
};

// character.cpp
// Now you must initialize the member reference in the constructor
character::character( Graphics &Gfx )
	:
	gfx( Gfx )
{}

You can do the same using a pointer to the Graphics object instead of a reference. The downside to using a reference is you can't have a default constructor "character() = default" since references have to be initialized when created...they can't be changed later. If users use this anywhere that has the Graphics object ( gfx ), then there's no problem. I think passing it in to the function the way it is though, is fine.
Thanks a lot. I've tried a couple of things and I got pretty close to figuring it out myself if it weren't for the fact that I forgot that you can't make a copy of gfx. So my object was "Graphics gfx" instead of "Graphics& gfx". I'll update the original post.

-NinjaKat_

Post Reply