Tuesday 17 March 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();
}

}