?? board.java
字號:
yTemp = yTemp + tileHeight; } } lastDrawn = true; } // Image bufferCharacter = null; private void drawCharacterBoard(Character c, int x, int y, Graphics gInit) { int xTemp = x; int yTemp = 0; int xInit = x; int counter = 0; for (int i = 0; i < height; i++) { // y cycle (counter is "i") yTemp = y + tileHeight * i; xTemp = xInit - (tileWidth / 2) * i; for (int j = 0; j < height; j++) { int xCharTemp = j + cellX; int yCharTemp = i + cellY; if ((((xCharTemp - c.x <= 3 && xCharTemp - c.x >= 0) //TODO configuration 3, 3... && ((yCharTemp - c.y <= 3 && yCharTemp - c.y >= 0)) && map.getCell(0, xCharTemp, yCharTemp) >= 77) || (xCharTemp - c.x <= 2 && xCharTemp - c.x >= 0) && ((yCharTemp - c.y <= 2 && yCharTemp - c.y >= 0)) ) && (map.getCell(0, xCharTemp, yCharTemp) > 65 || (xCharTemp == c.x && yCharTemp == c.y) || (charactersPositions.containsKey(xCharTemp + "_" + yCharTemp + "_0"))) && j + cellX < map.getWidth() && i + cellY < map.getHeight() && onScreen(xTemp - tileWidth / 2, yTemp, -17, -17, //TODO configuration clipWidth + 17, clipHeight + tileHeight)) { counter++; if (!(xCharTemp == c.x && yCharTemp == c.y)) { drawTile(j + cellX, i + cellY, xTemp, yTemp, gInit); } drawCharacter(j + cellX, i + cellY, xTemp, yTemp, gInit); // drawItem(j + cellX, i + cellY, xTemp, yTemp, gInit); } if (!lastDrawn) { lastI = i + 1; } xTemp = xTemp + tileWidth / 2; yTemp = yTemp + tileHeight; } } lastDrawn = true; } /** * If there is a Character in the x, y, z position of the Board it returns * its name. Return null if there is no character. * * @param x * x * @param y * y * @param z * z * @return Character name */ public String isCharacter(int x, int y, int z) { String result = null; if (charactersPositions.containsKey(x + "_" + y + "_" + z)) { result = charactersPositions.get(x + "_" + y + "_" + z).toString(); } return result; } /** * If there is a Item in the x, y, z position of the Board it returns its * name. Return null if there is no item. * * @param x * x * @param y * y * @param z * z * @return Item name */// public String isItem(int x, int y, int z) {// String result = null;// if (itemsPositions.containsKey(x + "_" + y + "_" + z)) {// result = itemsPositions.get(x + "_" + y + "_" + z).toString();// }//// return result;//// } /** * Move a Character on the Board * * @param c * Character to move * @param oldX * old x * @param oldY * old y * @param oldZ * old z * @param newX * new x * @param newY * new y * @param newZ * new z * @param overwrite * true if you want to overwrite an existing Character that stays * in the new position * @return true if the movement was done * @todo use the Character c to know oldX, oldY, oldZ and to change c * coords. */ //Graphics g = null; public boolean moveCharacter(isoj2me.Character c, int oldX, int oldY, int oldZ, int newX, int newY, int newZ, boolean overwrite) { c.speed = 16; c.isMoving = true;//TODO verify// if ((newX >= cellX && newX <= cellX + width)// && (newY >= cellY && newY <= cellY + height)) {// &&// } if (charactersPositions.remove(oldX + "_" + oldY + "_" + oldZ) != null) { if (overwrite != true) { if (!charactersPositions.containsKey(newX + "_" + newY + "_" + newZ)) { charactersPositions.put(newX + "_" + newY + "_" + newZ, c); return true; } else { return false; } } else { charactersPositions .put(newX + "_" + newY + "_" + newZ, charactersPositions.get(oldX + "_" + oldY + "_" + oldZ)); charactersPositions.remove(oldX + "_" + oldY + "_" + oldZ); } return true; } else { return false; } } /** * Move an Item on the Board * * @param i * Item to move * @param oldX * old x * @param oldY * old y * @param oldZ * old z * @param newX * new x * @param newY * new y * @param newZ * new z * @param overwrite * true if you want to overwrite an existing Item that stays in * the new position * @return true if the movement was done * * @todo use the Item i to know oldX, oldY, oldZ and to change c coords. */// public boolean moveItem(isoj2me.Item i, int oldX, int oldY, int oldZ,// int newX, int newY, int newZ, boolean overwrite) {// if (itemsPositions.remove(oldX + "_" + oldY + "_" + oldZ) != null) {//// if (overwrite != true) {// if (!itemsPositions.containsKey(newX + "_" + newY + "_" + newZ)) {// itemsPositions.put(newX + "_" + newY + "_" + newZ, i);//// return true;//// } else {// return false;// }// } else {// itemsPositions// .put(newX + "_" + newY + "_" + newZ,// charactersPositions.get(oldX + "_" + oldY + "_"// + oldZ));// itemsPositions.remove(oldX + "_" + oldY + "_" + oldZ);// }// return true;// } else {// return false;// }// } private boolean onScreen(int xTemp, int yTemp, int boundMinWidth, int boundMinHeight, int boundWidth, int boundHeight) { xTemp += 16; yTemp += 8; if (xTemp > boundMinWidth && yTemp > boundMinHeight && xTemp < boundWidth + 5 && yTemp < boundHeight) { return true; } else { return false; } } private boolean onScreen(int xTemp, int yTemp, Graphics gInit) { xTemp += 16; //TODO configuration yTemp += 8; if (xTemp > -tileWidth && yTemp > 0 && xTemp < gInit.getClipWidth() + tileWidth && yTemp < canvas.getHeight() + tileHeight * 2) { return true; } else { return false; } } /** * Add a Character to the Board. * * @param c * Character object to add */ public void putCharacter(isoj2me.Character c) { charactersPositions.put(c.x + "_" + c.y + "_" + c.z, c); characters.put(c.name, c); } /** * Create and then add a Character to the Board. * * @param name * name of the Character * @param x * x * @param y * y * @param z * z */ public void putCharacter(String name, int x, int y, int z) { isoj2me.Character c = new isoj2me.Character(name, x, y, z); charactersPositions.put(x + "_" + y + "_" + z, c); characters.put(c.name, c); } /** * Add an Item to the Board * * @param i * Item object to add */// public void putItem(isoj2me.Item i) {// itemsPositions.put(i.x + "_" + i.y + "_" + i.z, i);// items.put(i.name, i);// } /** * Create and then add an Item to the Board. * * @param name * name of the Item * @param x * x * @param y * y * @param z * z */// public void putItem(String name, int x, int y, int z) {// isoj2me.Item i = new isoj2me.Item(name, x, y, z);// itemsPositions.put(x + "_" + y + "_" + z, i);// items.put(i.name, i);// } /** * Remove a Character from the Board * * @param c * Character object to remove */ public void removeCharacter(isoj2me.Character c) { charactersPositions.remove(c.x + "_" + c.y + "_" + c.z); characters.remove(c.name); } /** * Remove an Item from the Board * * @param i * Item object to remove */// public void removeItem(isoj2me.Item i) {// itemsPositions.remove(i.x + "_" + i.y + "_" + i.z);// items.remove(i.name);// } /** * This method change the shape of the basic tile. This affect the * coordinates of the tiles painted by the <b>draw()</b> method * * @param width * the width of the tile * @param height * the distance between the base of the tile file and the "floor" * of the basic tile */ public void setTileSize(int width, int height) { tileWidth = width; tileHeight = height; }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -