📄 actor.java
字号:
import javax.microedition.lcdui.Graphics;
/*
* Actor.java
*
* Created on 2007年9月17日, 上午9:45
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author wangquan84
*/
public abstract class Actor {
/** Creates a new instance of Actor */
public Actor() {
}
public void initData(){
}
public void initSpiritDate(String indexbinName,String pngName,String indexcombin){
spirit = new Spirit();
spirit.getTypeData(indexbinName,pngName,indexcombin);
spirit.setAction((byte) 0);
spirit.setCurrentFrame(-1);
}
public void setAction(byte action) {
spirit.setAction(action);
}
public void setCurrentFrame(int currentFrame) {
spirit.setCurrentFrame(currentFrame);
}
public boolean lastFrame() {
return spirit.lastFrame();
}
public byte getAction() {
return spirit.getAction();
}
public void draw(Graphics graphics) {
spirit.draw(graphics, iPosX, iPosY);
}
public void cleanSpirit() {
spirit.clean();
spirit = null;
}
public void changeMyState(){
}
public void initCenterXY(){
}
public void clean(){
}
//判断2个由动作编辑的物体是否向碰撞
public boolean isCollide(Actor Actor,Actor enemyActor){
//rMLeftX 为矩形的左上X坐标
int rMLeftX = (Actor.getIPosX() - (Actor.getIWidth() >> 1)) >> 8;
//rMLeftY 为矩形的左上Y坐标
int rMLeftY = (Actor.getIPosY() - Actor.getIHeight()) >> 8;
//rELeftX 为矩形的左上X坐标
int rELeftX = (enemyActor.getIPosX() - (enemyActor.getIWidth() >> 1)) >> 8;
//rELeftY 为矩形的左上Y坐标
int rELeftY = (enemyActor.getIPosY() - enemyActor.getIHeight()) >> 8;
return Tool.isIntersectingRect(rMLeftX, rMLeftY,
Actor.getIWidth() >> 8, Actor.getIHeight() >> 8,
rELeftX, rELeftY, enemyActor.getIWidth() >> 8, enemyActor
.getIHeight() >> 8);
}
// 画法是Center的物体与画法是TOPLEFT的物体碰撞
public boolean isCollideInCenterTopLeft(Actor actor, Actor actor2) {
// 子弹矩形的左上X,Y坐标
int rBLeftX = (actor.getIPosX() - (actor.getIWidth() >> 1)) >> 8;
int rBLeftY = (actor.getIPosY() - (actor.getIHeight() >> 1)) >> 8;
// rALeftX 为矩形的左上X,Y坐标
int rALeftX = actor2.getIPosX() >> 8;
int rALeftY = actor2.getIPosY() >> 8;
return Tool.isIntersectingRect(rBLeftX, rBLeftY,
actor.getIWidth() >> 8, actor.getIHeight() >> 8, rALeftX,
rALeftY, actor2.getIWidth() >> 8, actor2.getIHeight() >> 8);
}
// 判断2物体碰撞画法是VCENTER的碰撞
public boolean isCollideInCenter(Actor actor, Actor actor2) {
// 子弹矩形的左上X,Y坐标
int rBLeftX = (actor.getIPosX() - (actor.getIWidth() >> 1)) >> 8;
int rBLeftY = (actor.getIPosY() - (actor.getIHeight() >> 1)) >> 8;
// rALeftX 为矩形的左上X,Y坐标
int rALeftX = (actor2.getIPosX() - (actor2.getIWidth() >> 1)) >> 8;
int rALeftY = (actor2.getIPosY() - (actor2.getIHeight() >> 1)) >> 8;
return Tool.isIntersectingRect(rBLeftX, rBLeftY,
actor.getIWidth() >> 8, actor.getIHeight() >> 8, rALeftX,
rALeftY, actor2.getIWidth() >> 8, actor2.getIHeight() >> 8);
}
public boolean isCollideInLeftTop(Actor actor, Actor actor2) {
// actor矩形的左上X,Y坐标
int rBLeftX = actor.getIPosX() >> 8;
int rBLeftY = actor.getIPosY() >> 8;
// actor2矩形的左上X,Y坐标
int rALeftX = actor2.getIPosX() >> 8;
int rALeftY = actor2.getIPosY() >> 8;
return Tool.isIntersectingRect(rBLeftX, rBLeftY,
actor.getIWidth() >> 8, actor.getIHeight() >> 8, rALeftX,
rALeftY, actor2.getIWidth() >> 8, actor2.getIHeight() >> 8);
}
/*
* 根据轨迹数据文件设置一些参数
*
*/
public void initOrbit(byte[] orbitData, int orbitType) {
setIWidth(orbitData[orbitType * 39 + 2] << 8); //设置碰撞宽度
setIHeight(orbitData[orbitType * 39 + 3] << 8); //设置碰撞高度
enemyLife = orbitData[orbitType * 39 + 4]; //设置生命值
speed = orbitData[orbitType * 39 + 7]; //设置速度
iOccurType = orbitData[orbitType * 39 + 8]; //设置出现位置
iOffX = orbitData[orbitType * 39 + 9]; //设置X便移的距离
iOffY = orbitData[orbitType * 39 + 10]; //设置Y便移的距离
initEnemyXY(iOccurType); //设置敌机出现的XY坐标
iProcess = orbitData[orbitType * 39 + 11]; //设置飞机飞行轨迹的几个阶段
iProcessData = new int[3*iProcess];
processCount = 0;
processTimeCount = 0;
for (int i = 0; i < iProcess; i++) {
//阶段
iProcessData[i * 3 + 0] = orbitData[orbitType * 39 + 12 + 3 * i];
//阶段轨迹
iProcessData[i * 3 + 1] = orbitData[orbitType * 39 + 13 + 3 * i];
//阶段子弹
iProcessData[i * 3 + 2] = orbitData[orbitType * 39 + 14 + 3 * i];
}
}
public void initEnemyXY(int occurType) {
int newX = -GameConstant.iACTIVE_RECT + iOffX;
int newY = -GameConstant.iACTIVE_RECT + iOffY;
switch (occurType) {
case 0: // 正前方
iPosX = ((GameConstant.iSCREEN_WIDTH >> 1) + iOffX) << 8;
iPosY = newY << 8;
break;
case 1: // 左前方
iPosX = newX << 8;
iPosY = newY << 8;
break;
case 2: // 左上方
iPosX = newX << 8;
iPosY = (newY + (GameConstant.NEW_iSCREEN_HEIGHT / 3)) << 8;
break;
case 3: // 左中
iPosX = newX << 8;
iPosY = (newY + (2 * GameConstant.NEW_iSCREEN_HEIGHT / 3)) << 8;
break;
case 4: // 左下方
iPosX = newX << 8;
iPosY = (newY + GameConstant.NEW_iSCREEN_HEIGHT) << 8;
break;
case 5: // 右前方
iPosX = (newX + GameConstant.NEW_iSCREEN_WIDTH) << 8;
iPosY = newY << 8;
break;
case 6: // 右上方
iPosX = (newX + GameConstant.NEW_iSCREEN_WIDTH) << 8;
iPosY = (newY + (GameConstant.NEW_iSCREEN_HEIGHT / 3)) << 8;
break;
case 7: // 右中
iPosX = (newX + GameConstant.NEW_iSCREEN_WIDTH) << 8;
iPosY = (newY + (2 * GameConstant.NEW_iSCREEN_HEIGHT / 3)) << 8;
break;
case 8: // 右下方
iPosX = (newX + GameConstant.NEW_iSCREEN_WIDTH) << 8;
iPosY = (newY + GameConstant.NEW_iSCREEN_HEIGHT) << 8;
break;
case 9: // 正后方
break;
}
}
public int getIPosX() {
return iPosX;
}
public void setIPosX(int posX) {
iPosX = posX;
}
public int getIPosY() {
return iPosY;
}
public void setIPosY(int posY) {
iPosY = posY;
}
public int getIHeight() {
return iHeight;
}
public void setIHeight(int height) {
iHeight = height;
}
public int getIWidth() {
return iWidth;
}
public void setIWidth(int width) {
iWidth = width;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int[] getIProcessData() {
return iProcessData;
}
public int getIProcess() {
return iProcess;
}
public int getAngle() {
return angle;
}
public void setAngle(int angle) {
this.angle = angle;
}
public boolean isNotUsed() {
return isNotUsed;
}
public void setNotUsed(boolean isNotUsed) {
this.isNotUsed = isNotUsed;
}
public int getEnemyLife() {
return enemyLife;
}
public void setEnemyLife(int enemyLife) {
this.enemyLife = enemyLife;
}
/**当前位置X*/
public int iPosX;
/**当前位置Y*/
public int iPosY;
/**碰撞宽*/
private int iWidth;
/**碰撞高*/
private int iHeight;
// // 是否被锁定
//private boolean bLock = false;
//private byte bLockNo;
// 生命值
private int enemyLife;
/**出现位置*/
private int iOccurType;
/**位置X偏移*/
private int iOffX;
/**位置Y偏移*/
private int iOffY;
/**速度半径*/
private int speed;
/**阶段数,阶段计数器*/
private int iProcess;
/**阶段数据,0 - 时间间隔,帧 1 - 轨迹类型, 2 - 子弹类型*/
private int[] iProcessData;
//阶段记数
public int processCount = 0;
//阶段用时记数
public int processTimeCount = 0;
private int angle; //角度
private boolean isNotUsed; //是否未使用
private Spirit spirit; //动作精灵
// public boolean isBLock() {
// return bLock;
// }
//
// public void setBLock(boolean lock) {
// bLock = lock;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -