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){//相对移动 sprite.move(dx,dy); }
public void moveto(int x,int y){//绝对移动 sprite.setPosition(x,y); }
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++) { charhash[i]=-1;//没有代表此字符的图片 } 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){ sprite.setFrame(charhash[hashcode]); sprite.paint(g); } }
public void drawString(String str, int x, int y){ int length=str.length(); for (int i = 0; i < length; i++) { drawChar(str.charAt(i),x+width*i,y); } }