The Game Crafter News



Designing a Game Programmatically

I while back I talked about how I created Lacuna Expanse: A New Empire programatically. Today, I’m pleased to share with you how another user did it, using a different programming language. The following article was contributed by Alex Wolff (aka Supremacy in chat) of Wolfpack Studios

Designing a Card Game With C#

By Alex Wolff (Wolfpack Studios)

Ever wanted to create games, but weren’t the graphically talented type? Struggle to make stick figures that look like they were drawn by someone over the age of 5? Same here. I’m fairly certain my 3 year old nephew has more artistic talent than I do.

Fortunately, learning to progam can help solve a lot of these issues. Taking advantage of some of the tools in the C# .Net library, mainly System.Drawing, it’s pretty quick and easy to pop out something like a card game.

We can also do this with all completely free software!

The tools that I use are:

Visual C# 2010 Express

Paint.Net (Though Inkscape and GIMP are also options that you can use as well)

Getting Started:

While designing the actual cards programmatically is the end goal, first you will need to design a template using the graphics program of your choice.

Since I used TheGameCrafter to build, design, and publish my game. I’m going to start by using one of their templates. First, I open up the template in Paint.Net and put it on it’s own layer. This way I can start designing the rest without constantly having to check how it fits on the card template, and also to make sure that my finished template is the correct size for upload.

image

Next, I usually add in separate layers for each specific thing that I want to put on the card. These cards are really simple in layout, all they need is a background and some text to be put on them. Putting each piece on a separate layer might seem like more work up front, but if you ever need to make changes, it’s a hell of a lot easier in the long run.

I went with a very simple “terminal” looking background, consisting of green 0’s and 1’s on a black background. This requires absolutely no artwork and still fits the game’s theme. I created a new layer for the black background, filled it in using the Fill tool, and then created a new layer to put my 0’s and 1’s.

image


The 0’s and 1’s were created using the Font tool. I just used Arial font, 12 point. I listened to some music and tapped out random patterns of 0’s and 1’s for a few minutes, then copied and pasted the rest. Just for visual effect I tried not to repeat the same pattern over and over in an obvious way, so I inserted the copy/paste into the middle of itself a few times, and did some overlaying.

Next, per the card design, I wanted to add a layer to show where the card text was going to be. After playtesting and a few different designs, I settled on wanting the text to show on the top and bottom of the card, with a way to distinguish which way the card was being held. This allows the players to adjust to the way they are looking at the game board and makes it much easier for players to see what the numbers on their cards are as they hold them.

image


The final card template looks like

Now that everything is on the template that I want it to be, the next part is to save it off as a PNG file so that it’s something we can reference in our code that the library understands without too much trouble. In Paint.Net this is as easy and doing a Save As and selecting PNG in the format list.

image



Next is the fun part, the programming part… the part you probably started reading this to get to!

While a console application could easily do the job, I prefer to use standard WinForms applications to do my quick and dirty apps. They give me the control of a button, and when it’s something visual it allows me to do a preview before I create the entire batch.

In Visual Studio Express, I created a new Windows Forms Application project for my Bit Shift cards. I only have 2 controls, a button to fire off the card creation (appropriately labeled CREATE STUFF) and a Picture Box that I can use to preview what my final images look like after I’ve manipulated the template.

image



Warning: I’m well aware that my code probably doesn’t follow standard programming guidelines, best practices, and may possibly not make sense to anyone that isn’t me. Regardless, I’m going to show you what I did to get my cards created.

First, I created a reference to the template:

staticImage baseImage { get { returnImage.FromFile(@"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\BitShiftCardTemplate.png"); } }

Then, I needed a method that I would use to create the actual cards in an image based on the template.

