?? bomb.java
字號:
package game;
import javax.microedition.lcdui.*;
import java.util.*;
import java.lang.Integer;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
//泡泡游戲特殊類
public class Bomb extends Canvas{
//begin
//--------------------泡泡通用模塊----------------------------
//一個人物所有泡泡的通用屬性
//泡泡類消息
final static int MSG_NOTHING = -1;//無事件
final static int MSG_DOING = 7;//發生
final static int MSG_END = 8;//停止
public int iCurrentMsg = MSG_NOTHING;
//泡泡屬性
int nMight = 0; //泡泡威力
int nBombTotal = 8;//泡泡總數
int nBombNum = 5;//泡泡數
static int nBlastNum = -1;
static int nRunTime = 0;
boolean bStart = false;
//泡泡膨脹狀態通用屬性--------------------
String sSwellImgPath;//泡泡膨脹的圖片路徑
Image imgSwell; //膨脹圖片
int nSwellImgHeight = 16,nBombImgWidth = 16;//泡泡膨脹圖片尺寸
final byte btSwellTotalFrame = 3;//泡泡膨脹總幀數
byte btSwellTotalCol = 4, btSwellTotalRow = 1; //泡泡膨脹圖片文件分割的總行列數
static byte [] arr_btSwellAnimationFrame={0,1,2};//泡泡膨脹動畫數組
//泡泡爆炸狀態通用屬性----------------------
String sBlastImgPath;//泡泡爆炸圖片路徑
Image imgBlast;//泡泡爆炸圖片
int nBlastImgHeight = 16,nBalstImgWidth = 16;//泡泡爆炸圖片尺寸
final byte btBalstTotalFrame = 5;//泡泡爆炸總幀數
byte btBalstTotalCol = 4, btBalstTotalRow = 2; //泡泡爆炸圖片文件分割的總行列數
final static byte [] arr_btBalstAnimationFrame = {0,7,5,6,4};//泡泡爆炸動畫數組
//泡泡死亡狀態通用屬性----------------------
String sDeathImgPath;//死亡圖片路徑
Image imgDeath;//死亡圖片
public static boolean bIsDead = false;
int nDeathImgHeight = 16,nDeathImgWidth = 16;//死亡圖片尺寸
final byte btDeathTotalFrame = 5;//死亡動畫總幀數
byte btDeathTotalCol = 1, btDeathTotalRow = 7; //圖片文件分割的總行列數
final static byte [] arr_btDeathAnimationFrame = {0,1,2,3,4};//死亡動畫數組
Vector popQueue = new Vector(10);
//public Pop p;
//----------------------------泡泡通用模塊--------------------------------
//end
//begin
//-----------------------------泡泡隊列模塊-----------------------------------
//每個泡泡必備的屬性
//AnimationModule
//動畫類
public static class AnimationModule{
//動畫通用屬性
byte[] btCurrentFrame = {-1}; //當前幀號
int btCurrentIndex = 0; //當前幀在圖片的索引值
int btCurrentCol = 0, btCurrentRow = 0; //當前幀在圖片的行列位置
byte btAtCol = 0,btAtRow = 0;
int ix = 0, iy = 0; //所在的坐標
byte iIntervalTime = 0;
byte iExistTime =0;
byte iRunTime=-1;
public AnimationModule(byte existTime){
btCurrentFrame[0]=-1;
btCurrentIndex=0;
btCurrentCol=0;
btCurrentRow=0;
btAtCol=0;
btAtRow=0;
iExistTime=existTime;
iRunTime=-1;
}
}
//為泡泡隊列分配空間
public void createPopQueue(Pop p){
p.amSwell = new AnimationModule((byte)(btSwellTotalFrame*3));
p.amBlast = new AnimationModule((byte)(btBalstTotalFrame));
p.amDeath = new AnimationModule((byte)(btDeathTotalFrame*3));
}
public static class Pop{
int iTest;
//泡泡未啟動狀態-------------------------
final public static byte MSG_NOTHING = -1;
public static byte btCurrentMsg = MSG_NOTHING;
final public static byte MSG_SWELL = 6; //泡泡膨脹狀態
AnimationModule amSwell;
final public static byte MSG_BLAST = 7;//泡泡爆炸狀態
AnimationModule amBlast;
final public static byte MSG_DEAD = 8;//泡泡死人狀態
AnimationModule amDeath;
final public static byte MSG_CLEAR = 9;//泡泡清除狀態
final public static byte MSG_END = 10;//泡泡結束狀態
Pop(){
}
}
//-----------------------------泡泡類模塊-----------------------------------
//end
//泡泡構造函數
public Bomb(String sPath1,String sPath2,String sPath3) {
sSwellImgPath = sPath1;
sBlastImgPath = sPath2;
sDeathImgPath = sPath3;
try{
imgSwell = Image.createImage(sSwellImgPath);
imgBlast = Image.createImage(sBlastImgPath);
imgDeath = Image.createImage(sDeathImgPath);
}catch(Exception e){
e.printStackTrace() ;
}
}
//泡泡類動畫幀自增方法
public void nextBombFrame(Pop p){
switch(p.btCurrentMsg){
case Pop.MSG_SWELL://放泡泡消息
p.amSwell.btCurrentIndex//放泡泡動畫指向下一指幀在圖片的索引值
=nextFrame(this.btSwellTotalFrame,
p.amSwell.btCurrentFrame,
this.arr_btSwellAnimationFrame);
//if(++p.amSwell.iRunTime>=p.amSwell.iExistTime){
// p.btCurrentMsg=Bomb.Pop.MSG_BLAST;
//}
break;
case Pop.MSG_BLAST://爆炸消息
p.amBlast.btCurrentIndex//爆炸動畫指向下一指幀在圖片的索引值
=nextFrame(this.btBalstTotalFrame,
p.amBlast.btCurrentFrame,
this.arr_btBalstAnimationFrame);
break;
case Pop.MSG_DEAD://死亡消息
p.amDeath.btCurrentIndex//死亡動畫指向下一指幀在圖片的索引值
=nextFrame(this.btDeathTotalFrame,
p.amDeath.btCurrentFrame, this.arr_btDeathAnimationFrame);
break;
case Pop.MSG_END:
break;
}
}
//泡泡類繪制圖片方法
public void paintBomb(Graphics g,Pop p){
switch(p.btCurrentMsg){
case Pop.MSG_SWELL://放泡泡消息
this.paintImage(g, p.amSwell.ix, p.amSwell.iy, this.imgSwell, //繪制泡泡
this.btSwellTotalRow, this.btSwellTotalCol,
p.amSwell.btCurrentIndex);
break;
case Pop.MSG_BLAST://爆炸消息
this.paintImage(g,p.amBlast.ix,p.amBlast.iy,this.imgBlast,//繪制爆炸
this.btBalstTotalRow,this.btBalstTotalCol,
p.amBlast.btCurrentIndex);
break;
case Pop.MSG_DEAD://死亡消息
this.paintImage(g,p.amDeath.ix,p.amDeath.iy,this.imgDeath,//繪制死亡
this.btDeathTotalRow,this.btDeathTotalCol,
p.amDeath.btCurrentIndex);
break;
case Pop.MSG_END:
break;
}
}
/*---------------------------------繪圖通用模塊---------------------------------*/
/*-----------序列數組----------
//動畫幀自增通模塊
//bTotFrame 圖片總幀數
//btCurFrame[] 當前幀數,為指針型
//arr_btBombAnimation 動畫序列數組
------------------------------*/
//返回動畫下一幀的貼圖索引值
public byte nextFrame(byte btTotFrame,byte[] btCurFrame,byte [] arr_btBombAnimation){
if (++btCurFrame[0] >= btTotFrame) {//或者當前移動幀數大于移動總幀數,
btCurFrame[0] = 0; //則幀數從頭開始,指向第0張圖片
}
byte btCurIndex = arr_btBombAnimation[btCurFrame[0]]; // 從序列表里獲得當前圖片幀數
return btCurIndex;
}
/*-------------------------------------------------------
* 函數名: paintImage
*
* 功能: 在指定坐標處繪出圖片的部分區域
*
* 參數說明:
* -g 上級圖形類
* -x 要繪圖的x點
* -y 要繪圖的y點
* -row 圖片被分割成row行
* -col 圖片被分割成col列
* -index 繪圖區域在圖片文件中行列的索引值
*-------------------------------------------------------*/
public void paintImage(Graphics g,int x,int y,Image img,
int row,int col,int index){
int h=0;
try{
h= img.getHeight()/row;//求得每單元圖的高寬
}catch(Exception e){
e.printStackTrace();
}
int w = img.getWidth()/col;
int c = index % col;//求得當前單單元圖的行列
int r = index / col;
g.setClip(x,y-h,w,h);//設置繪圖區域
g.drawImage(img,
x - c * w,
y - r * h - h,
0);
g.setClip(0, 0, getWidth(), getHeight());//恢復繪圖區域
}
public void paint(Graphics g){
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -