Subscribe Now: Feed Icon

Saturday, April 16, 2011

Game Programming with Kodu

Part of the Beginner Game Programming in .Net series.

Kodu is a “new visual programming language made specifically for creating games”. I heard about Kodu back in 2009 but back then I didn’t have time to explore it. Kodu is game design engine designed like a game it self.

This is a Kodu

The advantages of using Kodu are:

  • Really easy
  • Free
  • Fun: treat as a puzzle
  • Can be played on XBox
  • Doesn’t need Visual Studios
  • Can be exported (and thus played on another PC)

The disadvantages of using Kodu are:

  • Cannot be converted into a standalone application
  • Not really .Net – implemented in .Net since it needs the XNA Framework but implementing games without a .Net language such as C# (disadvantage just because it’s part of the requirements)



Download and install Microsoft XNA Framework Redistributable 3.1

Download and install Kodu Game Lab


Getting Started

Open: Desktop –> Kodu Game Lab

Or:     Start –> Programs –> Microsoft Research –> Kodu Game Lab

The best way to get started is to go over the tutorials, on the main menu click on Load World and start the First Tutorial:


and select Play.

This tutorial is just for making the Kodu move by your input. The controls are very easy and just made me remember a game I played as a kid: TIM (The Incredible Machine) but if in TIM the task to perform was predefined here you can just choose it.


The Basics

Kodu is a game platform for interactions, it is fairly easy to program the Kodu into a shooter or a race. But add in logic and it starts to become tough.

There are no ifs, the objects are interacted by: Event => Action

So how do a Programmer programs Kodu?

Well… The first insight is that we have variables: the score boards! (we have 11 colors and 26 letters of scores)

Another insight is that there is a GOTO mechanism: switching the pages

There is even a compare of the score in the score boards – though it is of a const value…



I was actually not sure if a Tic-Tac-Toe game can be created in Kodu (since it is a game platform for interactions) but then I saw this video… And I was starting to think of implementing a Wacky Wheels instead…


How to create a turn based game?

The easiest way I found was using the Score Boards and pages:

Player 1 is with score 0 in the white score board

Player 2 is with score 1 in the white score board


Player 1: Plays and when his turn ends changes the score to +1


Player 2: Waits for a score of 1 all the while complaining about how slow the other player is:


When it’s Player 2 turn: He plays and in his end of turn subtracts 1


The player’s pages are complete opposites, player 1 will wait in page 2 and play in page 1 while player 2 will wait in page 1 and play in page 2.


How to create a winning logic?

If we had a matrix it would have been easy, just check for the winning conditions.

But we don’t have a matrix – we do have integers and can use them as score boards:








Each letter is a score board.

When player 1 plays he adds 1 to the variables he effects.

When player 2 plays he adds 10 to the variables he effects (I started out with subtracting 1 but then found out you just can’t check for a score of –3).

For example: Player 1 colors the spot in the top left corner. So he adds 1 to A, D, G.




We shall know that a player won when a variable has either 3 or 30, and from that we shall know which player won…

Checking for a winner is done by inanimate object like a tree:


And setting the winner:



The game:


To make it more interesting I made the players are moving really fast:


Classic winning move by the red player:


And the winner is:


The example can be downloaded from my CodePlex samples in here (a zip download of the Kodu).


Now I don’t consider Kodu a real programming Framework. This tutorial was done both because I wanted to try Kodu out for some time and to help my cousin. But it made me think because there were so many things that I have grown used to in programming like loops, variables and even real debugging (I had a bug while programming of switching to a non existing page and the program simply went back to the first page and that just caused an infinite loop).

It got me thinking of old games which is definitely a plus (and I might just come back to it just give a rebirth to Wacky Wheels).

So even if you are a programmer do give it a try because it will get you thinking in some strange ways. If you have kids (or cousins) try it out with them – it does make the brain work while having fun…


Microsoft Research: Kodu

Game programming made easy

Planet Kodu – checkout the games section or the challenges


Keywords: Kodu, Game programming

IceRocket Tags: ,

Beginner Game Programming in .Net

My cousin has a birthday today and has expressed an interest yesterday in Game Programming. As I don’t really know Game Programming I decided to try it out in .NET and help him along. He tried studying it himself but had some troubles since he is not a programmer (he is in a computers class in high school) and the tutorials he found were too advanced.

So my requirements for this little side project are these:

  1. No advanced stuff: stuff even a non programmer can do (so no shades and lightning)
  2. Easy games: No Doom… I think I will start with Tic-Tac-Toe 3D
  3. In .Net: I don’t want to relearn c++


The post of the series:
  1. Game Programming with Kudo
  2. Game Programming with XNA


Keywords: Game Programming

IceRocket Tags:

Friday, April 15, 2011

Blog Changes

I just wanted to update you on recent changes in the blog.

First I added my email account in image format (I have no need for more spam in my email then I currently have):

I have done it by using nexodyne email icon generator, it’s free and easy to use…

