Sunday, February 27, 2011

Tile Based Games

If you looked at a collection of 2D games, how many of them do you think would use a tile based system for drawing their environments? I'm going to hazard a random guess and say, "lots". So, if this is pretty standard stuff, why re-invent the wheel? Well recently, one of my awesome students pointed out a pretty fantastic tool and code library to me that does tiled maps -quite- well. I like enough that I'd probably use it in any of my own 2D projects, and would recommend it to anyone else.

The Tiled map editor in action, incredibly simple, incredibly powerful.

The map editor, Tiled, does everything it needs to, and nothing really more. It works with multiple layers of tiles, as well as simple object layers for placing objects that don't quite qualify as tiles. You can attach your own custom properties to any tile, layer or map in your project, so that you don't actually need any other editor to design your project in.

The designer allows you to fill areas with a paint bucket, as well as select multiple tiles to place simultaneously, a pair of features that greatly increase work speed for designing your maps. Hotkeys are provided for all commands, so with a little bit of practice, you should be able to iterate through map designs in minutes!

Also, did I mention that their undo history is killer? It really is, give it a try =D For documentation on the application, check out their wiki.

Integration with XNA

The editor by itself is fantastic, but half the problem is getting the stuff from the editor to the screen. Fortunately for everyone involved, a fellow by the name of Gareth Williams wrote a fairly friendly framework for loading/displaying/working with files generated from Tiled in XNA 4.0.

While I have not spent extensive amounts of time with this framework yet, a cursory glance reveals some pretty cool things, and some fairly solid code. Even better is that large parts of his code are based on widely popular and easily accessible tutorials. He's also quite amiable to the idea of other people using this code too, which is always a plus. Here's a link to the relevant posts from his blog. I strongly recommend at least checking it out, it could save you a world of time!


Tiled editor
Tiled editor Wiki page

Gareth Williams Tile Engine
Game State Management Sample (used in the Tile Engine)
Nick Gravelyn's commentary on TiledLib, and TiledLib itself (also used in the Tile Engine)

Monday, February 21, 2011

Chrome OS Review

Alright! So just recently, Google gave me a netbook! Pretty fantastic, right? I love these guys... So anyhow, I've been using it for a week or two now, and I think it's high time for me to have come up with some opinions about it~


I'm going to touch on hardware first, as that's a reasonably good introduction to the device. First! Some specs:

Processor: Intel Atom @ 1.66 GHz
RAM:       2GB DDR3
HD:        16 GB Solid state drive
Screen:    1280x800
Graphics:  integrated

So keep in mind that this device is not the biggest powerhouse on the block. The casing itself though feels quite spiffy, the matte rubber coating on it feels great, and the mouse pad is almost as good as my Macbook Pro's.

The device is quite small, 12", completely dwarfed by my 23" monitor in the background


The idea behind the operating system is to live completely on "the cloud", this magical location somehow made up of Internet, and honestly, I don't think Google could have timed it better. At this point, most of us are getting pretty used to doing things online, especially with the rise of Facebook as a platform for so much of our social data, and Dropbox for storing our files across multiple computers. What I'm trying to say is that living on the cloud completely isn't all that far-fetched.

Good things

I just want to say, the way I work on my computers in general has already changed, even after only a mere few weeks. I find myself relying far more on web based applications, especially for quick or simple tasks. It's hard to beat the convenience of having your workspace in a web tab, right next to your research information, and the site you're going to put your work on. I've also spent a fair bit more time on Google Docs, which really is quite delightful, especially with all of their recent changes.

If you've used Chrome on your desktop computer, you should have a collection of bookmarks, web apps, settings, and user preference data, and if you've set it up right, that data should be associated with your Google account. All of that data gets transfered over to the ChromeOS, and is constantly synced between whatever devices you have running chrome. Not having to worry about transferring data between computers allows the ChromeOS to fall perfectly into a support role for your main computer.

The interface to the OS is incredibly simple, and rather intuitive. It literally is almost exclusively your web browser. If you've used Chrome, you've already seen the interface. If you haven't, then you should, Chrome is a great browser =D The OS also has some pop-up tabs for things such as a download browser and gTalk windows, which are incredibly convenient, and rather unobtrusive.

One of my biggest apprehensions about using ChromeOS was not being able to code. I'm a coder, and I can't do without it. But I quickly found that it's not that hard to do web development online. There are plenty of web based web development tools, and even a few web based compilers that will compile applications in a wide range of different languages(Ideone is pretty nice). They might have to lean a little on the simple side, console windows, fixed input and the like, but it's definitely a start. Just the other day, I found myself writing code in a web window on my main computer, even though I had a couple copies of Visual Studio up in the background. I was pretty surprised.

