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

📄 spritemanager.java~1~

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

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.*;

public class SpriteManager extends LayerManager implements Runnable{
  protected Graphics g;
  protected Sprites sp;
  protected Sprites sp1;
  protected Sprites sp2;
  protected Image canyu,prize1,prize2;
  protected Sprites sp_canyu1,sp_canyu2,sp_prize1,sp_prize2,sp_prize3,sp_prize4;
  Thread t;
  public SpriteManager(Graphics g) {
    this.g = g;
    sp = null;
    sp1 = null;
    sp2 = null;
    try {
      canyu = Image.createImage("/res/canyu.png");
      prize1 = Image.createImage("/res/prize1.png");
      prize2 = Image.createImage("/res/prize2.png");
    }
    catch (IOException ex) {
    }

    t = new Thread(this);
    t.start();
  }

  public void run()
  {
    while(true)
    {
      for(int i=0;i<this.getSize();i++)
      {
        sp = (Sprites) this.getLayerAt(i);
        sp.m_iDrawIndex++;
        sp.nextFrame();
        if(sp != null)
        {
          if(sp.Draw() == 1){
            this.remove(sp);
            sp = null;
          }
          else
          {
            if(sp.SPRITE_TYPE == 1)
              sp1 = sp;
            if(sp.SPRITE_TYPE == 2)
              sp2 = sp;
            if(sp1 != null && sp2 != null){
              if (Math.abs(sp1.x - sp2.x) < 40 && Math.abs(sp1.y - sp2.y) < 40) {
 //               if(sp2.USERTYPE == 1)
                  CreatePrizeSprite_SMS(sp2.x,sp2.y);
 //               if(sp2.USERTYPE == 0)
//                  CreatePrizeSprite_VIR(sp2.x,sp2.y);
                this.remove(sp2);
                sp2 = null;
              }
            }
          }
        }
      }
      try {
          Thread.sleep(20);
        }
        catch (InterruptedException ex) {}
    }
  }

  static int g_iTotal1= 0; //MO总数
  public int GetPrize_SMS()
  {
        g_iTotal1 += 1;
        int iTemp = g_iTotal1 % 100 ;
        if ( iTemp == 0 )
                return 0;
        if ( iTemp % 99 == 0 )
                return 5;
        if ( iTemp % 60 == 0 )
                return 3;
        if ( iTemp % 51 == 0 )
                return 2;
        if ( iTemp % 9 == 0 )
                return 1;
        return 0;
    }

  static int g_iTotal2= 0; //VIR-MO总数
  public int GetPrize_VIR()
  {
       g_iTotal2 += 1;
       int iTemp2 = g_iTotal2 % 100 ;
       if ( iTemp2 == 0 )
               return 0;
       if ( iTemp2 % 99 == 0 )
               return 5;
       if ( iTemp2 % 60 == 0 )
               return 3;
       if ( iTemp2 % 51 == 0 )
               return 2;
       if ( iTemp2 % 9 == 0 )
               return 1;
       return 0;
   }

    static int g_sms_prize = 0;
    public void CreatePrizeSprite_SMS(int x,int y){
      int iPrize = GetPrize_SMS();
      if(iPrize <= 0)
      {
        sp_canyu1 = new Sprites(canyu,169,152,0,400,0,600,x,y,0,0,0,0);
        sp_canyu1.ENUM_STYPE = 1;
        this.insert(sp_canyu1,0);
     }
      else
      {
        g_sms_prize++;
        if(g_sms_prize % 2 == 0)
        {
          sp_prize1 = new Sprites(prize1, 113, 120, 0, 400, 0, 600, x, y, 0, 0, 0,0);
          sp_prize1.ENUM_STYPE = 1;
          this.insert(sp_prize1,0);
        }
        else
        {
          sp_prize2 = new Sprites(prize2, 113, 120, 0, 400, 0, 600, x, y, 0, 0, 0, 0);
          sp_prize2.ENUM_STYPE = 1;
          this.insert(sp_prize2,0);
        }

      }
    }

    static int g_vir_prize = 0;
    public void CreatePrizeSprite_VIR(int x,int y){
      int iPrize2 = GetPrize_VIR();
      if(iPrize2 <= 0)
      {
        g_vir_prize++;
        if(g_vir_prize % 2 == 0)
        {
          sp_prize3 = new Sprites(prize1,113,120,0,400,0,600,x,y,0,0,0,0);
          sp_prize3.ENUM_STYPE = 1;
          this.insert(sp_prize3,0);
        }
        else
        {
          sp_prize4 = new Sprites(prize2,113,120,0,400,0,600,x,y,0,0,0,0);
          sp_prize4.ENUM_STYPE = 1;
          this.insert(sp_prize4,0);
        }
      }
      else
      {
        sp_canyu2 = new Sprites(canyu,169,152,0,400,0,600,x,y,0,0,0,0);
        sp_canyu2.ENUM_STYPE = 1;
        this.insert(sp_canyu2,0);
      }
    }

}

⌨️ 快捷键说明

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