staticImage DrawImage(Image baseImage, string textline1)
{
    var newImage = newBitmap(baseImage);
    var graphics = Graphics.FromImage(newImage);
    var line1start = newPointF(100.0f, 162.0f);
    var line2start = newPointF(100.0f, 798.0f);
    var cardFont = newFont("Quartz MS", 114.0f, FontStyle.Regular, GraphicsUnit.Pixel);
    var whiteBrush = Brushes.White;

    graphics.DrawString(textline1, cardFont, whiteBrush, line1start);
    graphics.DrawString(textline1, cardFont, whiteBrush, line2start);

    return newImage;
}

This method will take in a base image (our template), and then write out our card text to it on both the top and the bottom.

Because of certain difficulties with images and how they can be saved/handled, I had to first create a new Bitmap from the base image. Using the Graphics.FromImage method gives me a Graphics object that is what I use to actually manipulate the Bitmap contained on it.

Next I define line1start and line2start as the different PointF objects which are the start points for my lines of text.

Then I need to define the font and size that I want to use. Quartz MS gives me that nice “alarm clock / terminal” feeling, which fits the theme of the game really well, so I went with that.

Note: The sizes of the fonts, and the Point starts did not line up to what I originally tried to do in Paint.Net, so it required a lot of trial and error to get them right. This is one of the reasons that I included a preview on the main screen, so that I could adjust the numbers, run and preview, then adjust them again if something was off.

Since I want my font to be White text on the template, I define my brush using the built-in Brush.White.

The graphics.DrawString method allows me to draw a string directly on the bitmap image contained in the graphics file. Since it updates the Bitmap reference directly, we can then just return the new bitmap that we created. The Graphics library contains a lot of methods that are useful for drawing. You can draw other images, text, ellipses, rectangles. If you’re more artisticly inclined than I am, you could probably get a lot more leverage out of the Graphics library than I can.

Anyway… now that we have a method to put text on our templates, we have to tell the program what text we want and how many cards to create. This is the code for our CREATE STUFF button.

private void btnCreate_Click(object sender, EventArgs e)
{
    //Loop through the numbers and create the images, and then save them
    var savedImagesDirectory = @"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\";

    for (short i = 0; i < 256; i++)
    {
        var numAsBinaryString = GetShortBinaryString(i);
        if (numAsBinaryString.Where(c => c == '0').Count() == 4)
        {
            var newImage = DrawImage(baseImage, numAsBinaryString);
            newImage.Save(savedImagesDirectory + "Bit_Shift_" + i.ToString().PadLeft(3, '0') + ".png", System.Drawing.Imaging.ImageFormat.Png);
        }
    }
}

When clicked, the button will loop through all of the numbers between 0 and 255, get their binary string representation, and then create and save the images in the specified directory, with a name based on the number it represents.

Since it turns out that having 256 cards for all combinations was not only too expensive, but did not really make the game too fun, I trimmed down the automated process to only output numbers that contained 4 0’s and 4 1’s in their binary string. I then further cut them down and tried to remove ones that had all 4 0’s or 4 1’s all in a row.

The Image class contains a Save method that allows you to save it in any of the supported formats.

The following is a function that I found on the Internet that I adapted to meet my needs. It takes a number and converts it to a binary string. The original version was 32 bit, but I only needed 8-bit for my purposes. (While trying to remember where I got it to credit the Author, I found additional articles with much easier ways to do this… but still) Credit to the Author:

static string GetShortBinaryString(short n)
{
    char[] b = newchar[8];
    int pos = 7;
    int i = 0;

    while (i < 8)
    {
        if ((n & (1 << i)) != 0)
        {
            b[pos] = '1';
        }
        else
        {
            b[pos] = '0';
        }
        pos--;
        i++;
    }
    returnnewstring(b);
}

The final piece of the application is to display a preview of the card on the screen before it gets printed. I put this in the form initialization method. I was originally having some troubles so I put in additional debug information into a label on the screen as well.

