Tag: software

Always Deliver to the Software Specification

As programmers and system designers, we want our time to be spent well and our products to be well received. Nobody likes to spend weeks of their life coding a system that ends up being hated and unused. But hey, you were likely paid for that work, so what does it matter? Well, unless you reflect on what exactly caused that scenario, the situation will probably repeat itself in the next project or another one down the road.

Of course, maybe it wasn’t directly your fault. Maybe you were constantly distracted by that guy who screams into his phone a few cubicles over. Maybe your boss constantly forgets his passwords and thought the best person to bother was you. Maybe the other developers decided that the coding standards were beneath them and made peer reviews a living nightmare. Or maybe the software specification just sucked straight from the beginning. Sometimes these things happen and become unavoidable or at least difficult to avoid. But never, ever, let a product suffer as a result of not delivering to the specification; no matter how bad it sucks.

“But it was just that awful! There was no punctuation, and the writer decided to write the entire thing in Ye Olde English.” you shout. OK, wow, that’s pretty bad. But why weren’t these things brought up during the specification review and sign-off? I guess someone up top thought it was well written and chock full of good ideas. If it somehow managed to pass through the stakeholders and into your hands, then there’s not much you can do except leave the company or do your best to implement the funny jokes generator that slipped in from someone in management at the last minute.

Now, that doesn’t mean the specification can’t be improved. You can certainly bring things to the stakeholders’ attention for post-sign-off review. Perhaps you don’t know the subtle distinction between thou and thee which seems to be sprinkled everywhere in Ye Olde Specification. This approach to specification review is quite common, because things will inevitably surface during development that you didn’t expect. This path leads to happiness and sanity.

But sometimes, we programmers get that creative spark, that hint of artistic genius, our Van Gogh moment. Ignore it. Don’t let your imagination get the better of what you should actually be doing which is delivering to the specification. I’ve had the displeasure of working with someone (we’ll call him Rembrandt) who constantly wasted time implementing features that no one asked for. And you know what, some of the features were really awesome. Rembrandt had some genuinely good ideas. Rembrandt also caused the ship dates to constantly slip because he was never finished with the agreed upon tasks.

Therein lies the lesson. Don’t create features that aren’t explicitly stated in the specification. I know it’s hard to ignore that nagging voice in your head that says, “It will only take a little more time to add this other feature!” In reality, it probably wouldn’t take much time to add useful little features.… Read more

How to load a map from Tiled Map Editor and render it with SDL2

I recently created a library named SharpTiles that is heavily based on Nick Gravelyn’s TiledLib. Both libraries will allow developers to load maps from Tiled Map Editor. However, TiledLib is based around XNA while SharpTiles is based around SharpDL (an XNA-like game framework for SDL2). I will discuss more about SharpDL in another post, but you can refer to the simple code in this post to learn how to render a map with a small subset of the library.

Load a Map

  • Window is a SharpDL object that represents a SDL_Window
  • Renderer is a SharpDL object that represents a SDL_Renderer
  • TiledMap is the main object that you will use to load a map file
// create an SDL window at position 100,100 with size 640x480
Window window = new Window("Example 1", 100, 100, 640, 480, Window.WindowFlags.Shown)

// create an SDL rendering context based on the window above
Renderer renderer = new Renderer(Renderer.RendererFlags.RendererAccelerated);

// load and create map to be displayed in the passed Renderer
TiledMap map = new TiledMap("Maps/Map1.tmx", Renderer);

Draw a Map

You can draw a map by looping through all TileLayers (layers which containd textured tiles) and all Tiles within the layers. Make sure to check if the tile is empty before drawing it. Tiled Map Editor will create empty tiles in spots that contain no textured tiles within the layer.

  • Texture is the tileset that contains the tile’s texture
  • Position.X is the X position of the tile to draw
  • Position.Y is the Y position of the tile to draw
  • SourceTextureBounds is a rectangle that indicates where in the tileset the tile’s actual texture is contained
foreach (TileLayer tileLayer in map.TileLayers)
    foreach (Tile tile in tileLayer.Tiles)
        if (!tile.IsEmpty)
            Renderer.RenderTexture(tile.Texture, (int)tile.Position.X, (int)tile.Position.Y, tile.SourceTextureBounds);
Read more

Some Useful git Commands

git status
shows pending changes that can be added to repo

git add -A
adds all pending changed files to pending commit list

git commit -a -m “Message”
commits all pending additions to the current branch with a message of “Message”

git push
pushes current branch to default remote

git push {branch name} {remote repo name}
pushes {branch name} changes to {remote repo name}

git reset {file name}
resets a file back to previous state after adding to pending commit list

git branch {branch name}
creates a branch named {branch name}

git checkout {branch name}
switches to a branch named {branch name}

git checkout -b {branch name}
creates and switches to a branch named {branch name}

git remote add {remote repo name} {remote repo uri}
adds a reference to a remote repo that can be pushed to… Read more

Read about My Game: The Chains of Acadia

I have been developing software professionally for about 5 years now, and I have been playing video games nearly my entire life. The combination of the two is something that I decided to tackle back in July of this year. Having never programmed for anything other than enterprise software, I decided to ease my way into the scene via XNA. I was already familiar with C# through my work, so it was an obvious choice to learn the basics and dip my toes into the ocean of game design.

Since I am a full-time employee, I usually only get nights and weekends to work on this project. I would love to dedicate all my time to the development of my first game, but I am constantly reminded that something has to pay the bills. Anyway, you did not come here to read about my life; you came to read about my game! I have quickly learned that game development calls for many different talents. Some of the requirements include skills that I simply do not possess. Namely, I have trouble producing quality art, sound, and music. Since I am in this alone (for now), I have to rely on the wonderful open source community to fill this important gap. I can handle the technical side no problem, but when it comes to art, yikes. Without further ado, here is my game.

The Chains of Acadia is a story of a hero. Oh, wow, how original. The thing is though, Acadia (the hero), does not know that he is a hero. When he finds out the truth, he probably will not want the status bestowed upon him. I do not want to ruin the story, so I will stop there and simply explain the style of play involved. The best way to describe the style is to picture Smash TV mixed with a slight bit of Touhou and some minor RPG elements.

Take this image from my Twitter account for example. You can see that the player is constricted on four sides by the walls of the screen. Not every screen will have this type of layout, but it will be the most common. The player has to complete several waves and challenges to proceed to the next screen. Remember in Zelda dungeons when going through a door would slide the camera to the next screen? This is similar.

Screens (maps) will make up a larger “level” that the player can explore to complete challenges, events, and puzzles. Unlike Smash TV, I want the player to have to return to certain screens for one reason or another. Maybe to pick up an item that was not available the first time around. Maybe there is a locked door that can only be opened by pushing a button or retrieving a key in another map. In order to add some fun to the mix, I have implemented a system that generates bullet patterns reminiscent of the Touhou series of games. This allows me to create some really cool challenges that the player must navigate through while attempting to destroy waves of enemies, defeat boss battles, or complete puzzles.… Read more

Quirks with XNA ContentManager Load and Unload

I was recently experimenting with game state transitions and attempting to unload content when a screen was no longer needed. For example, I had a main menu screen which loaded assets to its own ContentManager on activation and unloaded the content when the screen transitioned off based on user input. This all worked fine until the main menu was asked to transition back on after the user was done playing the game.

What I found is that calling the ContentManager’s Unload method will call the Dispose method of all the resources for which it is responsible. You do not and should not manually call the Dispose method for content that has been loaded. However, a problem arises when you want to reuse something that has been unloaded without reinitializing the ContentManager. Even worse, the problem arises even if you call the Load method for a piece of content after it has been Unloaded.

For example:

Texture2D texture = content.Load<Texture2D>("texture");
texture = content.Load<Texture2D>("texture");


I received an error on line 7 of the above paste because even though I reloaded the texture, the ContentManager will return the cached version of the already loaded texture (even though you called Unload!). Yes, the cached version is the one that got disposed!… Read more

Build XNA Game Installer: Visual Studio Setup Project

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This is the second article about building an XNA game installer when you are ready to distribute your game to the masses. In the first part, I described how to use the convenient ClickOnce option to build a relatively simple and non-customizable deployment package. If the ClickOnce option is too restrictive for you or simply does not meet your needs then you should refer to this article about using a Setup Project to create a more customizable installation package.

