Opinion? What's that?
Kryo's first journal...
Published on October 14, 2008 By kryo In PC Gaming

xnaAs many of those reading may be aware (at least those on our games sites), I work offsite. Probably less known though is where; I'm currently studying programming at university, with hopes to move on into Stardock's game development team after I finish my degree.

So anyway, this semester I'm studying C#. As part of this, we're going to have an open project at the end of semester, in which we will make pretty much anything we want, so long as it demonstrates a sufficient skill and knowledge in the language. While the professor is a command-line die-hard, referring to anything with a GUI as "dog and pony show", we have the option to make our projects as fancy as we like.

Toward that end, I had some time this past weekend and figured I'd better try and get a handle on at least getting 2D graphics on-screen in windows programs, beyond the simple form elements that you can drag and drop in Visual Studio. First I looked around for some tutorials on GDI or DirectDraw, but couldn't find anything all that helpful. So I then looked around for some stuff on XNA, and came across this pong clone tutorial.

 

pong1th pong2th
Pong main menu. Pong, with tweaks.

An hour or two of typing and copypasta later, it was done, with at least some portion of it having sunk in. It wasn't without incident, at least, as it seems the tutorial's author (despite best efforts to get it perfected) had left a number of mistakes which I had to correct along the way. Mostly small things, like using one variable name in one section or in the class description, but in the actual code he provided, he used another. Some bugs were significantly less minor though, like reversing the width and height in the part where the maximum "table" dimensions (the area where the ball can roam), such that the poor computer player could never hit the ball, because it disappeared 200 pixels before it reached his paddle.

To ensure that I understood the mechanics of the pong game, I made a few changes and tweaks, such as adding walls and obstacles to the table. Also, I made the player paddle larger and faster

Overall though, I came away from it with one major thought: XNA makes basic game development brutally simple (as programming goes). I had expected to have to deal with more nitty-gritty API stuff, setting up a main loop, dealing with timing, etc. (and will, when I get around to trying and figuring out how do to all this in C++ and DirectX), but XNA completely obscures all of that and any need for more than a general understanding of C# and object-oriented programming. All the "hard" stuff is nicely tucked away in the base classes, which yours can inherit from, and you can literally toss together a (very) simple 2D game in less than a day, from scratch.

Certainly, things will get more complex when you bring 3D into the picture, but short of that, it seems that pretty much any aspiring programmer should be able to get right into XNA with ease.

Back to the development: after finishing the pong tutorial and tinkering around with it for a while, I decided to see if I could put all the pieces to use with making a 2D scrolling shooter, following the same general structure and class hierarchy as used in the pong game (but making improvements and boosting efficiency along the way). That's for another journal, but here are some preview screens to cap this one off:

 

roid1th roid2th
Main menu--look familiar? A lone Drengin fights for his life...

Comments
on Oct 14, 2008

Overall though, I came away from it with one major thought: XNA makes basic game development brutally simple (as programming goes). I had expected to have to deal with more nitty-gritty API stuff, setting up a main loop, dealing with timing, etc. (and will, when I get around to trying and figuring out how do to all this in C++ and DirectX), but XNA completely obscures all of that and any need for more than a general understanding of C# and object-oriented programming. All the "hard" stuff is nicely tucked away in the base classes, which yours can inherit from, and you can literally toss together a (very) simple 2D game in less than a day, from scratch.

You know, I decided to get back into programming a while ago, and picked up a book for Visual Studio. I'm not jumping into game stuff right away, as I had absolutely no experience with any Windows programming (all my past instructors were command line die-hards, and it for good reason - it's hard to learn a language when you have all the Windows overhead, not to mention the completely different program execution method).

The reason I quoted that part was because I recently got to start learning how to make Windows apps, and it turns out that outside of working directly with the Windows API (which the author of my book even hinted is rarely done anymore due to the massive amount of coding involved) pretty much everything is set up the same way. I'm using MFC right now (Microsoft Foundation Classes) which is native C++ but it's basically a friendlier face on the WinAPI. There's a class for almost everything you can inherit from. You don't even need to write WinMain(), it's all done behind the scenes when you inherit from CWnd.

That said, it will take some time to figure out everything that the base classes can do. For now, I have to figure out how to point to a folder and tell my program to look at all the files in it and its subfolders, assign each of these files a string description, and then display them in a tree hierarchy (similar to Explorer, inheriting from CTreeView). I'm assuming there's a function out there somewhere that can return handles to files, just need to find the damn thing

Anyway, I haven't delved into C# yet, but as a fellow aspiring programmer (albeit one having to self-study and probably a good deal behind you if you've got experience with Windows programming ), I hope you continue writing these journals.

on Oct 14, 2008

Great potential here. Maybe we can learn together as you learn new stuff. I got a 3D project underway that requires me to build a prototype of something that needs to be rendered in real time(for university of course). I would recommend the Ogre3D engine for any 3D real time rendering work. Its an open source 3D engine. Not quite as easy as XNA but its not a game engine.

BTW are you using the express edition of VS? That is simply quite atrocious if you want to use it for other stuff. Avoid it if you can.

on Oct 14, 2008

BTW are you using the express edition of VS? That is simply quite atrocious if you want to use it for other stuff. Avoid it if you can.

No, I'm using 2005 Pro (and have the 2008 ISO laying about someplace as well). Yay for University MSDN.

I'm just thankful that the university is up to 2005 though--last year we were still on 2003 in the labs, and C# under .NET 1.0 has a variety of issues and shortcomings.

on Oct 14, 2008

That said, it will take some time to figure out everything that the base classes can do.

Intellisense + MSDN

on Oct 14, 2008

3D GUI FTW! (standard since 1987)...

on Oct 14, 2008

Good to see you doing somethign constructive with your life buddy. Bit of a change from the old milk days eh?

Best of luck to you in your course. How many years you got at Uni anyhow?

on Oct 14, 2008

Intellisense + MSDN

Yeah, basically MSDN is very light on code examples, though

on Oct 14, 2008

Cool, that is going in bookmarks.  I have been toying with picking up C#/Visual Studio since so many job listings ask for it, and it seems a small step having mostly worked in C and Java.  Was thinking of finding an open source team to learn from and help out, but they're all still using languages from the bad old days before garbage collection.

on Oct 15, 2008

I've toyed with the idea of trying out XNA for a while now, as C# is my main language anyway. Maybe I should finally get around to it.

on Oct 15, 2008

I'm studying C# at the moment as well. It's a fairly simple language, easier then C++ I think. Good luck to you Kryo!

on Nov 02, 2008

Argh. I was going to get back on this--first weekend since this journal that I've not been loaded down with work to do--but paint shop pro seems to not want to cooperate with my efforts to make some sprites to try out animation, crashing half the time I try using any gradients or vector shapes. Unfortunately the animation isn't going to happen without anything to animate, so it looks like it'll be a while longer before I can continue on this.