| public class ImageTools { protected ImageTools() {} public static Image getImage(String str){ Image img=null; try { img = Image.createImage(str); } catch (Exception ex) finally{ return img; } } } |
| public class GameObject { public Sprite sprite;//内置的Sprite public boolean alive;//存活标记 private int lifecount=0;//生命周期计数器 public int lifetime=0;//生命周期,以桢为单位 public int speed=0;//动画桢更新速度,(0至无穷,0代表每一桢跟新一个画面) private int animcount=0;// /动画桢更新计数器 public GameObject(Image img,int width,int height){ sprite=new Sprite(img,width,height); reset(); } public void move(int dx,int dy) public void moveto(int x,int y) public void update(){//更新状态,动画桢更新,生命周期更新 if(!alive) return; if(++animcount>speed){ animcount=0; sprite.nextFrame(); if(lifetime!=0 && ++lifecount>lifetime) alive=false; } } public void paint(Graphics g) public void reset() } |
| public class Font { Sprite sprite; //Sprite int width,height; //每个char的尺寸 int[] charhash; //储存1-127个常见字符在sprite的frameseq中的位置 Graphics g; public Font(Graphics g,Image img, int width, int height, char[] chars) { this.g=g; sprite=new Sprite(img,width,height); this.width=width; this.height=height; charhash=new int[128]; for (int i = 0; i < charhash.length; i++) Character c; for (int i = 0; i < chars.length; i++) { c=new Character(chars[i]); charhash[c.hashCode()]=i; } } public void drawChar(char ch, int x, int y){ Character c=new Character(ch); int hashcode=c.hashCode(); sprite.setPosition(x,y); if(hashcode>=0) } public void drawString(String str, int x, int y){ int length=str.length(); for (int i = 0; i < length; i++) } } |
用户评论