⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bomb.java

📁 手机泡泡堂 源码
💻 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 + -