Saturday, April 23, 2011

Magecrawl-Arena status update

I'm going to try to try to create something like Doryen Arena using python, seeing how things go. I figured I'd post a status update:

Project started 8 days ago, with about an hour of coding a day roughly. I'm through stage 5 of this, which includes:

GUI - Using public domain graphical tiles from Crawl Stone Soup, found here, I have a scrollable map with variable tiles (not every dirt tile is the same), that persist.
Physics - I have a simple physics engine that includes walls (that one can't walk through), and doors one can open.
Keybinding - Arbitrary key mapping (mouse support to come!)
Serialization - Save/Load support.

Compared to Magecrawl itself, it seems somewhat pathetic a feature list. However, I'm enjoying poking around in python between games of Portal 2 and Rift.

Source can be found here if you are curious.

Clever Python Hacks Part II - Serialization

Serialization is Magecrawl is pretty good, however it is somewhat verbose. I write out a giant XML tree with all of the attributes of everything, and parse that in on load. It is about 200 lines of core code, along with about 100 for the map and about another 100 for the player.

Here's what my serialization code looks like in python so far:

    SaveVersion = 1
    def __save(self):
        with open(self.player.name + ".sav", 'wb') as file:
            pickle.dump((self.SaveVersion, self.player, self.level), file)

    def __load(self, filename):
        with open(filename, 'rb') as file:
            fileSaveVersion, player, level = pickle.load(file)
            assert fileSaveVersion == self.SaveVersion
            self.player = player
            self.level = level

I do loose the XML format in exchange for a binary one, but you have to love that simplicity.

Wednesday, April 20, 2011

Clever Python Hacks Part I - Keymapping

Keymapping was complicated stuff in Magecrawl. See here for the XML reader(LoadKeyMappings() and HandleKeystroke). It was powerful stuff, using reflection, XML and such. However, I just got 80% of that in a four liner today:

def load_key_mapping():
    globalDict = {}
    exec(open("KeyMapping").read(), globalDict)
    return globalDict["KeyMapping"]

This function loads the given file as a python script and executes it, then sucks out the KeyMapping dictionary. The KeyMapping script looks like this:

import pygame

KeyMapping = \
{
    pygame.K_UP : 'Up',
    pygame.K_DOWN : 'Down',
    pygame.K_RIGHT : 'Right',
    pygame.K_LEFT : 'Left',
}

I get a simple dictionary of button presses to string, and I can switch off those later. The only concern I have is people sharing KeyMapping files and people doing stupid things in them. However, right now I'm now that concerned, as this is stupidly simple and works great.

Tuesday, April 19, 2011

Spinning Up The Time Machine

So, I'm still playing with python. Not sure I'm going to write an entire roguelike in it, but figured I'd hack out to the step 4 (walking around a room) on the 15 steps to a roguelike.

I noticed the number of files/lines of code seemed to be much smaller than I remembered, so I pulled up the equivalent submission in magecrawl.

The python copy looks like this:


While the magecrawl looked similar to this (this was from a few weeks later, similar idea though)



Here is the comparision (excluding test code). This isn't comparing to the map generator picture above, just the walking around an empty room.

Python - 3 source files, 127 lines of code.
C# - 13 source files, 503 lines of code.

Much of that difference comes from the verbosity of C#. Some of it comes from the use of interfaces in C# compared to duck typing in python. The rest comes from an effort to implement the minimum needed and keep things simplier.

As a side note, pygame is pretty awesome. I might pull in libtcod for line of sight and pathfinding, but since I want "tiles" graphics, pygame made that crazy easy.

Friday, April 15, 2011

Has it been 6 months already?

Wow, I can't believe 6 months slipped by that quickly. Between work and my personal life, I seem to have lost track of time (and stopped updating this). Eitherway, I'll try not to let that happen again.

I've picked up programming for fun again, but so far not on magecrawl. I still want to finish it or something like it, but I've come to realize something about myself and the projects I work on as a hobby. I find things fun that are different from what I work on while at work. While I was working in C/C++, C# was fun to work on; now that I use it 8+ hours a day, not so much now. The Silverlight front end was fun until I started wrestling with Silverlight at work.

I'm playing around with Test Driven Development and Python these days. It is kind of funny that I have more test code in my little project than actual lines of code, but I hear that is how things are supposed to be.

Once I get something a bit more presentable I'll post more about it. I just wanted to get back in the habit of blogging again.

Sunday, November 7, 2010

Learning OpenGL, slowly...

So I've burned a few hours trying to learn OpenGL. I'm using C#, accessing OpenGL via OpenTK. The tutorials here are great, but a bit out of date. After much frustrations, I found that ramblingcoder picked them up and converted them to C#.

Wednesday, November 3, 2010

Frustrations on programming languages

So, I'm honestly a bit demotivated to work on Magecrawl. Part of it is that I'm in the middle of porting it to Silverlight as a way to get a tiles version with little work that will work on Windows/Mac/Linux. Then this week, I come across these articles.

While it isn't like they are canceling Silveight, their "change in focus" and the fact that Mono is currently two major versions behind has me a bit worried. I don't want to sink another 20+ hours fixing things up, and then in a year or two have to move to another UI layer. I also don't want to loose being able to work on it on my Mac, and right now I'm in that boat.

More fundamentally, I'm frustrated that there doesn't seem to be a "good" way to do cross platform UIs for my game. I'm going to rattle though the programming languages I know or are good options. None of them right now seem to be a good fit.

C# - Silverlight: Only Mac/Windows right now. Linux is an unknown period of time away. A bit worried about its future, but probably best option right now.

C# - libtcod: Works everywhere, but no tiles UI.

C# - winforms - Yeah, it might technically work on Mac/Linux, but there are licensing concerns that make ppl not want to install it.

C# - GTK# - Doesn't look native on ANY platform except Gnome.

C/C++ - Any number of frameworks here, QT being the most obvious framework or OpenGL. Ignoring the rewrite aspect, I'd rather not chase memory errors in an unmanaged language when I'm not being paid for it.

python - pygame would be the most logical choice. I don't think I want to write in a dynamically typed language.

objective C - See C/C++ for the unmanaged language type. It also wouldn't work well on Windows/Linux, and I have no clue what GUI framework to use. 

Java - Seriously? Swing looks terrible anywhere, and with Sun Oracle trying its best to kill developer uptake, that isn't an option.

In writing this article, I've come across opentk, which appears to be a open gl binding for C#. While I'd have to learn yet another UI framework, at least I know it'd work everywhere...