⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 item.java

📁 斜45度游戏范例
💻 JAVA
字号:
package isoj2me;import java.util.Hashtable;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;/** * <p>Title: isoj2me: J2ME Isometric Engine</p> * <p>Description: An engine/framework for isometric games (like japanese RPGs) for mobile devices supporting J2ME (MIDP 1.0). This engine will manage maps, objects and characters. Visit http://sourceforge.net/projects/isoj2me</p> * <p>Copyright: Copyright (c) 2004</p> * <p>License: Lesser GPL (http://www.gnu.org)</p> * <p>Company: Mondonerd.com</p> * @author Massimo Maria Avvisati * @version 0.2 */public class Item {  public boolean isMoving = false;  public String name = "";  public int x = 0;  public int y = 0;  public int z = 0;  private int frame = 0;  private Hashtable actions = new Hashtable(6);  private String currentAction = null;  private Hashtable frames = new Hashtable();  public Item() {  }  /**   * Create a new Item.   * @param name Name/code of the Item   */  public Item(String name) {    this.name = name;  }  /**   * Create a new Item   * @param name Name or code of the Item   * @param x x on the map   * @param y y on the map   * @param z layer on the map   */  public Item(String name, int x, int y, int z) {    this.name = name;    this.x = x;    this.y = y;    this.z = z;  }  /**   * This draw the Item at given coordinates on given Graphics. This method also change the current frame (if more than one) for the current action.   * @param x x   * @param y y   * @param g given Graphics where to paint the Item   */  public void draw(int x, int y, Graphics g) {    if (currentAction != null && actions.containsKey(currentAction)) {      String tempFrame = "";      if (frame > Integer.parseInt(actions.get(currentAction).toString())) {	frame = 0;      }      if (frame > 0) {	tempFrame = frame + "";      }      Image temp_image = Utility.loadTile(currentAction + tempFrame, frames);      //int temp_x = x + (width - temp_image.getWidth()) / 2;      g.drawImage(temp_image, x, y - temp_image.getHeight(),		  g.TOP | g.LEFT);      changeFrame();    }  }  /**   * Store an action into this Item action list.   * @param action basic string used to load frames   * @param frames number of frames for this action   */  public void putAction(String action, int frames) {    actions.put(action, frames + "");  }  /**   * This return the name that identify the action that is performed in this moment by the Item   * @return basic string for this action   */  public String getCurrentAction() {    return currentAction;  }  /**   * Calculate the current frame and return the associated Image object   * @return current Image used   */  public Image getCurrentImage() {    Image temp_image = null;    if (currentAction != null && actions.containsKey(currentAction)) {      String tempFrame = "";      if (frame > Integer.parseInt(actions.get(currentAction).toString())) {	frame = 0;      }      if (frame > 0) {	tempFrame = frame + "";      }      temp_image = Utility.loadTile(currentAction + tempFrame, frames);    }    return temp_image;  }  /**   * Set the current action for this Item. The action have to be already in the actions list   * @param action name of the action to perform   */  public void setCurrentAction(String action) {    if (actions.containsKey(action)) {      currentAction = action;    }  }  private void changeFrame() {    if (actions.containsKey(currentAction)) {      int numberOfFrames = Integer.parseInt(actions.get(currentAction).toString());      frame++;      if (frame > numberOfFrames) {	frame = 0;      }    }    else {      frame = 0;    }  }  /**   * Return the name of the Item   * @return name of the Item   */  public String toString() {    return this.name;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -