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

📄 enemysprite16.java

📁 经典FC游戏《超惑星战记》的J2ME版本!!功能基本上都实现了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width +16 || x < -16 || y < -16
					|| y > TankGameCanvas.height + 16) {
				return ;
			}
			attack=0;
			if(dx<=0){
				frameCnt=16;
			}else{
				frameCnt=17;
			}
			if(timeCnt++%40==0){
				xSpeed=6;
				if(x-gm.lgr.tankSprite.x>=0){
					xSpeed=-6;
				}
				if(x-gm.lgr.tankSprite.x==0){
					ySpeed=0;
				}else{
					ySpeed=Math.abs(xSpeed*(y-gm.lgr.tankSprite.y)/(x-gm.lgr.tankSprite.x));
				}
				if(y-gm.lgr.tankSprite.y>0){
					ySpeed=-ySpeed;
				}
				gm.creatEnemyBullet(x+4, y+4, xSpeed, ySpeed, 4);
			}
			if(checkTileCollisionHorizon2()){
				dx=-dx;
			}
			
			if(checkTileCollisionVertical()){
				dy=-dy;
			}
			if(checkBulletDamage()){
				frameCnt=-1;
			}
			x+=dx;
			y+=dy;
			pow-=attack;
			if(pow<=0){
				gm.creatBombEffect(x-8, y-8, 1);
				isHidden=true;					
				if(timeCnt%4==0){
					gm.creatGoods(x, y, Goods.HOV);
				}
			}
		}
	}
}
/**
 * ---------------水母-------------------------------
 */
class Jellyfish extends EnemySprite16{

	boolean isJump;
	public Jellyfish(GameManage gm,int x,int y) {
		super(gm);
		this.x=x;
		this.y=y;
		this.isCollision=true;
		this.isHidden=false;
		this.pow=4;
		frameSpeed=2;
		frameCnt=18;
		dx=2;
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width +16 || x < -16 || y < -16
					|| y > TankGameCanvas.height + 16) {
				return ;
			}
			attack=0;
			isWater=false;
			checkTileValue();
			if(isWater){
				
				if(dx>0||dx<0){
					nextFrame(2,18);
				}
				if(dy<0){
					frameCnt=18;
				}else{
					nextFrame(2,18);
				}
				if(timeCnt++%40==0){
					isJump=!isJump;
				}
				if(timeCnt%50==0){
					if(x-gm.lgr.tankSprite.x>0){
						dx=-2;
					}else{
						dx=2;
					}
				}
				if(isJump){
					dy=-1;
					dx=0;
				}else{
					dy=1;
				}
				
				if(checkTileCollisionVertical()){
					isJump=false;
				}
				if(checkTileCollisionHorizon2()){
					dx=-dx;
				}
				x+=dx;
				y+=dy;
				if(checkBulletDamage()){
					frameCnt=-1;
				}
				pow-=attack;
				if(pow<=0){
					gm.creatBombEffect(x-8, y-8, 1);
					isHidden=true;					
					if(timeCnt%4==0){
						gm.creatGoods(x, y, Goods.POW);
					}
				}
			}else{
				isJump=false;
				dy+=2;
			}
		}
	}
	
}
/**
 * ------------------定时炸弹-----------------------
 */
class TimeBomb extends EnemySprite16{

	public TimeBomb(GameManage gm,int x,int y) {
		super(gm);
		this.x=x;
		this.y=y;
		this.isHidden=false;
		pow=4;
		frameCnt=22;
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width +16 || x < -16 || y < -16
					|| y > TankGameCanvas.height + 16) {
				return ;
			}
			attack=0;
			nextFrame(2,22);
			
			if(x-gm.lgr.tankSprite.x<=12&&x-gm.lgr.tankSprite.x>-12&&y-gm.lgr.tankSprite.y>=0&&y-gm.lgr.tankSprite.y<28){
				attack=4;
			}
			if(checkBulletDamage8()){
				attack=4;
			}
			pow-=attack;
			timeCnt++;
			if(pow<=0){
				gm.creatBombEffect(x-8, y-8, 1);
				isHidden=true;
				for(int i=0;i<3;i++){
					if(i==0)
						gm.creatEnemyBullet(x, y, -4, 4, 1);
					if(i==1)
						gm.creatEnemyBullet(x, y, 4, 4, 1);
					if(i==2)
						gm.creatEnemyBullet(x, y, 1, 4, 1);
				}
				if(timeCnt%4==0){
					gm.creatGoods(x, y, Goods.POW);
				}
			}
		}
	}
}
/** 
 * ----------------------摇杆----------------------
 */
