
private Image imgGoofy;
private Sprite sprGoofy;
private int xPosGoofy, yPosGoofy;
private int sequence = 12;
//Inicializamos las variables
imgGoofy = Image.createImage("/imagenes/goofy/issac.png");
sprGoofy = new Sprite(imgGoofy, 32, 48);
xPosGoofy = 95;
yPosGoofy = 250;
//Lo pitamos en el graphics
sprGoofy.setPosition(xPosGoofy, yPosGoofy);
sprGoofy.setFrame(sequence);
sprGoofy.paint(g);
//le damos movimiento al presionar las teclas
if ((keyStates & RIGHT_PRESSED) != 0){
if (i < 9 || i > 11){i = 9;}
xPosGoofy = Math.min(w-50, xPosGoofy + 5);
sequence = i;
i++;
}

//Este es el tile que vamos a utilizar para cargarlo por partes
private Image mapaImg;
private TiledLayer tile;
private int [] map = {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,12,
5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6,12,
5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 8,10,10,10,10,10,10,10,10,10,10,10, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7,10,10,10,10,10, 9, 7, 7, 7, 7, 8,10,10,10, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 9, 7, 7, 7, 8,10,10,10, 9, 7, 7,12,
5, 7, 7, 6, 6, 7, 7, 9, 7, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7,12,
5, 7, 7, 6, 6, 7, 7, 9, 7, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7,10,10,10,10, 9, 7, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7, 7, 9, 7, 7,12,
5, 7, 7, 7, 7, 7,17, 9, 7, 7, 7, 7,10,17, 7, 7,10,10,10,10,17, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,12,
5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,12,
5, 6, 7, 7, 7, 7, 7, 7, 7,15,16, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6,12,
5, 4, 4, 4, 4, 4, 4, 4, 4,13,14, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,12};
w = getWidth();//ancho de la pantalla
h = getHeight();//alto de la pantalla
xTiles = 24;//cantidad de tiles en x
yTiles = 22;//cantidad de tiles en y
xPosTile = -130;//posicion x del tile en pantalla
yPosTile = -225;//posicion y del tile en pantalla
mapaImg = Image.createImage("/imagenes/mapa/tilesMapa.png");//cargamos la imagen
tile = new TiledLayer(xTiles, yTiles, mapaImg, 24, 24);//
//Metodo para cargar el sprite en el tile
private void cargaSprites(){
for(int i = 0;i < map.length;i++){
int columna = i % 24;
int fila = (i - columna) / 24;
tile.setCell(columna, fila, map[i]);
}
}
tile.setVisible(true);
tile.setPosition(xPosTile, yPosTile);
tile.paint(g);
if ((keyStates & RIGHT_PRESSED) != 0){
xPosTile -= 5;
}
No hay comentarios:
Publicar un comentario