public frmMain()
{
    InitializeComponent();
    var previewImage = DrawImage(baseImage, "01010101");
    pbxPreview.Image = previewImage;
    pbxPreview.Height = previewImage.Height;
    pbxPreview.Width = previewImage.Width;
    imgInfo.Text = string.Format("Height: {0}, Width: {1}, PhysicalDimHeight: {2}, PhysicalDimWidth: {3}",
    baseImage.Height, baseImage.Width, baseImage.PhysicalDimension.Height, baseImage.PhysicalDimension.Width);
}

When the application loads up, it should load up the template, create an image based on the “01010101” string, and then output it into my Picture Box on the screen to preview. Having the preview was invaluable to getting and tweaking the values for the line1start and line2start values in my DrawImage method.

When the application starts it looks like this: It shows our template with our sample text on it along with some property information. Once it looks good, I know I’m good to click the button.

image



Once the button has been created, the program does its thing and VOILA! Cards.

image



Since I had to recreate the cards a few times based on different template styles, the time it took me to develop the application was nowhere near the time it would have taken me to adjust all of the images every time I wanted to make a template change.

Next step is to upload them to TheGameCrafter and proof them. I’m currently in the process of creating a .Net wrapper around the TheGameCrafter API, but that is a work in progress and has no estimated completion date.

Questions, comments, praise, or other musings can be sent to Wolfpack.Studios.PA@Gmail.com

If you’re interested in Bit Shift, you can find the link to it on TheGameCrafter

By popular demand we’ve uploaded the ICC color profiles we use on our digital presses for your use. Assigning these profiles in your image editor of choice should get you just a small bit closer to having the colors on your screen match the colors that we print.

Please note that due to all kinds of variables outside our control, we still cannot guarantee color matching. We just want to afford you every opportunity to get it as close as possible. 

Game Editor Supports Vimeo

The game editor now supports Vimeo URLs just like it has always supported YouTube URLs. To make use of it, simply add a Vimeo video URL to your Game Description field, like this:

http://vimeo.com/40503001

It will be automatically turned into a video.

Likewise you can now use HTML entities in your descriptions now. So you can display a copyright symbol by using a code such as: &copy; 

Enjoy

We&#8217;re getting very close to releasing the new version of our web site. We recommend uploading a new backdrop and a transparent logo for the new site. As you can see in the photo above, the backdrop is going to be nearly fully exposed in the new site.
If you have not attached a logo to your game by the time we launch the new site your game will be unpublished from the site. Please don&#8217;t let that happen. Just prepare a logo and upload it. Your logo should be a transparent 24-bit png.
We recommend your backdrop be a compressed jpeg to reduce it&#8217;s overall file size.

We’re getting very close to releasing the new version of our web site. We recommend uploading a new backdrop and a transparent logo for the new site. As you can see in the photo above, the backdrop is going to be nearly fully exposed in the new site.

If you have not attached a logo to your game by the time we launch the new site your game will be unpublished from the site. Please don’t let that happen. Just prepare a logo and upload it. Your logo should be a transparent 24-bit png.

We recommend your backdrop be a compressed jpeg to reduce it’s overall file size.

Short Description

We’ve just added a “Short Description” field to all games. This will default to the same thing that is in your “Tag Line” field for now, but you should update it to reflect a one sentence description of your game. The short description will not be used in the current site, but will be used in the new site that we’re working on. 

Say hello to the Flower Mat. These mats are made up of seven, one-inch hexes. Their shape enables you to build out dynamic game boards very quickly at minimal expense. They are printed 20 to a sheet for only 13 cents each. As with all our mats, they are printed on card stock full-bleed and double-sided. 
Download the template and get started today. Enjoy!

Say hello to the Flower Mat. These mats are made up of seven, one-inch hexes. Their shape enables you to build out dynamic game boards very quickly at minimal expense. They are printed 20 to a sheet for only 13 cents each. As with all our mats, they are printed on card stock full-bleed and double-sided. 

Download the template and get started today. Enjoy!

New Site Design Coming Soon

We’ve been hard at work on a new version of our site. We’re still a few weeks away, but we wanted to give you a head start on updating your games to fit with the new site.

