War In Space Day 1

WarInSpace1

Let’s jump right into the new project, learning about XNA by writing a clone of the classic Space War. First of all, I am aware that there is already the Space War starter kit available by Microsoft themselves. However, the gameplay (especially two players at the same time) fits very well to XNA compared to the other platforms/SDK I want to look into, and I think it’s always very instructive to build something from scratch even if someone else has already done it.

I want to approach this project in an agile fashion, trying to split up the 1 month goal I have set myself into four cycles at the end of which is always a working version of the game. So, this first week is about getting into XNA and getting the rudimentary parts of the gameplay in place.

Setup

The first thing to do when developing in XNA is to decide on which platforms the game will run. The most common choice will be Windows and XBox 360. The way I have decided to set up the project is to have one solution with two projects (Windows and XBox 360), which share the same code (see here for instructions). I have also set up a small “development kit” with my XBox connected to a small monitor standing next to my PC monitor so I can debug and see the output next to each other. One slightly annoying thing is that, even though the windows project is chosen as the startup project, XNA tries to always deploy the project onto the XBox, which fails if the XBox is not connected. Setting up an XBox 360 is described on the XNA Creators Club webpage.

Code

After setting up the projects, the next thing is to add the first code. Reading about XNA, I recognized that a natural way of breaking up the game loop into different parts is the use of GameComponents, which will get updated each frame. I decided to add two of those so far, an HIDGameComponent, responsible for managing input devices, and a RenderGameComponent, which at the moment is responsible for drawing the things on the screen.

The two ships in the game are represented by the Ship class, which at the moment only saves which of the players controls it and it’s position and rotation (both in 2D). The main game component updates the rotation based on the input devices, and the RenderGameComponent uses this information to draw the ships (at the moment, they are only triangles). You see the result in the first screenshot, with one of the “ships” being rotated slightly. Obviously, the next thing to do is to implement a camera so we can put the ships into perspective.

Design

These first steps already made me think about the general architecture design in programming games. Quite often, I find it not straightforward which code should go where. As an example, I currently have the HIDGameComponent return information like the amount of rotation that a player has put in for the ship he/she controls. Therefore, it’s not general purpose anymore, but rather tied to the gameplay. An alternative would be to have the ships themselves make sense of the input, or have another game component which can map general purpose input (e.g. button presses) to the in-game consequences. I think this is one of the points that will get a lot clearer once the game comes together more (after all, this is Day 1…)


Leave a Reply

Your email address will not be published.