LordChandar
|
 |
«
Posted
2012-11-03 01:22:05 » |
|
Greetings.
I am trying to convert my game from flat 2D to Isometric 2.5D. I have mocked up a prototype demo that displays all the tiles correctly, but when I go to move the Y jumps from up to left and from down to right...
I am sure I am doing something stupid...
Before I get into the technical details, if someone would be willing to jump onto Skype, I am signed on as jcannonb, and would be happy to send the prototype project in full over.
My method for converting the coordinates is: public static Point getIsoXY(int tilex, int tiley, int isoTileWidth, int isoTileHeight) { int x = tilex*isoTileWidth; int y = tiley*isoTileHeight/2; if (tiley %2 == 1) { x = x- isoTileWidth/2; } //y -= isoTileHeight/2; return new Point(x, y); }
When I am moving up down left and right, I do this: if (k == KeyEvent.VK_UP) { gamePanel.images.showY--; } if (k == KeyEvent.VK_DOWN) { gamePanel.images.showY++; } if (k == KeyEvent.VK_LEFT) { gamePanel.images.showX--; } if (k == KeyEvent.VK_RIGHT) { gamePanel.images.showX++; }
ShowX and ShowY manipulate the top most portion of the map to be displayed in this case...
To display the map, I do this: public void draw(Graphics g) { BufferedImage current; wvp.clearBuffer(); for (int y = 0; y < 30; y++) { for (int x = 0; x < 10; x++) { current = Map[x+showX][y+showY]==0?grass:water; wvp.WriteTile(current, x, y, 0, 0); } } //Place player in the center wvp.WriteTile(dirt, (10/2)-1, 30/2-1, 0, 0); g.drawImage(vp.getSurface(), 20, 20, null); }
Finally, Writing the tile looks like this:
public void WriteTile(Image i, int tilex, int tiley, int stepX, int stepY) {
Point xy = IsoUtil.getIsoXY(tilex, tiley, terrain_width, terrain_height); //System.out.printf("Writing at %d:%d\n",xy.x-stepX,xy.y-stepY); vp.WriteImage(i, xy.x-stepX,xy.y-stepY);
}
Thanks in advance...
|