Monday, November 12, 2012

TankGame 02 - Slick, MarteEngine, Lwjgl Setup - Java 2D game development

Posted by sudheera On 11:43 AM


Lets keep AI algorithm and the game logic aside for a while and focus on the Game interface in this post. I'm using Slick + MarteEngine +Light Weight Java Game Library(lwgjl) combination for this project. So this post and the future posts will be kind of Silk game developing tutorials. That's a good thing because these engins,libraries are not commonly used and tutorials are hard to find. Jmonkey is also a good game engine but as I heard it is biased towards 3D game developing and we don't need that. Since we're coding with Java we can't use XNA framework either.

First of all we need to include these libraries to our project. I'm developing this project with Netbeans, so here I'll explain the steps you should follow in oder to setup the environment first.  Eclipse users please google it, it's not hard to do it with eclipse. However with my x64 bit computer I spent like 48 hours to find a way to get these things to work. I'll explain the standard way and later I can give this special bundle for x64 bit users.

Slick

1. Download and extract the library from :  Link
2. Open netbeans, create new project, goto tools->libraries
3. Click on the button new library, and give name "Slick"
4. Click button add jar/folder and browse the extracted folder and go to the folder "lib" and choose all files except "slick.jar" and "slick-util-src.zip" and then click add.
5. In source tab add the folder "src" which located inside the extracted folder. And do the same for Javadoc tab(folder is named "javadoc").

Marte Engine

1. Download ans extract from : Link
2. Create the new library named "marte" like we did before(step 3 above)
3. add marteEngine.jar and src folder in classpath and sources tabs.


setup the project

1. Go to project properties. (RightClick - > Properties)
2. In left side choose libraries.
3. Under the "compile" tab click on add library and add "marte" library we just created.
4.Click on add jar/Folder and add Slick.jar which we left at step 4 of slick setting
5. In "Run" tab add the "slick" library.
6. Now choose 'run' from the left side panel()  and for the 'VM Options' you should enter the following line :
-Djava.library.path="F:\Tank Game\Libraries\lwjgl-2.8.4\lwjgl-2.8.4\native\windows" 

Here as the path I've given the path to "\native\windows" folder.  You have to browse the path according to your folder and paste it as the path.

And that's all. Now we have setup our environment. Here's my netbeans project folder that I'm currently working on. (It contains a half-game from a tutorial on youtube). Download it and import to netbeans and follow above steps. (If you already added the libraries then you have to follow "setup the project" part only).


Now run the spaceshooter.java file. If you get a new window and a space-ship in it, then you have done everything correctly so far. If not you have to go through above all steps and make it done. If your system is x64 bit then don't worry there's an issue with the lwgjl library for x64 systems. x64 users can follow these steps instead.

For x64 users 

I should give credit to Mr. Stefan Hendriks for sharing this wonderful method with us. I almost spent a whole day trying crack this one. here's the original post.
 
Download this special 64 version of lwgjl : Download

 1. In netbeans goto tools-> libraries and delete the slick library we created earlier.
2.  Create new "slick" library and add everything(to classpath tab) except slick.jar in the "slick\lib" folder of the downloaded folder. And the Java doc and src as we did earlier.
3.  Create a new library called "lwgjl" and add everything inside the "lwgjl\lib" folder of the downloaded folder to the classpath tab. And add src and Javadoc accordinly.
4. Then repeat the setup the project steps, but at the step 4 add the slick.jar located in the "\slick\lib" of the downloaded folder, and at the step 6 you should set the path of "\native\windows" folder that is located inside of the downloaded folder.
5. Don't forget to add the "lwgjl" library to compile tab.

This is how is should look


Now everything should be working nicely. That's it for now, soon we'll be developing the Tank Game world and players, hopefully. thanks.

Any problem with the post? please leave a comment.