Sprite steps

Yesterday I was fixing a bug in walking sprite (player). For the current sprite (Scias, Breath of Fire IV) are required 7 images for the transaction between the tiles. See below:

500000300 500000306 500000305 500000304 500000303 500000302 500000301

Note that the first step is the player is stopped. The bug occurred when the player performed a distance of several tiles. In the transition between the intermediate tiles (ie, all except the first and last), the first image appeared. What I like is that while it is moving, this first image was not displayed.
Solution: movements between tiles are now performed in a loop of 1-6 (excluding the first image – the index 0). Thus, when the player finished his walk, he remained with the image 6 (as if he was still walking). Then I created a new type of direction of motion called “NOTHING” (in Portuguese, NENHUMA), associating it with the first image.

NORTE(0,-2,TipoMovimentoEnum.VERTICAL,0,1),
NORDESTE(0,-1,TipoMovimentoEnum.DIAGONAL,-1,1),
LESTE(1,0,TipoMovimentoEnum.HORIZONTAL,-1,0),
SUDESTE(0,1,TipoMovimentoEnum.DIAGONAL,-1,-1),
SUL(0,2,TipoMovimentoEnum.VERTICAL,0,-1),
SUDOESTE(-1,1,TipoMovimentoEnum.DIAGONAL,1,-1),
OESTE(-1,0,TipoMovimentoEnum.HORIZONTAL,1,0),
NOROESTE(-1,-1,TipoMovimentoEnum.DIAGONAL,1,1),
NENHUMA(0,0,TipoMovimentoEnum.NENHUM,0,0);

Finally, changed the pathfinding to include “NOTHING” at the end of the path found. Thus, the thread that executes the character’s movement will end a sequence of movements with “NOTHING”, showing the image of the player stopped.

Note: of course I’m only using these images for’m in the prototype stage. Soon I will draw my own images (in another post I talk about it).

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…