class Rocker extends EnemySprite16{

	private boolean isAcross;
	private boolean isMove;
	public Rocker(GameManage gm,int x,int y,boolean isAcross) {
		super(gm);
		this.x=x;
		this.y=y;
		this.isAcross=isAcross;
		isHidden=false;
		pow=12;
		speed=6;
		this.isCollision=true;
		dx=0;
		dy=0;
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width +16 || x < -16 || y < -16
					|| y > TankGameCanvas.height + 16) {
				return ;
			}
			nextFrame(4,26);
			checkTileValue();
			//判断精灵属性是横向或直向
			if(isAcross){
				if(y-gm.lgr.tankSprite.y<32&&y-gm.lgr.tankSprite.y>-16){
					isMove=true;
				}
				if(isMove){
					dx=speed;
				}
				if(checkTileCollisionHorizon2()){
					dx=0;
					speed=-speed;
					isMove=false;
				}
				
			}else{
				if(x-gm.lgr.tankSprite.x>-16&&x-gm.lgr.tankSprite.x<32){
					isMove=true;
				}
				if(isMove){
					dy=speed;
				}
				if(checkTileCollisionVertical()){
					dy=0;
					speed=-speed;
					isMove=false;
				}
			}
			if(checkBulletDamage()){
				frameCnt=-1;
			}
			x+=dx;
			y+=dy;
			pow-=attack;
			timeCnt++;
			if(pow<=0){
				gm.creatBombEffect(x-8, y-8, 1);
				isHidden=true;					
				if(timeCnt%4==0){
					gm.creatGoods(x, y, Goods.POW);
				}
			}
		}
	}
}
/**
 * -------------------大螺丝-------------------------
 */
class Nut extends EnemySprite16{

	private int xSpeed;
	private int ySpeed;
	public Nut(GameManage gm,int x,int y) {
		super(gm);
		this.x=x;
		this.y=y;
		isHidden=false;
		speed=1;
		pow=8;
		this.isCollision=true;
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width +16 || x < -16 || y < -16
					|| y > TankGameCanvas.height + 16) {
				return ;
			}
			attack=0;
			if(x-gm.lgr.tankSprite.x<0){
				dx=speed;
			}else{
				dx=-speed;
			}
			if(y-gm.lgr.tankSprite.y<0){
				dy=speed;
			}else{
				dy=-speed;
			}
			if(timeCnt++%80==0){
				xSpeed=6;
				if(x-gm.lgr.tankSprite.x>=0){
					xSpeed=-6;
				}
				if(x-gm.lgr.tankSprite.x==0){
					ySpeed=0;
				}else{
					ySpeed=Math.abs(xSpeed*(y-gm.lgr.tankSprite.y)/(x-gm.lgr.tankSprite.x));
				}
				if(y-gm.lgr.tankSprite.y>0){
					ySpeed=-ySpeed;
				}
				gm.creatEnemyBullet(x+4, y+4, xSpeed, ySpeed, 6);
			}
			if(checkTileCollisionHorizon2()){
				dx=0;
			}
			
			if(checkTileCollisionVertical()){
				dy=0;
			}
			nextFrame(2,24);
			if(checkBulletDamage()){
				frameCnt=-1;
			}
			x+=dx;
			y+=dy;
			pow-=attack;
			if(pow<=0){
				isHidden=true;
				gm.creatBombEffect(x-8, y-8, 2);
				if(timeCnt%4==0){
					gm.creatGoods(x, y, Goods.GUN);
				}
			}
		}
	}
}
/**
 * --------------------飞盘------------------------
 */
class Frisbeer extends EnemySprite16{

