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

📄 boss.java

📁 Java射击小游戏源代码和图片都在里面可以直接玩的!
💻 JAVA
字号:

import java.util.Vector;
import javax.microedition.lcdui.Image;


public class Boss extends Plane {

	private Image imgBoss;
	public Image imgBullet;
	public int frameWidth;
	public int frameHeight;
	public Vector bulletVector;
	private int count;
	private int level;
	private int fireNum;
	
	
	public Boss(Image imgBoss, int frameWidth, int frameHeight,int level,ShotPlaneGameCanvas canvas,int kind) {
		super(imgBoss, frameWidth, frameHeight,kind);
		// TODO Auto-generated constructor stub
		this.imgBoss=imgBoss;
		this.frameWidth=frameWidth;
		this.frameHeight=frameHeight;
		this.level=level;
		this.canvas=canvas;
		imgBullet=ShotPlaneGameCanvas.createImage("/bullet.png");
		bullet=new Bullet(this,imgBullet,imgBullet.getWidth(),imgBullet.getHeight());
		energy=this.level*50;
		count=0;
		fireNum=0;
		bulletVector=new Vector();
	}

	public void setAlive(boolean isAlive) {
		// TODO Auto-generated method stub
		this.isAlive=isAlive;
		if(isAlive){
			setPosition(canvasWidth/2-frameWidth/2, -2*frameHeight);
		}
	}
	public void fire(){
		switch (fireNum) {
		case 0://单排平行子弹
			for (int i = 0; i <=5; i++) {
				bullet=new Bullet(this, imgBullet, imgBullet.getWidth(),imgBullet.getHeight());
				bullet.setCanvasSize(super.canvasWidth, super.canvasHeight);
				bullet.bossBulletDirection=Bullet.BULLET_MIDDLE;
				bullet.setAlive(getX()+frameWidth/2,getY()+frameHeight/2+(5-i)*10);
				bulletVector.addElement(bullet);	
			}
			fireNum++;
			break;
		case 1://3排平行子弹
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j <= 5; j++) {
					bullet=new Bullet(this, imgBullet, imgBullet.getWidth(),imgBullet.getHeight());
					bullet.setCanvasSize(super.canvasWidth, super.canvasHeight);
					bullet.bossBulletDirection=Bullet.BULLET_MIDDLE;
					bullet.setAlive(getX()+frameWidth/5+i*50, getY()+frameHeight/2+(5-j)*10);
					bulletVector.addElement(bullet);
				}	
			}
			fireNum++;  
			break;
		case 2://中间1排交叉
			for (int j = 0; j <=4; j++) {
				for (int i = 0; i <=2; i++) {
					bullet=new Bullet(this, imgBullet, imgBullet.getWidth(),imgBullet.getHeight());
					bullet.setCanvasSize(super.canvasWidth, super.canvasHeight);
					bullet.setAlive(getX()+frameWidth/2, getY()+frameHeight/2);
					bullet.bossBulletDirection=i;
					bulletVector.addElement(bullet);
				}
				bullet.tick();
			}
			fireNum++;
			break;
		default:
			fireNum=0;
			break;
		}
	}
	

	public void tick() {
		// TODO Auto-generated method stub
		
		if(isAlive&&getY()>=22){
			count++;
			if(count==25){
				fire();
				count=0;
			}	
		}
			
		if(getY()<22&&isAlive){
			move(0,speed);
		}
		if(energy>=0){	
			bullet.tick();
			
		}else{
			isAlive=false;
			canvas.hasBoss=false;
		}
		
	}
	public void init(){
		speed=3;
		setAlive(true);
		isExplod=false;
		bullet.setAlive(false);
		explodX=getX();
		explodY=getY();
		explodCount=0;
	}
}

⌨️ 快捷键说明

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