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

📄 enemy2.java

📁 JVAV手机游戏单机版 连连看
💻 JAVA
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.util.Random;
public class Enemy2 extends Sprite
{
    private boolean isAlive;
    public boolean isBullet1Alive;
    public boolean isBullet2Alive;
    private boolean canAttack=false;
    public int energy=4;
    private Random random;
    private Image img;
    private int []offsetX = 
    {
        14,42
    };
    private int offsetY = 32;
    public Sprite bullet1;
    public Sprite bullet2;
    private int frameWidth, frameHeight;
    private int CanvasWidth, CanvasHeight;
    public Enemy2(Image image, int frameWidth, int frameHeight)
    {
        super(image, frameWidth, frameHeight);
        this.frameWidth = frameWidth;
        this.frameHeight = frameHeight;
        defineReferencePixel(frameWidth / 2, frameHeight / 2);
        random = new Random();
        img = RaidenMIDlet.createImage("/bullet5.png");
        bullet1 = new Sprite(img, img.getWidth(), img.getHeight());
        bullet2 = new Sprite(img, img.getWidth(), img.getHeight());
        bullet2.setTransform(TRANS_MIRROR ) ;
    }
    public void draw(Graphics g)
    {
        if (isAlive)
            paint(g);
        if (isBullet1Alive)
   
            bullet1.paint(g);

    
        if (isBullet2Alive)
       
            bullet2.paint(g);

       
    }
    public void setCanvasSize(int CanvasWidth, int CanvasHeight)
    {
        this.CanvasWidth = CanvasWidth;
        this.CanvasHeight = CanvasHeight;
    }
    public void setAlive(boolean isAlive)
    {
        this.isAlive = isAlive;
        if(isAlive){setPosition(((random.nextInt() & 0x7fffffff) % (CanvasWidth-frameWidth)),0);
          energy = 4;
        }
    }
    public boolean isAlive()
    {
        return isAlive;
    }
  /*  public boolean isBulletAlive()
    {
      //  return isBulletAlive;
    }*/
    public void tick()
    {
    	if(isAlive){
        move(0, 4);
        if (getY() > CanvasHeight / 3-frameHeight){
            setPosition(getX(), CanvasHeight / 3-frameHeight);
            canAttack=true;
          }
        if ((random.nextInt() & 0x7fffffff) % 8 == 0 && isBullet1Alive == false&& isBullet2Alive == false&&canAttack==true)
        {   
        	  bullet1.setPosition(getX()+offsetX[0],getY()+offsetY);
            bullet2.setPosition(getX()+offsetX[1],getY()+offsetY);
            isBullet1Alive = true;
            isBullet2Alive = true;
        }
       }
        if (isBullet1Alive)
        {
            bullet1.move(-5, 5);
            if(bullet1.getY()>=CanvasHeight||bullet1.getX()<=0)isBullet1Alive=false;
            
        }
        if (isBullet2Alive)
        {
            bullet2.move(5, 5);
            if(bullet2.getY()>=CanvasHeight||bullet2.getX()>=CanvasWidth)isBullet2Alive=false;
            
        }                    
 
        
    }
    public void init()
    {
    	  isAlive = false;
    	  isBullet1Alive = false;
        isBullet2Alive = false;
        canAttack=false;
        energy=4;
    }    
}

⌨️ 快捷键说明

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