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

📄 sprites.java~75~

📁 基于数字机顶盒J2me平台开发的互动游戏《金鼠财神》游戏
💻 JAVA~75~
字号:
package WealthGod106;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
class Sprites extends Sprite implements Runnable{
  protected Graphics g;
  protected Globals gl;
  protected SpriteManager sm;
  protected Image pImage;
  protected int iFrameCount;	//精灵帧数
  protected int m_rect_top,m_rect_bottom,m_rect_left,m_rect_right;
  protected int x,y,xc,yc,zc,xg,yg;
  protected int m_z_way;		//z轴当前变化方向
  protected int ENUM_STYPE;//1为once,2loop,3BUMPSTOP
  protected int SPRITE_TYPE = 0;//自己定义,默认为0
  protected int USERTYPE;//VIR=0;SMS=1
  protected String szShowID;
  protected String szPrize;
  protected static int m_iDrawIndex;
  protected int iFrameEnd;
  protected int iFrameStart;
  protected int m_iDrawWeightBmp;
  protected int m_iDrawWeightMem;
  protected int m_iDrawHeightBmp;
  protected int m_iDrawHeightMem;
  Thread t;

  public Sprites(Image image,int iWidth,int iHeight,int m_rect_top,int m_rect_bottom,int m_rect_left,int m_rect_right,
               int x,int y,int xc,int yc,int xg,int yg) {
   super(image,iWidth,iHeight);
   this.pImage = image;
   this.iFrameCount = iFrameCount;
   this.m_rect_top = m_rect_top;
   this.m_rect_bottom = m_rect_bottom;
   this.m_rect_left = m_rect_left;
   this.m_rect_right = m_rect_right;
   this.x = x;this.y = y;this.xc=xc;this.yc=yc;this.xg=xg;this.yg=yg;

   if (iFrameEnd == 0)
	iFrameEnd = iFrameCount;
   m_iDrawIndex = 0;
   this.m_iDrawWeightBmp = iWidth;
   this.m_iDrawHeightBmp = iHeight;
   m_iDrawWeightMem = m_iDrawWeightBmp;
   m_iDrawHeightMem = m_iDrawHeightBmp;
// setImage(pImage,m_iDrawWeightBmp,m_iDrawHeightBmp);
   gl = new Globals();
   this.g = gl.getGraphics();
   t = new Thread(this);
   t.start();
  }

  public void SetFrame(int iStart, int iEnd)
  {
    iFrameStart = iStart;
    iFrameEnd = iEnd;
    m_iDrawIndex = iStart;
  }
  public void SetImage(Image image,int width,int height){
    this.SetImage(image,width,height);
  }

  public int Draw(){
    m_iDrawWeightMem += (zc*m_z_way);
    m_iDrawHeightMem += (zc*m_z_way);
    g.setColor(255,255,255);
    Font indicator = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,Font.SIZE_LARGE);
    g.setFont(indicator);
    // draw ID
    if(szShowID != null && szShowID.length()!=0){
      g.drawString(szShowID, x, y,Graphics.BASELINE | Graphics.HCENTER);
    }
    // draw Prize
    if(szPrize != null && szPrize.length()!=0){
      g.drawString(szPrize, x, y+30, Graphics.BASELINE | Graphics.HCENTER);
    }
    if (++m_iDrawIndex>=iFrameCount)//this.getFrame()>=iFrameCount
    {
      m_iDrawIndex = iFrameStart;
      if (ENUM_STYPE == 1)
        return 1;
    }
    return ChangPos();
  }

  public int  ChangPos(){

    // x
        if (xg == 0 && x + m_iDrawWeightBmp > m_rect_right)
        {
          if (ENUM_STYPE == 3)
                  return 1;
          xg = 1;
        }
        if (xg == 1 && x < m_rect_left-10)
        {
          if (ENUM_STYPE == 3)
                  return 1;
          xg = 0;
        }

        if (xg == 0)
          x += xc;
        else
          x -= xc;

    // y
        if (yg == 0 && y + m_iDrawHeightBmp > m_rect_bottom - 101)
        {
          if (ENUM_STYPE == 3)
            return 1;
          yg = 1;
        }
        if (yg == 1 && y < m_rect_top - 50)
        {
          if (ENUM_STYPE == 3)
            return 1;
          yg = 0;
        }

        if (yg == 0)
          y += yc;
        else
          y -= yc;

        return 0;
  }

  public void setSpriteManager(SpriteManager sm){
    this.sm = sm;
  }

  public void appendMe(SpriteManager sm){
    sm.append(this);
  }

  public void run() {
    while(true){
      Draw();
      this.setPosition(x,y);
      try {
        Thread.sleep(20);
      }
      catch (InterruptedException ex) {
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -