bullets.java

来自「手机射击游戏源代码,nokia s60模拟器开发包,eclipse工具开发.不可」· Java 代码 · 共 355 行

JAVA
355
字号
package src;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Graphics;

class Bullets extends Sprite {
	protected boolean isAlive = true;

	protected boolean isHit = false;

	protected int tickCount = 0;

	int bulletDirect;

	int bulletType;

	int bombDirect;

	boolean live;

	boolean upORdown;

	int test[] = { 0, 0, 1, 1, 2, 2, 3, 3 };

	public Bullets(Image image) {
		super(image);
		upORdown = false;
		live = false;
	}

	public Bullets(Sprite sprite) {
		super(sprite);
		upORdown = false;
		live = false;
	}

	public Bullets(Image image, int frameWidth, int frameHeight) {
		super(image, frameWidth, frameHeight);
		isAlive = false;
	}

	public void move() {
		x -= 2;
		if (x < 0)
			live = false;
	}

	int a = 0;

	public void move2() {
		if (a == 0) {
			x -= 4;
			y -= 5;
		}
		if (y < 50) {
			a = 1;
		}
		if (a == 1) {
			x--;
			y += 5;
		}

		if (y > 208) {
			a = 0;
			live = false;
		}
	}

	int a1 = 0;

	public void move3() {
		if (a1 == 0) {
			x -= 6;
			y -= 4;
		}
		if (x < 0) {

			a1 = 1;
		}

		if (a1 == 1)

			y += 4;

		if (y > 208) {

			a1 = 0;

			live = false;
		}

	}

	public void move11() {
		y-=2;
		x-=2;
		if (y < -50)
			live = false;
	}

	public void move22() {

		x += 4;

		if (x > 180)
			live = false;
	}

	public void boss4_bullet_move() {
		x-=4;
		if (x < 60){
			y+=4;
		}			
		if (y > 200){
			live = false;
		}			
	}

	//int aa=0;
	public void move33() {
		if (bulletType == 1)
			y+=4;
		if (bulletType == 2) {
			x-=4;
			y+=4;
		}
		if (bulletType == 3) {
			x+=4;
			y+=4;
		}

		if (y > 208) {
			live = false;
		}
	}

	public int type;
	int zhao=0;
	public void move5() {
		if(y<50)
		  zhao=1;
		
		if(type==1){
			if(zhao==0)
		       y-=2;	
			if(zhao==1)
			   y+=5;
		}
		if(type==2){
			if(zhao==0){
			  y-=2;
			  x-=2;}
			if(zhao==1){
				y+=5;
			    x-=2;}
			
			}
		if(type==3){
			if(zhao==0){
			  y-=2;
			  x-=4;}
			if(zhao==1){
				y+=5;
			    x-=2;}
			
			}
		if(type==4){
			if(zhao==0){
			  y-=2;
			  x+=2;}
			if(zhao==1){
				y+=5;
			    x+=2;}
			
			}
		if(type==5){
			if(zhao==0){
			  y-=2;
			  x+=4;}
			if(zhao==1){
				y+=5;
			    x+=2;}
			
			}
		 
		  if(y>208){
		  	zhao=0;
		  	live=false;}	
	}
	
	/** player 子弹移动的方法 */
	void doMove(int bulletDirect) {
		switch (bulletDirect) {
		case Character.DIRECTION_LEFT: //
			x -= 10;
			break;
		case Character.DIRECTION_RIGHT: //
			x += 10;
			break;
		case Character.DIRECTION_UP: //
			y -= 10;
			break;
		case Character.DIRECTION_RIGHT_DOWN:
			x += 10;
			break;
		case Character.DIRECTION_LEFT_DOWN:
			x -= 10;
			break;
		}
	}

	int step = 10;

	/** NPC 子弹移动的方法 */
	void doMoveNPC(int npcDirect,int sudu) {
		switch (npcDirect) {
		case Character.DIRECTION_LEFT:
			x -= sudu;
			break;
		case Character.DIRECTION_RIGHT:
			x += sudu;
			break;
		case Character.DIRECTION_UP:
			y -= sudu;
			break;
		case Character.DIRECTION_DOWN:
			y += sudu;
			break;
		}
	}

	void setBomb() {
		setFrameSequence(test);
	}

	void DrawBomb(Graphics g) {
		paint(g);
		nextFrame();
	}

	public void bombOverlaps(NPC npc) {
		if (isAlive() && npc.isAlive()) {
			if (collidesWith(npc)) {
//				npc.setHit(true);
				setAlive(false);
				npc.setAlive(false);
			}
		}
	}

	int aa = 5;

	/** player 手雷移动的方法 */
	void doMoveBomb() {
		if (isAlive == false)
			aa = 5;
		switch (bombDirect) {
		case Character.DIRECTION_LEFT:
			x -= 6;
			y -= aa;
			aa--;
			break;
		case Character.DIRECTION_RIGHT:
			x += 6;
			y -= aa;
			aa--;
			break;
		case Character.DIRECTION_RIGHT_DOWN:
			x += 6;
			y -= aa;
			aa--;
			break;
		case Character.DIRECTION_LEFT_DOWN:
			x -= 6;
			y -= aa;
			aa--;
			break;
		}
	}

	public void putBomb(Player player) {
		if (!isAlive) {
			setBombDirect(player.playerDirect);
			setPosition(player.x, player.y);
			aa = 5;
			if (player.playerDirect == Character.DIRECTION_RIGHT) {
				switch (player.playerState) {
				case 9://put bomb
					setPosition(player.x + player.width - 10, player.y);
					break;
				}
			}
			if (player.playerDirect == Character.DIRECTION_LEFT) {
				switch (player.playerState) {
				case 9://put bomb
					setPosition(player.x - 10, player.y);
					break;
				}
			}
			if (player.playerDirect == Character.DIRECTION_RIGHT_DOWN) {
				switch (player.playerState) {
				case 9://put bomb
					setPosition(player.x + player.width - 10, player.y);
					break;
				}
			}
			if (player.playerDirect == Character.DIRECTION_LEFT_DOWN) {
				switch (player.playerState) {
				case 9://put bomb
					setPosition(player.x - 10, player.y);
					break;
				}
			}
			setAlive(true);
		}
	}

	void doDraw(Graphics g) {
		paint(g);
		nextFrame();
	}

	public int getBulletDirect() {
		return bulletDirect;
	}

	public int getBombDirect() {
		return bombDirect;
	}

	public void setBombDirect(int bombdirect) {
		bombDirect = bombdirect;
	}

	public void setBulletDirect(int Direct) {
		bulletDirect = Direct;
	}

	void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	boolean isAlive() {
		return isAlive;
	}

	void setHit(boolean isHit) {
		this.isHit = isHit;
		tickCount = 0;
	}

	boolean isHit() {
		return isHit;
	}
}

⌨️ 快捷键说明

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