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

📄 enemy3456.java

📁 JVAV手机游戏单机版 连连看
💻 JAVA
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.util.Random;
public class Enemy3456 extends Sprite
{
    private boolean isAlive;
    public boolean isBulletAlive;
    private Random random;
    private Image img;
    private int offsetX;
    private int offsetY;
    public Sprite bullet;
    private int frameWidth, frameHeight;
    private int CanvasWidth, CanvasHeight;
    public Enemy3456(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("/bullet3456.png");
        bullet = new Sprite(img, img.getWidth(), img.getHeight());
        offsetX = (frameWidth - img.getWidth()) / 2;
        offsetY = frameHeight;
    }
    public void draw(Graphics g)
    {
        if (isAlive)
            paint(g);
        if (isBulletAlive)
            bullet.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)),  - frameHeight);
    }
    public boolean isAlive()
    {
        return isAlive;
    }
    public void tick()
    {
        if (isAlive)
        {
            move(0, 2);
            if (getY() > CanvasHeight)
                isAlive = false;
            if ((random.nextInt() & 0x7fffffff) % 8 == 0 && isBulletAlive ==
                false)
            {
                bullet.setPosition(getX() + offsetX, getY() + offsetY);
                isBulletAlive = true;
            }
        }
        if (isBulletAlive)
        {
            bullet.move(0, 4);
            if (bullet.getY() >= CanvasHeight)
                isBulletAlive = false;
        }
    }
    public void init()
    {
    	  isAlive = false;
    	  isBulletAlive = false;

    }
}

⌨️ 快捷键说明

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