Something To Share

Trying and failing is better than not trying at all

Game Development With MarteEngine

During the past few days I have been trying out some random stuff with Slick2D. I used Slick2D for my last game and I thought that it was amazing at what it does. It doesn’t get in my way of coding, it just helps you while you keep coding.

I’ve been reading Ziggy’s blog and he has talked about Artemis Entity Framework. Instead of having an Object Oriented approach at creating your entities (player, creeps, etc.) you have components and systems. I won’t go on explaining it in this post, you can read about it here.

Artemis framework is a very clever framework. When you start writing a game using that, you do feel that it is very extensible. But the only problem is that it’s too much work when just getting started. If you are only creating a small scale game, then you are better off with the good old OO approach. Unfortunately it took me 2-3 days of messing around plus a thread on Slick Forums to realize that.

What’s good about using Artemis ?

Your code would be very neat, and organized. Game data is handled by components and logic is handled by systems. Very little confusion, after you get yourself familiar with it (After reading through the source of their example game - Star Warrior.

What alternatives do I have ?

MarteEngine. This is a framework built on top of Slick2D. Created by Gornova at RandomTower.

Although still a work in progress, and aimed at beginners. It gives you lots of utilities, and a nice way to organize your code, without getting on our nerves all the time. For me it just took 30 minutes of going through their wiki, and reading the source of the awesome game Fuzzy, by Gornova. To get familiar with it.

What I like about the MarteEngine.

For your characters, you can create an object of their Entity class. Or you can extend their Entity class to create your own character.

Here’s an example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class Hero extends Entity {

  private Image image;
  private float velocityX = 5.0f;

  public Hero(float x, float y) {
    super(x, y);
    image = new Image("hero.png");
    this.setGraphic(image);

    // Controllers
    this.define("RIGHT", Input.KEY_RIGHT);
    this.define("LEFT", Input.KEY_LEFT);
  }

  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    super.update(container, delta);

    if(check("RIGHT")) {
      x += velocityX;
    }
    if(check("LEFT")) {
      x -= velocityX;
    }
  }

As you can see, the update logic for that entity is in it’s own class. And easy to manage. This code can be further extended to support collision / gravity and various other things.

MarteEngine has a built in collision detection system, and you can use it. But if you decide not to use it, you can use your own system. Basically it’s up to you to decide.

A quick “game” developed to test MarteEngine.

Home made graphics, using Inkscape

EDIT: Turned out to be more than just a test. Legless Runner is now available at https://github.com/yasithv/Legless-Runner.

I hope to compete for the 22nd Ludum Dare using Slick2D and MarteEngine, and I will write a development blog post about the experience.