domingo, 22 de julio de 2012

Tile Maps (mapas de mosaicos) y cargadores de niveles II



Se me ocurrío meter cada nivel entre dos caracteres '<' y '>' y dentro meter
las tiles especiales.
Ejemplo:
<10,1,0; 20,1,0; 30,2,1>
Esto sería en la posición (x=10, y =1) hay una tile de tipo 0
Esto sería en la posición (x=20, y =1) hay una tile de tipo 0
Esto sería en la posición (x=30, y =1) hay una tile de tipo 1
Meter en cada linea de un fichero de texto un nivel de estos y luego parsearlo.
¿Como? Algo así(el codigo esta mal y ya no lo uso):

// Devuelve un array de strings con los todos los niveles
  private void  ParseFichero(String nivel)
  {
  char[] canivel = nivel.toCharArray();
char[] ca_aux = new char[World.WORLD_WIDTH];
  int indexca_aux = 0;
  int estado = 1;
 
listaniveles = new ArrayList<String>();
 
for (int i = 0; i < World.WORLD_WIDTH; i)
  {
  char c = canivel[i];
switch (c)
  {
  case ST_BEGIN_LEVEL:
  {
  estado = ST_IN_LEVEL;
ca_aux = new char[World.WORLD_WIDTH];
  indexca_aux = 0;
  }
  break;
  case ST_END_LEVEL:
  {
  ca_aux[indexca_aux] = '\0';
listaniveles.add(new String(ca_aux));
  }
  break;
  case ST_IN_LEVEL:
  break;
  }
  }
}

  public void ParseLevel (int numnivel)
  {
String nivel = listaniveles.get(numnivel).toLowerCase().trim();
  String[] astrtiles = nivel.split("\\;");
obstaculos = new ObstaculoNormal[astrtiles.length];
 
  for (int i = 0; i < astrtiles.length ; i)
  {
int x = Integer.parseInt(tiledataseparado[0]);
  int y = Integer.parseInt(tiledataseparado[1]);
  int type = Integer.parseInt(tiledataseparado[2]);
 
ObstaculoNormal obstaculo = new ObstaculoNormal(x, y, type);
obstaculos[i] = obstaculo;
  }
}

No hay comentarios:

Publicar un comentario