?? character.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 Character { 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 Character() { } /** * Create a new character. * @param name Name/code of the character */ public Character(String name) { this.name = name; } /** * Create a new character * @param name Name or code of the character * @param x x on the map * @param y y on the map * @param z layer on the map */ public Character(String name, int x, int y, int z) { this.name = name; this.x = x; this.y = y; this.z = z; } /** * This draw the character 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 character */ 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 character 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 character * @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 character. 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 Character * @return name of the Character */ public String toString() { return this.name; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -