__Defense

Screenshot of __Defense

__Defense is a futuristic tower defense game written in C# using XNA/MonoGame. It’s rendered in 3D, though the gameplay occurs on a 2D plane. It’s a complete game experience from start to finish, though there are only a couple of types of tower and one type of enemy. But it’s a good starting point for the game, and should give many ideas on how algorithms covered in the book can be implemented.

There is a lot more detail on this project and how the source code is laid out in Chapter 14 of the book. This code is very much designed to be studied with the book as a companion, so it may be a little difficult to follow if you try to just dive into it.

Binary Download

If you don’t want to deal with building the code and just see what the game’s like, you can download the Windows binary here.

Note that this is built with XNA, so if you aren’t able to run it, you may need to download the XNA 4.0 Redistributable.

Source Download

The full source code is available on GitHub here. If you’re unfamiliar with the concept of source control, be sure to read the section on it in Appendix B of the book.

If you don’t have Git installed, and don’t want to mess with a client, you can also download the code in zip form.

There are three different solution files: one for XNA (Windows), MonoGame (Windows), and one for MonoGame (Mac). All three solutions use almost all of the same code files — there is only one feature that’s in the XNA version and not the MonoGame version, and that’s the glow post-process effect.

One thing to note if you plan on changing some of the content (such as the sounds, textures, and models) is that the MonoGame solutions currently do not support building the content. So you have to build the content through the XNA solution, which will then automatically copy the content into the directories that MonoGame uses.

In any event, depending on which one you want to build, the instructions are different.

Build Instructions

XNA (Windows)

The XNA solution is defense-xna.sln. This is the “best” version because it has a glow post-process effect that the MonoGame version does not. To build this version, you need to install the following:

  1. Visual Studio 2010. Students can get this for free at DreamSpark. Otherwise, you can install the free Visual C# Express 2010. XNA does NOT work with any other versions of Visual Studio (such as 2012).
  2. XNA Game Studio 4.0 Refresh

Once you’ve installed both, you should be able to open the solution and build/run without any further steps.

MonoGame (Windows)

If you’d prefer to use the MonoGame for Windows version instead, your solution of choice is defense-mono.sln. In order to build this version, you need to install the following:

  1. Visual Studio 2010 or 2012. Students can download either version at DreamSpark, and as above you can also use the C# Express versions. This solution might also work with MonoDevelop for Windows, but I have not personally tested this.
  2. MonoGame. The project was built on version 3.0.1, but it may also work on any newer versions.

Once those are installed, you should be able to open, build, and run this version without any further steps.

MonoGame (Mac)

If you want to run on a Mac, your only option is defense-mac.sln. The process to get the Mac version running is not as streamlined as the other two platforms. Here are the steps:

  1. Install Mono for Mac.
  2. Install Xamarin Studio. I used version 4.0.9, but it may also work on a newer version.
  3. Download the MonoGame add-in for Xamarin Studio. I used version 3.0.1.
  4. To install the add-in, you have to open up Xamarin Studio and go to the Add-In Manager and point it to your add-in.
  5. Now you can open the solution file. But it may not run because the MonoGame add-in does not properly point to a needed reference.
  6. To fix this click the drop down arrow next to the “References” folder in the Solution browser (on the left side of the Xamarin window).
  7. Right click on MonoGame.Framework and select “Delete.”
  8. Now right click on the “References” folder and select Edit References.
  9. From here, select the “.Net Assembly” tab and browse to the ~/Library/Application Support/XamarinStudio-4.0/LocalInstall/Addins/MonoDevelop.MonoGame.3.0.1/assemblies/MacOS directory.
  10. Once you get to that folder, select MonoGame.Framework.dll and click the “Add” button.

Hopefully, after you do that you will be able to build and run the game on your Mac!

MonoGame (Linux)

I currently do not have a machine with Linux setup on it, so I did not provide a Linux solution file. However, if anyone wants to setup a Linux solution file and put in a pull request on GitHub, I’d be more than happy to accept it.