Also, Teminal window! (Ctrl + Alt + t)

Bad things

Lets start with some simple things, like renaming files. While working on the cloud is great and all, files will eventually end up on your computer in some fashion or another, whether it be uploading pictures from SD card, or downloading from Google Docs to upload back into a class file submission, you still need to work with files. I'm OK with that, and they do have a file browser and all that fun stuff, but you can't rename files. Pretty simple, but important.

Chrome allows for multiple windows, each with multiple tabs. I think its pretty great, but each of these windows is fullscreen, so there's no way to drag tabs between windows. It would be nice to be able to right click on a tab and say 'move over one window' or some such. Google also doesn't do the standard alt+tab that Windows does, it merely rotates through, rather than switching between the most important windows first. There's a reason why Microsoft does it the way they do, and Google should pay attention in this case.

Plugins! Flash is built in, that's cool... but the web runs on more than Flash these days! For example, Silverlight. ChromeOS is built on top of Linux, and there is a Linux plugin for Silverlight out there. ChromeOS can't install or run it though. Same goes for Java, doesn't work. That's a bit of a big problem.

HURG @.@ THIS THING IS SLOW. Can't play video well, can't play games without lag... I hate integrated graphics chips... General use is quite fine otherwise. (Gawker doesn't count anymore, they just screwed up)

Also, Terminal window was nerfed :'(


Overall, I rather like the ChromeOS, and I really believe it's the future. The problems that I've pointed out so far are small details easily fixed by a quick patch, and the good parts really shine through to make the experience quite great. I'm not ditching my Windows 7 yet though we've still got a long ways to go... but it sure does make a great support computer in the meantime!

Tuesday, February 15, 2011

Programming Side Effects

Alright, so it's not often I actually benefit from programming classes, but every once in a while, a teacher sparks off an idea. Today that idea was side effects! This is a concept related to style and modularity, as well as a little bit of math.

Traditionally in math, when you call a function, you get a value back, f(x) = y. Going further, these results should be communicative, f(x) + g(x) = y and g(x) + f(x) = y. In programming however, this is not the case. All sorts of additional values can come in and contaminate the purity of the math based idea of functions, global variables like time and random seeds, and nearby variables that track the internal state of a class. All of these affecting values are called "Side Effects".

Here's a quick example:

#include <stdio.h>

int a = 0;

int Func1()
 a += 2;
 return a;
int Func2()
 a *= 4;
 return a;

int main()
 printf("%d\n", Func1() + Func2() );
 printf("%d\n", Func2() + Func1() );

In this case, you can easily see the side effect variable 'a', which completely destroys the predictability of the code. The problem is, this functionality is incredibly important to larger more complicated programs, which is why large amounts of effort is expended to do such things safely. This results in properties, get/set methods, and all manner of other things.

So it's something to think about when coding and to avoid if you can. It may even be a good thing to mark them down and keep track of in the comment docs, so you know which functions are less likely to be causing issues.

Just some food for thought =D

Sunday, February 06, 2011

Scene graphs vs. regular lists

When I first got into game development, I used simple lists to hold everything in my game. It worked out quite well, it was simple, and it wasn't overly complicated. But like any programmer, I have an insatiable desire to improve my code, to make things more powerful and flexible. It didn't take me long to find out about scene graphs, which is a remarkably intuitive and powerful way to store my game objects.

In case you aren't familiar with the idea of the scene graph, I highly recommend looking into it, even if you ultimately end up not using it, it's a good thing to at the very least consider.

An example of a simple scene graph, illustrating a child/parent relationship for position and more

However, I recently encountered the Unity editor, learned it, and worked with it extensively, and discovered that they don't seem to use a scene graph. The only parent/child relationships going on appeared to be done primarily through the transform components exclusively.

Now I thought this was a pretty intriguing idea, and with my recent focus on extreme simplicity in coding, I thought, "Well why not? A scene graph does make things more complicated and difficult to search through..." and the train suddenly left the station. What if I returned to using a simple list to represent my scenes?

Returning to the earliest example of a scene graph that I had seen, Morrowind, I suddenly realized something. Morrowind is a huge game, having to represent seamless landscapes that cover large amounts of land. Fitting all that data into a single list is impossible, and more or less has to be stored in a hierarchical fashion to facilitate loading.

Now, while I would love to make games on the scale of Morrowind, as an independent hobbyist developer, I don't. Mine are extremely small levels that are easily represented by a basic list, isn't a scene graph overkill? I think it is.

I'm working on a 2D framework for ImagineCup 2011, and have already started implementing this idea. I guess we'll see how it goes =D