Zune games with XNA

The latest version of XNA comes with support for creating games for the Zune. I’m pretty excited about this and have embarked on an open source game with three coworkers called ZuDoKu. It will be a collaborative Sudoku variant for the zune.

I figured that in order to get this going I was going to have to update my Zune software finally. I haven’t been able to update it since I first got it, it’s not that I didn’t want to but it was just bombing out during the update process every time. Well I spent two hours of my friday night trying to fix it and finally was able to! It was choking when trying to access certain registry keys and when trying to unregister an assembly called Flash9b.ocx. Well both problems were eventually resolved by navigating to the registry keys in question and giving myself the correct permissions to manually delete the problematic keys.

It seems that Flash v9b was actually setting the “Everyone” user to be denied to delete some keys and their uninstallation process was not cleaning these keys up properly, which in turn was causing the Zune update software to choke. Well, after manually deleting all of the Flash related keys in HKLM\CLSID (after uninstalling flash of course) I got the update to finally work! I’m pretty excited… now off to game programming!

The Illusion of Strong Typed Xml with Boo

One interesting feature of boo is the ability to do dynamic typing. To do dynamic typing in boo you simply have to declare a variable as type “duck”, which is a reference to Ruby’s duck typing concept (“if it walks like a duck and quacks like a duck… then it must be a duck!”). The fact that they named the type “duck” in boo reveals the light hearted and humorous style that went into the creation of boo. I think it makes programming feel a little more casual and fun, boo is not a very self important language.

So while messing around with dynamic typing a bit I decided to come up with a simple example of how to use dynamic typing to read XML with a strongly typed style. Here is the main code for the example application I have written:
namespace Boo1
 
import System
import System.Collections
import System.Xml
 
doc as XmlDocument = XmlDocument()
doc.LoadXml(“<root><child1 att=\”hello\” /><child2 att=\”world!\” /></root>”)
 
xml as duck = XmlDocumentFu(doc)
hello = xml.root.child1.att.Value
world = xml.root.child2.att.Value
 
print ${hello} ${world}
 
print “Press any key to continue . . . “
Console.ReadKey(true)
 
·         Download: Source Code [rar]
Below you can see I have passed the XmlDocument into a class called XmlDocumentFu. This is a custom class I have created that implements the interface IQuackFu. In boo if you make a call to a method or property on an object that implements IQuackFu that does not exist, it will allow you to intercept the failed call and handle it yourself. In this case our XmlDocumentFu object will intercept failed calls to the root property first and attempt to translate that call into a one that iterates through the ChildNodes and finds a node of the name of the property instead.
This allows us to access elements in our XML as if they were properties on a strongly typed object! Pretty sweet! You should note however that in order to do this I had to declare my xml object as type “duck”. This enables duck typing for that object and as a result you do not get any intellisense support at design time. So it’s a bit of a tradeoff, what is more important to you explicit intellisense supported code or brevity? With this style you can kiss goodbye all of the various looping you might have done otherwise and encapsulate it in a few simple classes.
namespace Boo1
 
import System
import System.Reflection
import Boo.Lang
import System.Xml
 
class XmlDocumentFu(IQuackFu):
      
       _document as XmlDocument
      
       def constructor(document as XmlDocument):
              _document = document
      
       def QuackInvoke(name as string, o as (object)) as object:
              return null
             
       def QuackGet(name as string, params as (object)) as object:
              node as XmlNode                                
              for child as XmlNode in _document.ChildNodes:
                     if child.Name == name:
                           node = child
                           break
             
              if node is not null:
                     return XmlNodeFu(node)
                    
              ret as duck #this is type duck so you can call indexers optionally below
              prop as PropertyInfo = _document.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public)
              if prop is not null:
                     ret = prop.GetValue(_document, null)
                    
              if params is not null:
                     for p in params:
                           ret = ret[p]
                          
              return ret
             
       def QuackSet(name as string, o as (object), value as object) as object:
              return null
             
class XmlNodeFu(IQuackFu):
      
       _node as XmlNode
      
       def constructor(node as XmlNode):
              _node = node
             
       def QuackInvoke(name as string, o as (object)) as object:
              return null
             
       def QuackGet(name as string, params as (object)) as object:
              node as XmlNode
              for child as XmlNode in _node.ChildNodes:
                     if child.Name == name:
                           node = child
                           break
                                        
              if node is not null:
                     return XmlNodeFu(node)
                    
              attribute as XmlAttribute
              for att as XmlAttribute in _node.Attributes:
                     if att.Name == name:
                           attribute = att
                           break
                          
              if attribute is not null:
                     return attribute
                    
              ret as duck
              prop as PropertyInfo = _node.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public)
              if prop is not null:
                     ret = prop.GetValue(_node, null)
                    
              if params is not null:
                     for p in params:
                           ret = ret[p]
                          
              return null
             
       def QuackSet(name as string, params as (object), value as object) as object:
              return null
 

Boo is blowing my mind

For the next Twin Cities Code Camp I am planning on talking about Boo, a very new and interesting .NET language.

It’s truly blowing my mind, check out this example of Syntactic Macros for an example of what I’m talking about. If you want to try boo out for yourself the easiest way to get started is to just install SharpDevelop. Boo comes compeltely integrated out of the box and that’s all you need to do to get going.

My mind is reeling with the possibilities… is this truly the solution to the intentional programming with N levels of embedded DSL’s I’ve been wanting?

Geometry Wars Galaxies

If you’ve been wondering why I’ve been somewhat MIA lately it’s completely due to Geometry Wars: Galaxies.

If you own a Nintendo Wii, do yourself a favor and go out and buy this game right away. It’s amazing. It’s exactly like the Xbox Live Arcade game of the same title (minus the galaxies) except with LOTS of diversity. There is a new “drone” feature where you get to pick a type of drone to take with you into battle and the more you use it the more your drone will go up in power. Some of the later levels are frankly impossible without the help of your drone. Besides just being incredibly fast paced and visually stunning the game is full of all sorts of clever little devices used to surprise you and change things up.

The only thing I would complain about this game was simply that it’s on the Wii. I mean I like the Wii and all but the controller you have to use is just too small for my hands for such a fast paced game. I’ll probably have to see if I can beat my old score on xbox live after all this practice.

Watch this video if you haven’t played geometry wars before:

Geometry Wars–4 Million