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

📄 gamecanvas.java

📁 手机射击游戏源代码,nokia s60模拟器开发包,eclipse工具开发.不可用于商业用途.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
							bullet[i].setImage(img[2], 28, 7);
							break;
						case Character.DIRECTION_LEFT_DOWN:
							bullet[i].setImage(img[5], 28, 7);
							break;
						}
						break;
					case 4:
						switch (player.playerDirect) {
						case Character.DIRECTION_RIGHT:
							bullet[i].setImage(img[4], 27, 10);
							break;
						case Character.DIRECTION_LEFT:
							bullet[i].setImage(img[7], 27, 10);
							break;
						case Character.DIRECTION_UP:
							bullet[i].setImage(img[8], 10, 27);
							break;
						case Character.DIRECTION_RIGHT_DOWN:
							bullet[i].setImage(img[4], 27, 10);
							break;
						case Character.DIRECTION_LEFT_DOWN:
							bullet[i].setImage(img[7], 27, 10);
							break;
						}
						break;
					}

					player.setBulletPosion(bullet[i]);
					bullet[i].setAlive(true);
					myBulletsCount++;
					break;
				}
			}
		}
	}

	/** TODO NPC开火 * */
	void doFireNPC(Bullets[] bullet, NPC npc) {
		if (npcBulletsCount < bullet.length) {
			for (int i = 0; i < bullet.length; i++) {
				if (!bullet[i].isAlive) {
					bullet[i].setBulletDirect(npc.npcDirect);
					if (npc.npcDirect == Character.DIRECTION_RIGHT) {
						bullet[i].setPosition(npc.x + npc.width, npc.y
								+ npc.height / 2 - 15);
					}
					if (npc.npcDirect == Character.DIRECTION_LEFT) {
						bullet[i].setPosition(npc.x, npc.y + npc.height / 2
								- 15);
					}
					bullet[i].setAlive(true);
					npcBulletsCount++;
					break;
				}
			}
		}
	}

	boolean npc4fire = false;

	void doFireNPC4(NPC npc) {
		if (!npc4bullet.isAlive) {
			npc4fire = true;
			npc4bullet.setBulletDirect(Character.DIRECTION_LEFT);
			npc4bullet.setPosition(npc.x, npc.y);
			npc4bullet.setAlive(true);
		}
	}

	/** TODO player投掷手雷 * */
	void doPutBomb() {
		if (myBombCount > 0) {
			if (!bombtest.isAlive)
				myBombCount -= 1;
			bombtest.putBomb(player);			
		}
	}

	/** TODO 初始化NPC * */
	void initNPC() {	
		if (boss==null)boss = new Boss();
		for (int i=0;i<NPC.length;i++){
			NPC[i]=null;
		}
		switch (gds.getMissionID()) {
		case 1:
			boss.initBoss1();
			for (int i = 0; i < NPC.length; i++) {
				if (i < 10)
					NPC[i] = new NPC(1, "npc1", img[26],
							img[26].getWidth() / 2, img[26].getHeight());
				if (i >= 10 & i < 20)
					NPC[i] = new NPC(2, "npc2", img[27],
							img[27].getWidth() / 6, img[27].getHeight());
				if (i >= 20)
					NPC[i] = new NPC(3, "npc3", img[28],
							img[28].getWidth() / 6, img[28].getHeight());
			}
//			boss.isAlive = true;
			break;
		case 2:
			boss.initBoss2();
			for (int i = 0; i < NPC.length; i++) {
				if (i < 10)
					NPC[i] = new NPC(4, "npc4", img[39],
							img[39].getWidth() / 3, img[39].getHeight());
				if (i >= 10 & i < 20)
					NPC[i] = new NPC(2, "npc2", img[27],
							img[27].getWidth() / 6, img[27].getHeight());
				if (i >= 20)
					NPC[i] = new NPC(3, "npc3", img[28],
							img[28].getWidth() / 6, img[28].getHeight());
			}
//			boss.isAlive = true;
			break;
		case 3:
			boss.initBoss3();
			for (int i = 0; i < NPC.length; i++) {
				if (i < 5)
					NPC[i] = new NPC(5, "npc5", img[36],
							img[36].getWidth() / 2, img[36].getHeight());
				if (i >= 5 & i < 10)
					NPC[i] = new NPC(6, "npc6", img[37],
							img[37].getWidth() / 2, img[37].getHeight());
				if (i >= 10 & i < 20)
					NPC[i] = new NPC(2, "npc2", img[27],
							img[27].getWidth() / 6, img[27].getHeight());
				if (i >= 20)
					NPC[i] = new NPC(3, "npc3", img[28],
							img[28].getWidth() / 6, img[28].getHeight());
			}
//			boss.isAlive = true;
			break;
		case 4:
			boss.initBoss4();
			boss.initBoss5();
			for (int i = 0; i < NPC.length; i++) {
				if (i < 5)
					NPC[i] = new NPC(5, "npc5", img[36],
							img[36].getWidth() / 2, img[36].getHeight());
				if (i >= 5 & i < 10)
					NPC[i] = new NPC(6, "npc6", img[37],
							img[37].getWidth() / 2, img[37].getHeight());
				if (i >= 10 & i < 20)
					NPC[i] = new NPC(2, "npc2", img[27],
							img[27].getWidth() / 6, img[27].getHeight());
				if (i >= 20)
					NPC[i] = new NPC(3, "npc3", img[28],
							img[28].getWidth() / 6, img[28].getHeight());
			}
//			boss.isAlive = false;
			break;
		}

		//初始化NPC的坐标
		for (int i = 0; i < NPC.length; i++) {
			NPC[i].initNPC(npcdata[gds.getMissionID() - 1][i][0], npcdata[gds
					.getMissionID() - 1][i][1]);
		}
	}

	/** TODO 初始化player * */
	void initPlayer() {
		uu=0;
		step=stepV;
		player.isAlive = true;		
		player.setImage(img[11], img[11].getWidth() / 24,
				img[11].getHeight() / 2);
		player.setPosition(10, 170);
		player.isjump=false;

		for(;player.x<screenWidth;player.x++){
			if (player.collidesWith(map))break;
		}
		diaoluo = false;
		player.defineCollisionRectangle(10, 20, 14, 18);
		player.y = -200;
		player.setState(3);
		player.playerDirect = Character.DIRECTION_RIGHT;
		playerWudi = true;
		fuhuo = true;
		myBombCount = 9;
	}
	
	/** TODO player与地图的移动关系 * */
	void playerMove() {
		if (player.isMove == true) {
			if (!playerpc.collidesWith(object[5])
					&& !playerpc.collidesWith(object[6])
					&& !playerpc.collidesWith(object[3])
					&& !playerpc.collidesWith(object[4])) {
				if (!playerpc.collidesWith(map)) {
					if (player.playerDirect == Character.DIRECTION_RIGHT) {
						if (player.x + player.width >= screenWidth / 2) { //主角走到屏幕中央时让屏幕移动,主角不移动
							if (Math.abs(map.x) >= mapend) {
								if (player.x >= screenWidth / 2 + 30) {
									if (gds.getMissionID() == 4 && cheng == 2)
										boss.isAlive = true;
									if (gds.getMissionID() != 4)
										boss.isAlive = true;
									player.x += 0;
									map.x -= 0;
								} else {
									player.x += 5;
									map.x -= 0;
								}
							} else {
								x1 += 1; //背景移动
								mapPx = -4;
								map.x -= 5;
								NPCMoveWithMap(-5, 0);
							}
							//*****************
						} else
							player.x += 5;
					}
				}
			}
			if (!playerpc1.collidesWith(object[5])
					&& !playerpc1.collidesWith(object[6])
					&& !playerpc1.collidesWith(object[3])
					&& !playerpc1.collidesWith(object[4])) {
				if (!playerpc1.collidesWith(map)) {
					if (player.playerDirect == Character.DIRECTION_LEFT) {
						x1 -= 0;
						mapPx = 0;
						map.move(0, 0);
						if (player.x <= 0)
							player.setPosition(player.x, player.y);
						else
							player.x -= 5;
					}
				}
			}
		} else {
			x1 -= 0;
			mapPx = 0;
			map.move(mapPx, 0);
		}
	}
		
	int death_right[] = { 0,0,0,0,1,1,1,1 };
	int death_left[] = { 2,2,2,2,3,3,3,3 };
	/** TODO player死亡 */
	void playerDead() {	
		pd.visible=true;
		switch (player.playerDirect) {
		case 4:
			pd.setFrameSequence(death_right);
			break;
		case 7:
			pd.setFrameSequence(death_right);
			break;
		case 8:
			pd.setFrameSequence(death_right);
			break;
		case 3:
			pd.setFrameSequence(death_left);
			break;
		case 5:
			pd.setFrameSequence(death_left);
			break;
		case 6:
			pd.setFrameSequence(death_left);
			break;
		}
//		pd.setFrameSequence(death_right);
		pd.setPosition(player.x,player.y);
		player.isAlive = false;
		player.isjump=false;
		playerJiShu();
		initPlayer();
		bombtest.isAlive = false;
		if (playerCountT <= 0) {
			engine.gameOver = true;
			mc.updateHiscores(myscore);
			mc.writeScores("h",0,5,myscore);
		}		
	}

	int playerCountT;
	void playerJiShu(){
		playerCountT = playerCount1 * 10 + playerCount2;
		playerCountT--;
		playerCount2 = playerCountT % 10;
		playerCount1 = (playerCountT - playerCount2) / 10;		
	}
	
	/** TODO 如果地图移动,那么NPC也移动 * */
	void NPCMoveWithMap(int mapPx, int mapPy) {
		for (int i = 0; i < object.length; i++) {
			object[i].move(mapPx, mapPy);
		}
		if (gds.getMissionID() == 1) {
			playerpc3.move(mapPx, mapPy);
			playerpc4.move(mapPx, mapPy);
			playerpc5.move(mapPx, mapPy);
			playerpc6.move(mapPx, mapPy);
		}
		s1.move(mapPx, mapPy);
		bombtest.move(mapPx, mapPy);
		for (int i = 0; i < NPC.length; i++) {
			NPC[i].move(mapPx, mapPy);
		}

		for (int i = 0; i < npcBullets.length; i++) {
			npcBullets[i].move(mapPx, mapPy);
		}

		gunIco.move(mapPx, mapPy);
		gunIco2.move(mapPx, mapPy);
		bombIco.move(mapPx, mapPy);

		switch (gds.getMissionID()) {
		case 1:
			if (tower.isAlive)
				tower.move(mapPx - 4, 0);
			break;
		case 4:
			lift.move(mapPx, 0);
			playerPc.move(mapPx, 0);
			boss.boss4_i += mapPx;
			boss.boss4_x[0] += mapPx;
			break;
		}
	}

	void doThreadStart() {
		Thread t = new Thread(this);
		t.start();
	}

	void drawLoad(Graphics g) {
		g.drawImage(loadImg,screenWidth-loadImg.getWidth(), screenHeight-loadImg.getHeight() ,0);
	}

	void paint_zhuangtai(Graphics g) {
		score[0] = myscore / 10000;
		score[1] = (myscore - score[0] * 10000) / 1000;
		score[2] = (myscore - score[0] * 10000 - score[1] * 1000) / 100;
		score[3] = (myscore - score[0] * 10000 - score[1] * 1000 - score[2] * 100) / 10;
		score[4] = (myscore - score[0] * 10000 - score[1] * 1000 - score[2]
				* 100 - score[3] * 10) / 1;

		for (int i = 0; i < 5; i++) {
			g.setClip(55 + i * 11, 2, 11, 14);
			g.drawImage(img[15], 55 + i * 11 - score[i] * 11, 2, 0);
		}
		
		if (bulletType == 1) {
			g.setClip(150, 5, 15, 9);
			g.drawImage(img[14], 150, 5, 0);
		} else {
			g.setClip(150, 5, 9, 9);
			g.drawImage(img[16], 150 - myBulletsCount1_1 * 9, 5, 0);
			g.setClip(160, 5, 9, 9);
			g.drawImage(img[16], 160 - myBulletsCount1_2 * 9, 5, 0);
		}
		g.setClip(25, 5, 9, 9);
		g.drawImage(img[16], 25 - playerCount1 * 9, 5, 0);
		g.setClip(35, 5, 9, 9);
		g.drawImage(img[16], 35 - playerCount2 * 9, 5, 0);		
		g.setClip(150, 20, 9, 9);
		g.drawImage(img[16], 150 - myBombCount * 9, 20, 0);
		g.setClip(120, 5, 17, 9);
		g.drawImage(img[18], 120, 5, 0);
		g.setClip(10, 0, 14, 18);
		g.drawImage(img[17], 10, 0, 0);
		g.setClip(125, 18, 10, 13);
		g.drawImage(img[19], 125, 18, 0);
		g.setClip(0, 0, getWidth(), getHeight());
	}

	private void paint_kaishi(Graphics g) {
		g.setColor(0, 0, 0);
		g.fillRect(0, aaa, getWidth(), getHeight() - aaa * 2);

		g.setColor(0, 0, 0);
		for (int k = 0; k < 104; k += 2) {
			g.drawLine(0, kaishi_y1 + k, getWidth(), kaishi_y1 + k);
			g.drawLine(0, kaishi_y2 + k, getWidth(), kaishi_y2 + k);
		}

		if (kaishi_guan) {
			g.setColor(255, 0, 0);
			g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
					Font.SIZE_SMALL));
			g.drawString("第 " + gds.getMissionID()+"关", 60, 95,0);
		}
	}
	
	private void kaishi() {
		if (kaishi_line) {
			aaa += 8;
			kaishi_y2 -= 8;
			kaishi_y1 += 8;
		}

		if (aaa > getHeight() / 2) {
			kaishi_guan = true;
			kaishi_line = false;
			kaishi_y1 -= 8;
			kaishi_y2 += 8;

		}
		if (kaishi_y2 > getHeight())
			kaishi_guan = false;		
	}

	void paint_V(Graphics g) {
		if (V) {
			g.drawImage(img[25], V_x, V_y, 0);
		}
	}

	boolean baoguan=false;
	void V_run() {
		switch (gds.getMissionID()) {
		case 1:
			if (boss.boss1_x[11] <= 0) {
				V = true;
				fuhuo=true;				
				boss.isAlive = false;
				V_y += 3;
			}
			break;
		case 2:
			if (boss.boss2_y[0] >= screenHeight / 2) {
				V = true;
				fuhuo=true;
				boss.isAlive = false;
				V_y += 3;
			}
			break;
		case 3:
			if (boss.boss3_y >= screenHeight / 2) {
				V = true;
				fuhuo=true;
				boss.isAlive = false;
				V_y += 3;
			}
			break;
		case 4:
			if (boss.boss5_ming <=0) {
				V = true;
				fuhuo=true;
				boss.isAlive = false;
				V_y += 3;					
			}
			break;
		}
		
		//试玩版本
//		if (V_y > getHeight() / 2) {
//			baoguan=true;
//			cs.display.setCurrent(mc);
//			mc.updateHiscores(myscore);
//			mc.writeScores("h",0,5,myscore);
//			running=false;
//		}else{
//			if (V_y > getHeight() / 2) {
//				engine.gameState = 7;
//				gds.nextMission();
//			}	
//		}
		
//		if (V&&gds.getMissionID()!=4){
//			mc.playmidi(mc.sound.guoguanPlayer);
//		}
//		if (V&&gds.getMissionID()==4){
//			mc.playmidi(mc.sound.tongguanPlayer);
//		}
		
		//4关
		if (gds.getMissionID()==4){
			if (V_y > getHeight() / 2) {
				baoguan=true;
				cs.display.setCurrent(mc);
				mc.updateHiscores(myscore);
				mc.writeScores("h",0,5,myscore);
				running=false;
			}
		}else{
			if (V_y > getHeight() / 2) {
				engine.gameState = 7;
				gds.nextMission();
			}
		}			
	}

	public int imgJuanLeft(Graphics g, int speedx, int speedy, Sprite bg) {
		if (speedx > bg.getWidth())
			speedx = 1;
		bg.setFrame(0);
		g.setClip(bg.getWidth() - speedx, 0, speedx, speedy);
		bg.setPosition(bg.getWidth() - speedx, -bg.getHeight() + speedy);
		bg.paint(g);
		g.setClip(bg.getWidth() - speedx, speedy, speedx, bg.getHeight()
				- speedy);
		bg.setPosition(bg.getWidth() - speedx, speedy);
		bg.paint(g);

		g.setClip(0, 0, bg.getWidth() - speedx, speedy);
		bg.setPosition(-speedx, -bg.getHeight() + speedy);
		bg.paint(g);
		g.setClip(0, speedy, bg.getWidth() - speedx, bg.getHeight() - speedy);
		bg.setPosition(-speedx, speedy);
		bg.paint(g);
		g.setClip(0, 0, getWidth(), getHeight());

		return speedx;
	}

	public int imgJuanDown(Graphics g, int speedx, int speedy, Sprite bg) {
		if (speedy > bg.getHeight())
			speedy = 1;
		bg.setFrame(0);
		g.setClip(bg.getWidth() - speedx, 0, speedx, speedy);
		bg.setPosition(bg.getWidth() - speedx, -bg.getHeight() + speedy);
		bg.paint(g);
		g.setClip(bg.getWidth() - speedx, speedy, speedx, bg.getHeight()
				- speedy);
		bg.setPosition(bg.getWidth() - speedx, speedy);
		bg.paint(g);

		g.setClip(0, 0, bg.getWidth() - speedx, speedy);
		bg.setPosition(-speedx, -bg.getHeight() + speedy);
		bg.paint(g);
		g.setClip(0, speedy, bg.getWidth() - speedx, bg.getHeight() - speedy);
		bg.setPosition(-speedx, speedy);
		bg.paint(g);
		g.setClip(0, 0, getWidth(), getHeight());
		return speedy;
	}

	boolean uuu = false;

	public void lCeng() {
		if (cheng==1){
			if (!lift.collidesWith(playerPc) & player.collidesWith(lift)
					& (player.x + 20) > lift.x) {
				map.y += 2;
				playerPc.y += 2;
				beijing.y += 2;
				uuu = true;			
			} else {
				uuu = false;
				if (lift.collidesWith(playerPc)) {
					cheng = 2;
					mapend = map.width - 2 * screenWidth;
				}
			}
		}
		
		if (lift.collidesWith(playerPc)) fuhuo = false;
	}
	
	protected void hideNotify() {
	    running=false;
	  }

	protected void showNotify() {
	     //填写暂停恢复内容内容
	}
}
//Graphics bufferG=ImageBuffer.getGraphics(); //双缓冲
//Runtime r=new Runtime();
//g.setClip(0,0,176,208);
//g.setColor(0,255,0);
//g.drawString(Integer.toString((int) r.freeMemory()),0,50,0);
//g.drawString(Integer.toString((int) r.totalMemory()),0,70,0);

⌨️ 快捷键说明

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