Sunday, 18 April 2010

The Wheels are Turning

One week later, and I've started the third tutorial on 2D collision detection on the XNA Creators Club website, this time with transformed object.  Things have been cranked up a notch, as I've just bailed out (for a blog post and dinner) at the point where rotation matrices were mentioned.  They shouldn't be a problem for me in theory, but it's been a while since I used matrices at all.  Some brain spring-cleaning might be in order, to get rid of the cobwebs.

So far I now have a separate Block class, created via a right-click, which leads me to believe that Visual Studio will make me an incredibly lazy programmer.  Some more interesting objects have replaced the falling triangles, they rotate around their central point, and some ugly pop out when they reached the bottom of the screen has been fixed.

However, given that the background should only be red when the player avatar when he collides with a falling object, the screenshot on this post shows all is not well in my borrowed gaming epic.  The next part will resolve said issues, thanks to lovely matrix stuff, apparently.

As an aside, there was another bug in the code you are asked to paste in, which given that earlier the tutorial asked you to correct that exact same error is somewhat bizarre. Either it was another test or the author doesn't test his/her code.

Sunday, 11 April 2010

When Pixels Collide

I've gone through the second XNA tutorial on collision detection, this time with the collision detection on a per-pixel basis rather than just crude rectangles.  It uses the information from each pixel of the two images and then compares their pixel by looping through the arrays, ignoring magenta as a transparency key.

I made a small modification to the code in the tutorial, whereby I first decide if the rectangles bounding the two images overlap, as per the first tutorial, and then only do the pixel-by-pixel basis stuff if they do, as presumably the pixel-by-pixel stuff is more CPU-intensive.  I'm not actually sure that my way is faster though, as it's pretty quick either way.

As an aside, I tried to rename the Visual Studio project to something more generic than the original 'RectangleCollision', and for some bizarre reason renaming seems to take far too much effort if you want it also to change the project directory, etc.  I expected that Visual Studio would have an easy way to do this, but many of the file paths are greyed out so you can't change them directly, and at the same time there doesn't seem to be an obvious way to change them all at once.  A rather strange oversight, and an example of why I don't always like Visual Studio.  At least with your own makefiles, etc. it is very easy to change the paths quickly if you want to move/rename the project folder, especially if you specify file paths in a relative way.  Maybe I'm missing something here.

Saturday, 10 April 2010

Level up!

Two years and a nice shiny (well, lime green) Dell Studio 15 later, and I'm back on the game-making hobbyist horse.  I'm unencumbered by Apple, just after everyone else has started developing iPhone apps.

At first I was going to go for a free 'middleware' solution, such Adventure Game Studio (AGS) which broadly would do everything I would want for the kind of game I want to make.  At the same time I thought I would take a look at XNA Studio, especially given that I now use C# in my job, and ideally would like to improve my profiency with it.  Given that AGS now seems a little dated, I eventually chose XNA as my weapon of choice, especially given that it will hopefully improve my programming skills too.

Within the hour I was able to have a little game up and running, although admittedly I did little more than cut and paste from a tutorial, and I've only gone through the first part of the tutorial so far.  Rather strangely, the tutorial code contained an error, but anyone with an ounce of previous programming experience could fix it within a few seconds.  All told, it's already better than my Pong clone made all that time ago, simply because XNA provides much better support for accessing the graphics and input capabilities of my laptop than Java ever did, and brilliantly it also comes with some simple built-in collision detection routines.  A promising start.