Wrapping JGame engine in Clojure - A rocky start

38 views
Skip to first unread message

John Pratt

unread,
Sep 24, 2011, 11:34:20 PM9/24/11
to Clojure Games
Hello clojure-games group!

The JGame engine ( http://www.13thmonkey.org/~boris/jgame/ ) sounds
like it will be perfect for the type of game I want to make. It
supports multiple platforms, fixed frame rate, animations, collisions,
scrolling, snapping to tiles, sound, text display, and some other
stuff that didn't interest me as much. It is one of few game engines
I've found that isn't just a graphics engine or layer on top of
OpenGL. It also looks fairly easy to use... except it is written in
Java, not Clojure.

It is already being used in Clojure by somebody, as it is on clojars:
[org.clojars.nakkaya/jgame "3.2.0"] , but I couldn't find anything by
nakkaya showing how to use it.

I decided to wrap it in Clojure, but got stuck trying to even run
their first tutorial example.


The idiomatic usage of the jgame, to allow running as an applet and as
a jar, is:

public class Example1 extends JGEngine {

public static void main(String [] args) {
new Example1(new JGPoint(640,480));
}

public Example1() {
// This inits the engine as an applet.
initEngineApplet();
}

public Example1(JGPoint size) {
// This inits the engine as an application.
initEngine(size.x,size.y);
}

// snip the rest of the class

}

From Clojure I try this:

(ns jgame-tutorial.core
(:gen-class
:class jgame-tutorial.core.Engine
:extends jgame.platform.JGEngine
:init init
:constructors {[] [], [jgame.JGPoint] []}
:state state)
(:import
;; snip 2 full packages that were imported in the java version
))

(defn -main [& args]
(new jgame-tutorial.core.Engine (JGPoint. 640 480)))

(defn -init
([]
(.initEngineApplet this)
[[] (ref {})])
([^JGPoint size]
(.initEngine this (.x size) (.y size))
[[] (ref {})]))

;; snip the rest of the functions


When I try to create a standalone jar with leiningen:

$ lein uberjar
Cleaning up.
Exception in thread "main" java.lang.ClassFormatError: Duplicate field
name&signature in class file jgame-tutorial/core/Engine (core.clj:30)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5376)
...snip...
Caused by: java.lang.ClassFormatError: Duplicate field name&signature
in class file jgame-tutorial/core/Engine
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
...snip...
... 45 more
Uberjar aborting because jar/compilation failed.

Does anyone have either experience with using JGame in Clojure?
Or enough understanding of Clojures gen-class to know what is going on
here?
Or enough understanding of Clojure and Java to know a better approach
to wrapping/using JGame from Clojure?
Reply all
Reply to author
Forward
0 new messages