Tuesday, March 17, 2009

First Jython experiment

W00t! Got first Jython program working with GTGE:
# Test of Jython and GTGE.

# Java Foundation Classes (JFC)
from java.awt import *

# GTGE API
from com.golden.gamedev import *


"""
**
* The basic skeleton of Golden T Game Engine (GTGE).
*
* Objective: show how to set up a new game.
*
"""

class Test(Game):

def initResources(self):
# initialize game variables
pass

def update(self,elapsedTime):
# update game variables
pass

def render(self,g):
# render to the screen
pass


def main():
game = GameLoader()
game.setup(Test(), Dimension(640,480), False)
game.start()

main()


I decided on GTGE because it seems like it has been used for a lot of games so far, and so is fairly mature. It has also just been released as open source and seems to fairly well supported. We'll see.

Anyway, have a working Jython program that create a GTGE window. Admittedly the authors of GTGE did all the work and I just converted a Java tutorial into Python. Original Java code:
// JFC
import java.awt.*;

// GTGE
import com.golden.gamedev.*;


/**
* Game in Windowed Mode Environment.
*
* Objective: show how to set up a windowed mode game
*/
public class Tutorial5_1 extends Game {


/***************************************/
/************ GAME SKELETON ************/
/***************************************/

public void initResources() {
}


public void update(long elapsedTime) {
}


public void render(Graphics2D g) {
}


/**************************************/
/********** START-POINT ***************/
/**************************************/

public static void main(String[] args) {
GameLoader game = new GameLoader();
game.setup(new Tutorial5_1(), new Dimension(640,480), false);
game.start();
}

}

Sunday, March 15, 2009

Safari 4 Beta

Just trying out Safari 4 beta. Previously I decided Firefox 3 was better than Safari 3 because Safari didn't seem to add any advantage, as Firefox has lots of customisation options.

My initial impression is that Safari 4 is really fast. Pages appear notably faster than Firefox 3. It will be interesting to see Firefox 3.5 improvements. I wonder if they'll beat Webkit.

Other reviews (The Unix Geek: Safari 4 Review) have pointed out new features. I agree that moving the tabs into the title bar is a great idea as it gives more space. This is especially important on laptops where the screen isn't as tall. It's a relatively simple change but being able to read a couple of extra lines makes all the difference.

I also found a plug-in to allow use of Delicious bookmarks. It's not as well integrated as the Firefox one, but it'll keep me using Safari until I can try Firefox 3.5. Having your bookmarks stored online is a great usability boost for web usage, and having this well integrated with the browser is just as important.

The new bookmarks viewer in Safari 4 looks interesting. You can scroll through previews of your bookmarks or history. This a great if you are doing research and trying to find a site you bookmarked to read later. I hope someone is working on a Delicious extension for this. Now that would be cool.

Saturday, March 14, 2009

Java games

Been wanting to write a little game for fun. There are lots of ways to do this!

There are good C/C++ cross platform game libraries. One of the best I found is Clanlib. It's well designed and contains everything you'll need. Libraries like SDL provide simple cross platform APIs but extra functionality is via extension libraries which tend to be low quality or not maintained. Clanlib provides more of a coherent framework, and uses OpenGL for all rendering, so there are no platform specific quirks.

Using Python and PyGame means you don't have to recompile per platform. PyGame provide bindings for SDL. High level languages, like Python, are nice for prototyping and knocking experimental games up. You also don't need to worry too much about performance these days since most PCs have more than enough horsepower.

If you want to get your game to the widest audience then probably the best way is to make is playable in a browser. Downloading executables from the web is a lottery. Any program could contain malicious code. Running them in a browser gives people more confidence nothing nasty will happen. Flash is quite popular for this, but I didn't really grow to like it when experimenting with it. Now that canvas has arrived, Flash may be on the way out.

I've never really used Java, I suppose I haven't found a use for it. I use C++ for performance programming and Python for scripted tools etc. An interesting Python variant is Jython, that is, Python written in Java. This allows you to compile Python code into Java. So this seems like a good compromise, and allows you embed your Jython applet in a page to be used.

Using Java and Python also allows me to use Eclipse, which is a great development environment. We'll see how it works out.