import com.nttdocomo.ui.Graphics; import com.nttdocomo.ui.Image; public class Ball extends Object // ボールの情報を保持 { /* --- Field --- */ private Image image; private int x,y; private int vx,vy; private int rx,ry; // 移動可能範囲 /* --- Constructor --- */ public Ball(Image image) { this.image=image; } /* --- 初期化 --- */ public void setPosition(int x,int y) { this.x=x; this.y=y; vx=vy=0; } public void setRange(int x,int y) { this.rx=x; this.ry=y; } /* --- 移動 --- */ public void left() { vx=Math.max(vx-1,-5); } public void right() { vx=Math.min(vx+1, 5); } public void jump() { if (y+vy==ry) { vy=-14; } } public void crash(Ball target) { target.vx=-target.vx+vx/2; target.vy=-target.vy+vy/2; vx=-vx; vy=-vy; } public void translate() { if (x+vx<0) { vx=(0-x); } else if (x+vx>rx) { vx=(rx-x); } vy=vy+2; if (y+vy>=ry && vy>0) { vy=(ry-y); } x+=vx; y+=vy; } /* --- 情報 --- */ public int getX() { return x; } public int getY() { return y; } public Image getImage() { return image; } public boolean isNear(Ball target) { return (Math.abs((target.x+target.vx)-(x+vx))