My first steps

Hi. I’m creating a 2d game in Java. I will post my progress here. In future I’ll create a oficial website. For now, I have an isometric map. I drew the tiles (floors, stairs and walls) and downloaded sprites of the Scias, a Breath of Fire IV (a ps1 game) character.

The project is organized into three sub projects: base, client and server. The dependence between them and the management of package dependencies being managed by Maven. The basic project contains database entities, rich model entities, utilities (eg, bundle resources, i18n, static classes), classes for artificial intelligence and classes for pathfinding. It is used as a library for the other two.

I’m currently still using the hibernate entities, but in the future I intend to replace the database access by simple jdbc (‘m still thinking about it later). Why? The client project do not access the database directly. Only the server project will have access to the database (directly) and perhaps better access via jdbc (because of performance).

The project client will access data from database through a statefull connection (and encrypted) with a script running on Node.js. These script (affectionately called SuperServer) will not have business rules and only provide a means for requests to the database.

What am I working on now? Like I already said, my map is isometric. Therefore pattern pathfinding algorithm can not be fully utilized. The first adaptation is to change the weights of the horizontal/vertical and diagonal movements. Usually a diagonal move has a higher cost compared to the horizontal/verticias, respectively have 14, and 10. In my case, the horizontal/vertical movement should have a higher cost. Why? See the representation of an isometric tile below:

Isometric Tile

See it to walk north from an isometric tile you need to hold a diagonal movement. Therefore, diagonal directions are more expensive than orthogonal directions.

Another adjustment was needed in Manhattan algorithm. In matrix map, Manhattan calculates exactly the orthogonal distance between the current node and the destination node. In an isometric map, this calculation is not always correct. Luckily, another game developer had already found a solution for this (http://www.quartertothree.com/game-talk/archive/index.php/t-69406.html).

package br.com.linu.vectortown.base.pathfinding;
import java.io.Serializable;
import br.com.linu.vectortown.base.modelo.auxiliar.Posicao;
public class ManhattanIsometrico implements Serializable {
   private static final long serialVersionUID = -2242005057055685258L;
   private static int intValue(Double d) { return d.intValue(); }
   /* http://www.quartertothree.com/game-talk/archive/index.php/t-69406.html */
   public static int calcular(No origem, No destino) {
      int cx = origem.x() - intValue(origem.y() * 0.5);
      int cy = origem.y() + cx;
      int gx = destino.x() -intValue(destino.y() * 0.5);
      int gy = destino.y() + gx;
      int diagonal = Math.min( Math.abs(cx-gx) , Math.abs(cy-gy) );
      int straight = (Math.abs(cx-gx) + Math.abs(cy-gy));
      return 12 * diagonal + 10 * (straight - 2 * diagonal);
   }
}

I copied your solution and it’s served me well 🙂

For now, however, I’m still having a few problems finding the best path when the source tile and destination tile are on different floors (the game will have at most three different floors per screen). Sometimes pathfinding goes to a far corner of the stairs that would take him to the different floors, and consequently for the destination tile. Soon I will post here the solution to this…

Leave a comment