The second thing I did was add my twitter account using go2web20 Follow badge, again fairly easy to use and free.

The third and final thing is I opened a CodePlex project for all my samples. It was really easy to set and use (I use it with the Visual Studio Team Explorer settings).

Right now I only have the Google Street View example but it’s better than sharing things through DropBox’s public folder…

Saturday, April 9, 2011

Unit Tests: Introduction

On my previous job we had a large team working on an existing framework above the ESRI framework, we worked with coded Unit Tests with continuous integration.

I guess it was a kind of cultural shock to reach a place that had ZERO coded Unit Tests, that the only framework above the ESRI framework was the usage of a Dictionary class and the copy paste of file named SdeUtilities.cs from project to project.

Not to say that everything was perfect in my old project. Most of our framework was without Unit Tests, we used the excuse of “It’s too difficult to test COM objects/code that accesses the database”. But we also suffered from it.

I remember this one time where I changed a private method with a piece of code that looked like:

  1. public void UpdateFeature(IFeature feature, IEnumerable<KeyValuePair<string, object>> fields, IGeometry geometry)
  2. {
  3.     foreach (var field in fields)
  4.     {
  5.         feature.SetValue(field);
  6.         feature.Store();
  8.         if (geometry != null)
  9.         {
  10.             feature.Shape = geometry;
  11.             feature.Store();
  12.         }
  13.     }
  14. }

I changed it to:

  1. public void UpdateFeature(IFeature feature, IEnumerable<KeyValuePair<string, object>> fields, IGeometry geometry)
  2. {
  3.     foreach (var field in fields)
  4.     {
  5.         feature.SetValue(field);
  7.         if (geometry != null)
  8.         {
  9.             feature.Shape = geometry;
  10.         }
  11.         feature.Store();
  12.     }
  13. }

Seems close, no? Well I tested it in both my services and my WinForm application and everything worked so I checked it in. My friend sitting next to me did a get latest and for the next two days debugged why his application stopped working. At the end he asked me and I told him what I changed. It didn’t seem like a large change and I am not really sure why the ArcObjects code needed those two “Store”s. But what I do know is that Unit Tests for that code would have found that bug in at most minutes and at best seconds and would have prevented me from making that mistake.


When I rewrote the framework this time I wrote both Unit Tests and coded integration tests (tests that effect the DB). This time when I upgraded from ArcGIS version 9.3.1 to version 10 and the build passed without any problem, I ran the Unit Tests and they failed. I got the error:

System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {D9B4FA40-D6D9-11D1-AA81-00C04FA33A15} failed due to the following error: 80040111…

Googling the problem I found the solution. The problem was that in version 10 ESRI added another level of license control that needed to be initialized. I of course found out only when the tests failed.

When my team leader and manager asked me how much time I thought it will take me to upgrade the framework. My answer was two days. The unit tests I had were a big reason for that low estimate. I knew that all I needed to do was:

a. Make sure the tests pass in version 9.3.1

b. Replace the Dlls with those of version 10

c. Get the tests to work in version 10

I didn’t have to go over every pips in the application – my unit tests covered all of them.


Managers will forever tell you “there is no time for writing Unit Tests”. They do this for the sole reason of not understanding the importance of Unit Tests. They don’t understand that even the basic Unit Tests give a developer the confidence of changing his/her code (and prevent us from making the mistake of rewriting the code from scratch, since with Unit Tests it can be easily refactored). They don’t see Unit Tests as real tests – a developer’s job is to write code, a QA’s job is to do the tests. For them writing Unit Test just mean doubling the work with next to no gain – the developer might write better code but the QA will test it all the same.

So how do you start writing Unit Tests?

1. Try explaining it. I rarely succeeded in doing that (I scored very low on my bulshiting skill) so I can’t really help you there…

2. Going behind the back of the manager and just writing the damn tests.

3. Combine the two first methods. Begin with method 2 and start writing the tests, add CI (Continuous Integrations) to the mix with some instructions such as “Do not check in if the test or build failed” and show the manager concrete proof that Unit Tests work. Use graphs if you have to and show how Unit Tests saved you time in figuring the bugs in the system. Make sure to use the words like “experiment” and “low maintenance” managers seem to like them. And last but not least ask for the managers “advice” whether  to continue with this “experiment” or not – managers really want to manage us to death by giving the manager both the way (i.e. Unit Tests) and the problem “productivity”, “time” and “maintenance”, the manager will go to the least resistance route – the one you offer him… Let him in turn show it as his own success to his managers (for more such great advice read “The joy of work” by Scott Adams).


If you haven’t guessed I am going with method 3, it has both a return in results (i.e. written Unit Tests) and less manager bulshiting that managers must have in order to take things on faith alone…


Well tell me of your experience in convincing your boss? have you used one of these methods? Another way? How did it go? Do you have any advice for others?


Keywords: Unit Test, Test, IFeature

IceRocket Tags: ,,