	public Frisbeer(GameManage gm,int x,int y) {
		super(gm);
		this.x=x;
		this.y=y;
		isHidden=false;
		pow=4;
		speed=-8;
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width  || x < -32 || y < -32
					|| y > TankGameCanvas.height + 32) {
				speed=-speed;
			}
			timeCnt++;
			if(timeCnt>40)
				timeCnt=0;
			if(timeCnt>=0&&timeCnt<20){
				dy=speed/4;
			}else if(timeCnt>5&&timeCnt<=40){
				dy=-speed/4;
			}
			dx=speed;
			if(dx<0){
				nextFrame(2,30);
			}else{
				nextFrame(2,32);
			}
			if(checkBulletDamage()){
				frameCnt=-1;
			}
			pow-=attack;
			x+=dx;
			y+=dy;
			if(pow<=0){
				gm.creatBombEffect(x-8, y-8, 2);
				isHidden=true;					
				if(timeCnt%4==0){
					gm.creatGoods(x, y, Goods.HOV);
				}
			}
			
		}
	}
}

class OddFace extends EnemySprite16{

	public byte part;
	public static final byte HEAD=1;
	public static final byte FACE=2;
	public static final byte MOUSE=3;
	public static boolean oddIsHit;
	boolean running;
	int type;
	public OddFace(GameManage gm,int x,int y,byte part) {
		super(gm);
		this.x=x;
		this.y=y;
		this.part=part;
		if(TankSprite.oddFacePow<=0){
			isHidden=true;
		}else{
			isHidden=false;
		}
		
	}
	
	public void action(){
		if(!isHidden){
			if (x > TankGameCanvas.width  || x < -32 || y < -32
					|| y > TankGameCanvas.height + 32) {
				return ;
			}
			attack=0;
			oddIsHit=false;
			if(checkBulletDamage()&&TankSprite.HYPER_BEAM){
				oddIsHit=true;
				TankSprite.oddFacePow-=attack;
			}
			switch(part){
			case HEAD:
				frameCnt=36;
				if(oddIsHit||TankSprite.oddFacePow<200){
					frameCnt=37;
				}
				break;
				
			case FACE:
				frameCnt=38;
				if(oddIsHit||TankSprite.oddFacePow<200){
					frameCnt=39;
				}
				break;
				
			case MOUSE:
				frameCnt=40;
				if(oddIsHit||TankSprite.oddFacePow<200){
					frameCnt=41;
				}
				if(running){
					if(type==0){
						gm.creatEnemyBullet(x+12, y+8, 6, 0, 3);
						type+=1;
					}else if(type==1){
						gm.creatEnemyBullet(x+12, y+8, 6, -1, 3);
						type+=1;
					}else if(type==2){
						gm.creatEnemyBullet(x+12, y+8, 6, -3, 3);
						type=0;
					}
//					gm.creatEnemyBullet(x+16, y+32, 5, 180, 5);
				}
				if(++timeCnt%40==0){
					running=!running;
					timeCnt=0;
				}
				break;
			}
			if(TankSprite.oddFacePow<=0){
				gm.creatBombEffect(x-8, y-8, 3);
				isHidden=true;
			}
		}
	}
}

/**
 * ----------------BOSS 1 Helper--------------------
 */
class BossOneHelper extends EnemySprite16{

	private int dx;
	private int dy;
	private int arc;
	private int arcos;
	private boolean add;
	private boolean sub;
	private boolean running;
	public BossOneHelper(GameManage gm,int arcos) {
		super(gm);
		isHidden=false;
		this.arcos=arcos;
		frameCnt=34;
		dx=100;
		dy=100;
	}
	
	public void action(){
		if(Boss.isLive){
			if(dx<100||dx>150){
				add=!add;
			}
			if(dy<20||dy>150){
				sub=!sub;
			}
			if(timeCnt++%100==0){
				running=!running;
			}
			if(running){
				if(add){
					dx++;
				}else{
					dx--;
				}
				if(sub){
					dy--;
				}else{
					dy++;
				}
			}
 			arc+=3;
 			if(arc>=360)	//角度>360时复位
 				arc=0;
 			x=(int)(dx*Math.cos(Math.toRadians(arc-arcos)))+Boss.tmpx+48;
 			y=(int)(dy*Math.sin(Math.toRadians(arc-arcos)))+Boss.tmpy+34;
			
		}else{
			isHidden=true;
		}
	}
}

⌨️ 快捷键说明

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