Slick and Clojure … firsts steps …

Playing with clojure at the moment … in the idea to try and make the
next 2D game in my round with it (just for fun…).

Since I’m going back to the java world, why not use a ‘real’ 2D engine
instead of rolling my own half-baked one each time ? I googled a bit
and found a bunch of interesting 3D engines (jMonkey, I’ll have to go
back to you sooner than later 😉 ), and a bunch of interesting 2D
engines. I have to try one, I picked Slick, I have no idea how it will
end up.

Slick is found

Set up the project

I’ll use the following structure

  • slick-test
    • src
    • lib
    • clj

for java sources, lib and clojure files.

I’ll do this ‘by hand’, but if you use and IDE like Eclipse, you might want to adapt what comes next.

I’ll let Slick documentation help on this, but basically you want all of this :

  • Get the Slick full distribution from SVN
  • Build slick.jar if needed (the ant task is build-slick)
  • You’ll need the libs slick.jar, lwgl.jar. Put them in lib.
  • Also get Clojure, and the clojure.jar lib. Put it in lib.
  • Export the content of the jar called native-linux.jar (from Slick distribution, if you are on linux obviously).
    In eclipse, you do this with “export->java archive”. otherwise jar -xvf should do the trick. Copy all the so files in you lib folder

The java code

I am adapting the code for a very basic Slick example, taken here. (I won’t copy / paste is since it is render very uglily by wordpress, sorry…)

This is an app that does nothing.

The Clojure code

Here is the equivalent code in clojure (or so I think), to be put in a file like test.clj :

;; I suppose there is a way to import all classes ...
(import '(org.newdawn.slick





;; Here is the proxy for the simple game

(def simple-test

        (proxy [BasicGame] ["SimpleTest"]

                (init [container])

                (update [container delta])

                (render [container graphics]

                        (.drawString graphics "Hellow Slick world!" 0 100))))
;; Then the application is created and run

(.start (new AppGameContainer simple-test))

I run the app with a shell script like this. If you copy and compile
both the clojure and the java code, you can try and run both to see
that there is – at least to the naked eye – not a big difference
between the running times. Of course I’ll have to check that more …


if [$1 = "java"]; then
java -cp ${CP} -Djava.library.path=${LIB_PATH} ${CLASS} ./clj/test.clj

Next time I’ll try to have things move for real 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: