XNA Tutorial Part 1

Source: thriftynerd.com

by Jonathan Sescon

XNA is a very simple-to-use game development framework for Windows and Xbox 360. It mainly uses C#, an object oriented language influenced by both Java and C++. According to Wikipedia, some popular games which use XNA are the tunnel digging Terraria, the sexily narrated RPG Bastion, the dimension-shifting Fez and the beat ‘m up The Dishwasher series.

And the student-created charity game Wildfire, created by By Implication, composed of members from UP and Ateneo. These students entered Wildfire into the Microsoft Imagine Cup Competition and won 1st place in the World Finals. Now they work in their own game development studio.

As you can see, XNA is mostly targeted to indie developers. Indie is the new buzzword these days. Indie music. Indie films. Indie games like Braid, Angry Birds, Fruit Ninja, etc. Indie means independent, which means that resources are smaller. XNA is built to minimize low-level digging in the code. Simply put, think of it as digging with a Caterpillar backhoe instead of digging with a shovel.

First of all, I will not teach you C# in this tutorial. Most of you Wildcard readers were probably once enrolled in a CS21a class in Ateneo. Even though CS21a teaches Java, C# is a lot like Java. I will assume that you are confident enough to tread these waters; however, I will always provide some help for you Java developers. If you did not take CS21a or you want to have a better grasp with C#, read a tutorial from the internet. The Microsoft Developer Network (MSDN) is a good starting place, since your life with anything developed under MS will pretty much depend on it.

For this tutorial, we will create a very simple 2D game in which the avatar moves and detects collisions; however, I won’t go into a lot of details. If you want to learn more, then either read more tutorials from the internet or make a game by yourself and consult MSDN whenever you have a compilation or runtime error or you don’t know what syntax to use. All-in-all, the best advice can be summarized in two words:

START NOW.

If you need a nice version of Visual Studio and Windows, ask some of your Microsoft Student Partners or go to the technicians’ office in Faura 225. If you don’t want any hassle and you already have a Windows machine, just download Visual C# 2010 Express Edition and XNA 4.0. Here are the links:

Visual Studio C# Express – http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express

XNA 4.0 – http://www.microsoft.com/en-us/download/details.aspx?id=23714

If you have Visual Studio and XNA already installed on Windows, open Visual Studio, then select New Project in the Start Page. Within the templates box, choose Visual Studio, then XNA Game Studio. For this tutorial, we will be creating a Windows Game, since I believe that not all of you have at least one Xbox. Select Windows Game, and then enter a name for the project. Note: the name of the project does not necessarily mean that it will be the name of the final game. Click OK.

Immediately, you see that code is already written. Those methods that Visual Studio has written for you will be the core of the game. You will use them a lot.

The code looks so much like Java, right? Yes it does, with some minor differences, like List is C#’s ArrayList and accessing an element in List is done regular Java array style (i.e. myList[0] in C# is like myList.get(0) in Java). Also, the capitalization rules are quite different from what CS21a has taught you, since we will follow MS’s guidelines. All public methods and variables should be capitalized while private methods and variables should be in lowercase. All class names will still be capitalized, however. Again, if you want a better command of C#, please take a look at other tutorials.

Stay tuned here in Wildcard for Part 2!


Read more articles

Comments