As with most things in life, the Setup Project is not a perfect solution to packaging up and distributing your game. What I find extremely annoying and shortsighted on Microsoft’s part is that the Setup Project will not automatically detect your game content like ClickOnce does. I want to be clear that, in this context, “content” is referring to your compiled content by the Content Pipeline (textures, sounds, other files) and not the “content” of your project as a whole. I will explain how to force the Setup Project to use your game content. Be warned: it is tedious and annoying, but it works..

  1. Open your game solution
  2. Right click solution -> Add -> New Project…
  3. Other Project Types -> Setup and Deployment -> Visual Studio Installer -> Setup Project
  4. Right click the setup project -> Properties
  5. Change the “Configuration” drop down to whatever configuration you want the setup to use (debug/release/etc)
  6. Click “prerequisites”
  7. Make sure these are checked:
    • Microsoft .NET Framework 4 Client Profile (x86 and x64)
    • Microsoft XNA Framework Redistributable 4.0
    • Windows Installer 3.1
  8. Right click the setup project -> View -> File System
  9. In the “Application Folder”, right click -> Add -> Project Output
  10. Change the “Project” drop down to the main game project
  11. Click “Primary” output in the list box
  12. Choose the configuration for which you want to include the output (debug/release/etc)
  13. Repeat steps 9-12 for any other projects that you need to include in the output (custom libraries)
    • NOTE: Do note include output from content pipeline extension projects because the content pipeline it is unavailable at run time

You just created a setup project, told it which prerequisites are needed for your game to work, and finally told it which build output you want to include in the installer. You can arrange the “File System” folders to how you see fit for your application folder hierarchy. For example, you should see options to include files in the User’s Desktop or the User’s Programs Menu in case you want to include shortcuts. Be careful not to abuse this though, because the user will not be happy if you dump 500 files on their desktop!

While that was relatively painless, all is not well in setup project land. For some reason there is no way to have the setup project automatically find your compiled content in .xnb format after the content pipeline has imported and processed your content files. You can include the “Project Output” of the content project, but that will not do anything useful, so do not bother!… Read more

Build XNA Game Installer: ClickOnce

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This article is the first of two on how to package your XNA game into an installer for Windows environments. The first is the easier but less customizable option of using Visual Studio’s built in ClickOnce installer. ClickOnce is essentially a hand-holding tool to package up prerequisites, dependencies, manifests, and content. Additionally, it allows you to specify locations from which the users will install the package (CD, Web, Shared Drive). More conveniently, ClickOnce allows you to specify where the application should check for updates in order to automatically update the content when new versions of the application are released. For example, you could specify a URL that the application will use to check for new versions. If a new version is detected, you can specify either the same URL or a different URL to use for downloading the new content.

While ClickOnce is easy to use, it is not perfect for every scenario and can fail quite spectacularly. I have personally run into situations where users could not install updates to the application because of cryptic errors that were only resolved by completely recreating a user account in Windows (I kid you not, this is a Microsoft-sanctioned approach). Many of the errors are difficult to diagnose and the documentation does not help much when it comes to the more advanced features of ClickOnce. It is definitely convenient, but do not use it if you want customization or extendability.

That said, here is how you use ClickOnce to package your XNA game into an installer.

  1. Open your solution in Visual Studio
  2. Right click your main project -> Properties…
  3. Click Publish tab
    • Publishing Folder: local or remote path that will be the destination of the publish (example: C:DevGamesGame1Installer)
    • Installation Folder URL: optional unless you want the users to install from a location different from the publish location
    • Install Mode: Pick offline availability (users should not have to be connected to the internet to play video games!)
    • Click Application Files…
      • Make sure the Publish Status of your game files is set to Include (Auto)
      • Make sure the Publish Status of the XNA libraries is set to Prerequisite (Auto)
    • Click Prerequisites…
      • Microsoft .NET Framework 4 Client Profile
      • Microsoft XNA Framework Redistributable 4.0
      • Windows Installer 3.1
    • Click Updates…
      • Check for updates if you want your application to check for updates through ClickOnce
      • A lot of the options are self explanatory on this screen
    • Click Options…
      • Description tab
        • Publisher name: your company name
        • Suite name: optional used to define a super application that manages this one
        • Product name: the name of your game
      • Deployment tab
        • If you want to deploy to a web page, specify the URL here
        • Check the other options here if need them
      • Manifests
        • Click “Create desktop shortcut” if you want a shortcut
        • Ignore the other options unless you really need them
  4. Specify the version of this publish (you can have it auto increment if you want)
  5. Click either the Publish wizard (which just confirms your already entered information) or Publish Now to begin publish

Your published files will be organized like this:

  • Application Files
    • Contains every version that has been published (in case user needs to rollback to a previous version)
    • Contains “Content” folder which includes files from your Content project in your XNA solution
    • .dll
Read more