Archive for March, 2009

XNA Mouse Input and Handling

Sunday, March 22nd, 2009

This is short tutorial on how I’m handling some of the mouse commands. I’m dumping it here in case some one find it useful:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

static public class InputHandler


Notice the libraries that are included. Only the ones that are strictly necessary. The reason it’s static and public, it’s to allow all other parts of the program access to it. This is handy because it will allow us to control menu selections, and gameplay at the same time without having to initialize the class everywhere. (more…)

Slow progress…

Wednesday, March 11th, 2009

I have been doing a lot of things lately. One of the most interesting was creating a set of screens for game flow:

* Initial Screen
* Options
* Pause
* others

This was done thanks to one of the resources in the XNA (again using code from resources… shame on me). The complexity of it is a bit above my knowledge, so it was a direct copy/paste and I just did some mark up to get it to work with my own code.

I did this because of several reasons. First of all, I really got to clean up the code and outsource everything out of the main class and into a World class. World class controls everything in the game board through function calls on update for each element. The only logic here is on the AI behavior changes (when enemies shoot or dive).

The second reason is because it let me use a Options screen that lets me load and reaload things without having to quit the game. This was when the big eureka moment hit me. After having traced how each screen worked, i noticed that it didnt’ have a way to pass game options from point to point. In other words, any options that I added to the options screen was lost the moment I left the screen.

This posed a problem to my idea of having options for adding enemies and other elements. Of course, this is the whole purpose of the options screen! The solution was rather inspired by my previous work with the Sound class. So I created a public static GameSettings class. Why static? well, the answer is rather simple, it offers me the option to control them and access them from anywhere. When the options are updated in the options screen, they’re read by the World class in the GamplayScreen and taken into account when the game loads.

I like this solutions a lot. I think it’s both elegant and functional. It also led me to create a Level class which can store level options. I can create a array of levels, and then access each level as the game progresses.

I am currently working on a HUD. I just got started on it, so there is no much functionality to it yet. So far I am only drawing a radar and a small marker for where the hero is. I still need to decide how to work the radar in the game. I have 2 options, to display a radius of where things are, or display everything in the playing field. They both have pros and cons. I haven’t decided because I’m still strugling with now I want to make the game work. This is a bad thing at this stage… I really should know where I’m going, but I have become increasingly worried about what it takes to make any type of RTS work (even on the simplest level). I love the idea of the RTS, but it takes more than one person, and I have been doing this all by myself, which makes it extremely difficult.

I think I will be working on a single controlled ship taking a number of enemies very much Galaga style though the AI will be free roaming.

More to work on =)

Finding solutions to problems…

Friday, March 6th, 2009

I have been enjoying my journey through the XNA very much. It all started with a little project to move a sprite around, and now I can control a number of sprites, spawning different behaviors, animations and sounds. It wouldn’t be fair to say that I have done all this entirely on my own. The XNA has a great number of resources that I have tried to take as much advantage of as possible. It is not a bad thing to admit that have copied at lot of source code from the resources when it fits my needs. However, more importantly, I have tried to write my own code as much as possible. I have only copied it when it fits my exact needs, and when I think I can learn more from copying it, than from writing my own.