You can now attach a logo to your game. It must measure 350 x 150 pixels, and should be uploaded as a transparent PNG. This will be required when the new site goes live, and if your game does not have one at that time, it will be unpublished. 

image

You can also highlight a review given to your game by a professional game reviewer.  These are not required fields.

image

Neither of these options will do anything on the current site. When the new site goes live they’ll become important. 

As we get closer, we’ll give you a sneak peek at the new site. 

Toren and Prax from IcePack Games show off the evolution of one of their games (Joust!) over the years. It’s a must watch.

Site Updates

We’ve just released a number of important site updates that we want to share with you.

First, there is now a My Files tab under the publish section, which will allow you to manipulate your files without editing an existing image. 

Second, when we mark a part as “discontinued”, if you have that part in your game you’ll now be notified about it.

Third, the site will sometimes tell you that you can’t delete a file because it is in use. When viewing the file there is now a section that tells you what is using it and links you directly to that item. For example:

Fourth, there are now three additional color selectors in the parts search: Pink, Grey, and Brown.

Fifth, we’ve separated out Tools from minis in the parts search. This will make it easier to find things like the revolver and wheel barrow. 

Sixth, if you place a Will Call order, you’ll now get an email immediately after it becomes available to pick up.

Enjoy!

Jumbo Card Change

Due to a change in our process Jumbo Cards are now printed 6 to a sheet at $1.25 per sheet, which means the price per card is still 21 cents. They were 9 to a sheet at $1.89. 

Say hello to the Small Pro Box! This is a new line of boxes we’re introducing this year. Pro boxes are made of a thick material, are telescoping, and are a rigid design. The Small Pro Box is large enough for two decks of poker cards or a single deck of jumbo cards, or perhaps a deck of square cards and some game pieces. Both the top and bottom of the box are fully customizable, and you can add the Small Pro Box to your game for $5. Download the template and get started today. Enjoy!

For a while now people have been asking us to expand the available sizes of our mats. They say they need a mat that is just slightly larger or smaller than something we already have. To that end, today we&#8217;re releasing our Half Mat, which is exactly half the size of our Large Square Mat and just an inch wider than our Skinny Mat: 5 x 10 inches. These are printed 3 to a sheet on cardstock for 63 cents each. As you might expect they are full-color, full-bleed, and double-sided just like all our other mats. 
Download the template and get started today. Enjoy!

For a while now people have been asking us to expand the available sizes of our mats. They say they need a mat that is just slightly larger or smaller than something we already have. To that end, today we’re releasing our Half Mat, which is exactly half the size of our Large Square Mat and just an inch wider than our Skinny Mat: 5 x 10 inches. These are printed 3 to a sheet on cardstock for 63 cents each. As you might expect they are full-color, full-bleed, and double-sided just like all our other mats. 

Download the template and get started today. Enjoy!

Even Better Bulk Pricing

About a month ago we released a new bulk pricing system that allowed many games to get up to a 40% discount when purchasing in bulk. However, some games have complex components that are more difficult to mass produce so they might only get around a 20% discount. We’re pleased to announce that the bulk pricing just got better for many additional games, so now even more people should be able to enjoy the benefits of bulk pricing. In our tests, some games that were 20% now are all the way up to a 40% discount! Enjoy!

Introducing Large Square Tiles. They measure 3.5 x 3.5 inches, which are the same size as our Square Cards. They come 12 to a sheet for $6.49 per sheet.
Our tiles are made from chipboard that is 0.06 inches thick (roughly the same as Catan tiles. They are printed in full color and full bleed on one side.
Download the template and get started today. Enjoy!

Introducing Large Square Tiles. They measure 3.5 x 3.5 inches, which are the same size as our Square Cards. They come 12 to a sheet for $6.49 per sheet.

Our tiles are made from chipboard that is 0.06 inches thick (roughly the same as Catan tiles. They are printed in full color and full bleed on one side.

Download the template and get started today. Enjoy!