Several years ago I started learning Ruby, which is my first dynamic-typed programming language. As a rookie programmer I was very astonished by its elegance and flexibility. But as time goes by, I has stopped being a fan of dynamic languages.
I have to admit dynamic languages are generally easier to code and understand. In the meanwhile, however, you can’t find an efficient way to refactor/debug them. Unit Test only mitigate this problem partially. On the other hand static languages are tedious but easier to scale in features.
To get the best of two worlds I chose Scala, a functional language based on JVM. Scala is not the final answer of programming language(the syntax is too obscure), but for me, it’s the most viable solution by far.
One of the best features of Scala is the fact it’s based on JVM, so it can utilize existing libraries written in Java. What interests me most is libGDX, a cross-platform game development library.
Scala and sbt
First, of course, you need Scala. It’s a kind of popular language now, so you may be able to install it via your package manager:
sudo apt-get install scala // On Ubuntu brew install scala // On OSX
If you want the bleeding edge version you can check the official site.
libGDX decided to use Gradle as dependency manager. It’s not a bad idea(compared to Ant and Maven), but in the world of Scala we use sbt. Similarly:
brew install sbt
On Ubuntu or other Linux systems you can download .deb file here.
libGDX and the game
It may not be a simple job to figure out all dependencies and build scripts, especially when you wish to develop game for multiple platforms, not just desktop. Luckily someone has done that and save his work as a template. To set it up you need giter8:
curl https://raw.github.com/n8han/conscript/master/setup.sh | sh cs n8han/giter8 g8
Then set up the template. It will ask you to specify some configurations.
g8 ajhager/libgdx-sbt-project ... package [my.game.pkg]: cc.raintomorrow.smile name [My Game]: Smile scala_version [2.10.3]: api_level : main_class [MyGame]: Smile libgdx_version [0.9.9]:
It will generate a directory named
smile. Now you have a fully functional game project! Oh wait, I’m lying. You haven’t installed its dependencies yet. Before you do this, you can check the
project directory in the project. You can change the versions of dependent sbt plugins in
project/plugins.sbt and sbt itself in
project/build.properties if the template’s choices don’t please you. Be careful, not every up-to-date plugin is compatible with each other.
Then install everything you need:
sbt > update
It will take a while. After it’s done, you can run your game now! Watching an empty window is sort of boring, however, so let’s add some code. (Of course you shouldn’t use ShaderRenderer in real-world project.)