抽象公共类,复用公共方法为多个对象(二)

2014-11-23 17:52:32 · 作者: · 浏览: 35
royBody(body);
}
}


public int getAnimIndex() {
return animIndex;
}


public void setAnimIndex(int animIndex) {
this.animIndex = animIndex;
}


public int getCountDown() {
return countDown;
}


public void setCountDown(int countDown) {
this.countDown = countDown;
}


public float[] getDestoryPoint() {
return destoryPoint;
}


public void setDestoryPoint(float[] destoryPoint) {
this.destoryPoint = destoryPoint;
}


public float getDestoryAngle() {
return destoryAngle;
}


public void setDestoryAngle(float destoryAngle) {
this.destoryAngle = destoryAngle;
}


}

package org.liky.angrybird.vo;


import org.jbox2d.dynamics.Body;
import org.liky.angrybird.util.Globals;
import org.liky.angrybird.util.ImageUtils;


import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;


public class Wood extends Item {


public Wood(Body body) {
setBody(body);
setWidth(Globals.PIECE_WIDTH * 3);
setHeight(Globals.PIECE_HEIGHT / 2);
setLife(100);
}


public void drawItem(Canvas canvas, Paint paint, Point nowPosition) {


if (getLife() > 300) {
canvas.drawBitmap(ImageUtils.getWood(0), getBody().getPosition().x
* Globals.RATE - getWidth() / 2 + nowPosition.x, getBody()
.getPosition().y
* Globals.RATE
- getHeight()
/ 2
+ nowPosition.y, paint);
} else if (getLife() > 100) {
canvas.drawBitmap(ImageUtils.getWood(1), getBody().getPosition().x
* Globals.RATE - getWidth() / 2 + nowPosition.x, getBody()
.getPosition().y
* Globals.RATE
- getHeight()
/ 2
+ nowPosition.y, paint);
} else if (getLife() > 0) {
canvas.drawBitmap(ImageUtils.getWood(2), getBody().getPosition().x
* Globals.RATE - getWidth() / 2 + nowPosition.x, getBody()
.getPosition().y
* Globals.RATE
- getHeight()
/ 2
+ nowPosition.y, paint);
} else {
setCountDown(getCountDown() - 1);
if (getCountDown() == 0) {
setCountDown(2);
setAnimIndex(getAnimIndex() + 1);
if (getAnimIndex() == 15) {
setAnimIndex(14);
}
}


canvas.drawBitmap(ImageUtils.getWoodDestory(getAnimIndex()),
getDestoryPoint()[0] - Globals.PIECE_WIDTH / 2
+ nowPosition.x, getDestoryPoint()[1]
- Globals.PIECE_HEIGHT + nowPosition.y, paint);
}
}
}