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

📄 gamecanvas.java

📁 手机射击游戏源代码,nokia s60模拟器开发包,eclipse工具开发.不可用于商业用途.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				BulletJiShu();
			}
			bulletKill = 10;
			break;
		}
	}

	void BulletJiShu() {
		myBulletsCountT--;
		myBulletsCount1_2 = myBulletsCountT % 10;
		myBulletsCount1_1 = (myBulletsCountT - myBulletsCount1_2) / 10;
		if (myBulletsCountT < 1) {
			bulletType = 1;
			myBulletsCount = 0;
		}
	}
			
	void jump() {
		if (player.isjump) {
			if (!player.collidesWith(map)) {
				player.y -= step;
				step -= 1;
//				if(step>=0)
//					step-=1;
//					if(step<0)
//						step-=3;
			}
			
			for (int i = 0; i < 3; i++) {
				if (player.collidesWith(map) || player.collidesWith(object[i])
						|| player.collidesWith(object[5])
						|| player.collidesWith(object[6])
						|| player.collidesWith(object[3])
						|| player.collidesWith(object[4])) {
					jumpState = 0;
					step = stepV;
					if ((right_bln || left_bln) && (rightbln || leftbln)) {
						player.setState(5);
					} else
						player.setState(0);
					player.isjump = false;
				}
			}
			if (gds.getMissionID()==4){
				if (player.collidesWith(lift)){
					jumpState = 0;
					step = stepV;
					if ((right_bln || left_bln) && (rightbln || leftbln)) {
						player.setState(5);
					} else
						player.setState(0);
					player.isjump = false;
				}
			}
		}
	}

	/** 判断NPC状态 * */
	void npcAction() {
		for (int i = 0; i < NPC.length; i++) {
			if (NPC[i].x < player.x + screenWidth && NPC[i].x > screenWidth) {
				NPC[i].setAlive(true);
			}
			if (NPC[i].x < -NPC[i].width) {
				NPC[i].setAlive(false);
			}
		}
		for (int i = 0; i < object.length; i++) {
			if (object[i].x < player.x + screenWidth
					&& object[i].x > screenWidth) {
				object[i].setAlive(true);
			}
			if (object[i].x < -object[i].width) {
				object[i].setAlive(false);
			}
		}
		if (boss.boss4_i < player.x + screenWidth && boss.boss4_i > screenWidth) {
			boss.isAlive = true;
		}
	}

	boolean lift(boolean a, TiledLayer tl, NPC lift, Sprite sprite2,
			Sprite sprite3, Sprite sprite4, Player player) {
		if (a)
			lift.y -= 2;
		if (lift.collidesWith(tl))
			a = true;
		if (!a) {
			if (player.collidesWith(lift))
				player.y += 2;
			lift.y += 2;

		}
		if (sprite2 != null) {
			if (!sprite2.collidesWith(tl))
				a = false;
		}

		if ((player.x + player.width) > lift.x && player.collidesWith(lift))
			player.y -= 7;
		if (sprite3 != null) {
			if (lift.collidesWith(sprite3))
				a = false;
		}
		if (sprite4 != null) {
			if (lift.collidesWith(sprite4))
				a = true;
		}
		return a;
	}

	void ImagePz4(Player player, TiledLayer tl) {
		if (player.collidesWith(lift)){	
			ff = true;
//			fuhuo=true;
		}			
		else
			ff = false;
		if (!ff) {
			if (!player.collidesWith(tl))
				player.y += 5;
		}

		if (!player.collidesWith(lift)) {
			if (!player.collidesWith(map))
				player.y += 5;
		}

		if (!gunIco.collidesWith(tl))
			gunIco.y += 4;
		if (!gunIco2.collidesWith(tl))
			gunIco2.y += 4;
		if (!bombIco.collidesWith(tl))
			bombIco.y += 4;

		if (player.collidesWith(tl)) {
			fuhuo = false;
		}
	}

	void ImagePz(Player player, TiledLayer tl, NPC[] object1) {
		if (player.collidesWith(object1[0]) || player.collidesWith(object1[1])
				|| player.collidesWith(object1[2])
				|| player.collidesWith(object1[3])
				|| player.collidesWith(object1[4])
				|| player.collidesWith(object1[5])
				|| player.collidesWith(object1[6]))
			ff = true;
		else
			ff = false;
		if (!ff) {
			if (!player.collidesWith(tl))
				player.y += 5;
		}

		if (!gunIco.collidesWith(tl))
			gunIco.y += 4;
		if (!gunIco2.collidesWith(tl))
			gunIco2.y += 4;
		if (!bombIco.collidesWith(tl))
			bombIco.y += 4;

				if (player.collidesWith(tl) && playerWudi
						|| player.collidesWith(object[5]) && playerWudi
						|| player.collidesWith(object[3]) && playerWudi || playerWudi
						&& player.collidesWith(object[4])) {
					fuhuo = false;
				}
		
				for (int i = 0; i < 7; i++) {
					if (player.collidesWith(object[i]))
						fuhuo = false;
				}
	}

	void bulletOverlapsBoss2(Bullets b,Sprite s,int body){
		if (b.collidesWith(s)) {
			boss.boss2_jishu(bulletKill,body);
			b.setAlive(false);
			myBulletsCount--;
		}
	}
	
	void bulletOverlapsBoss3(Bullets b,Sprite s,int body){
		if (b.collidesWith(s)) {
			boss.boss3_jishu(bulletKill,body);
			b.setAlive(false);
			myBulletsCount--;
		}
	}
	
	/** TODO player子弹与NPC的检测 * */
	void bulletOverlaps(Graphics g, Bullets[] bullet) {
		for (int i = 0; i < bullet.length; i++) {
			if (bullet[i].isAlive) {
				bullet[i].doMove(bullet[i].getBulletDirect());
				bullet[i].doDraw(g);
				if (bullet[i].x >= screenWidth || bullet[i].x <= 0
						|| bullet[i].y <= 0
						|| bullet[i].y >= player.y + player.height) //
				{
					bullet[i].setAlive(false);
					myBulletsCount--;
					break;
				}

				//boss
				switch (gds.getMissionID()) {
				case 1:
					if (boss.isAlive && bullet[i].collidesWith(boss.boss1[0])) {
						bullet[i].setAlive(false);
						myBulletsCount--;

						//test
//						boss.boss1_x[11] = 0;
						boss.boss_Jishu(bulletKill);
						if (boss.boss1_x[11] <= 0) {
							myscore += 100;
						}
						break;
					}
					break;
				case 2:
					if (boss.isAlive) {
						bulletOverlapsBoss2(bullet[i],boss.boss2[1],1);
						bulletOverlapsBoss2(bullet[i],boss.boss2[2],2);
						bulletOverlapsBoss2(bullet[i],boss.boss2[3],3);

						for (int j = 0; j < boss.b2_bullets_2.length; j++) {
							if (bullet[i].collidesWith(boss.b2_bullets_2[j])) {
								boss.boss2_JishuB(bulletKill);
								bullet[i].setAlive(false);
								myBulletsCount--;
								break;
							}
						}
						//test
//						boss.boss2_x[4] = 0;
//						boss.boss2_x[5] = 0;
//						boss.boss2_x[6] = 0;
						if (boss.boss2_x[4] <= 0 && boss.boss2_x[5] <= 0
								&& boss.boss2_x[6] <= 0){
							myscore += 150;						
						}							
						break;
					}
				case 3:
					if (boss.isAlive) {
						bulletOverlapsBoss3(bullet[i],boss.boss3[1],1);
						bulletOverlapsBoss3(bullet[i],boss.boss3[2],2);
						bulletOverlapsBoss3(bullet[i],boss.boss3[4],3);
						bulletOverlapsBoss3(bullet[i],boss.boss3[5],4);
						
//						boss.boss3_xrming = 0;
//						boss.boss3_xlming = 0;
//						boss.boss3_dlming = 0;
//						boss.boss3_drming = 0;
						if (boss.boss3_xrming <= 0 && boss.boss3_xlming <= 0
								&& boss.boss3_dlming <= 0
								&& boss.boss3_drming <= 0) {
							myscore += 200;
//							playerWudi = true;
						}
					}
					break;
				case 4:
					if (boss.isAlive) {
						switch (cheng) {
						case 1:
							if (bullet[i].collidesWith(boss.boss4[1])) {
								boss.boss4_Jishu(bulletKill);
								bullet[i].setAlive(false);
								myBulletsCount--;
								break;
							}
							//test
//							boss.boss4_x[2] = 0;
							if (boss.boss4_x[2] <= 0) {
								myscore += 250;								
								boss.isAlive=false;	
//								bossP=screenWidth / 2 + 30;
							}
							break;
						case 2:
							if (bullet[i].collidesWith(boss.boss5[1])) {
								boss.boss5_Jishu(bulletKill);
								bullet[i].setAlive(false);
								myBulletsCount--;
								break;
							}
							//test
//							boss.boss5_ming = 0;
							if (boss.boss5_ming <= 0) {
								myscore += 300;
								boss.isAlive=false;
							}
							break;
						}
					}
					break;
				}
			}

			for (int j = 0; j < NPC.length; j++) {
				if (bullet[i].isAlive() && NPC[j].isAlive()) {
					if (bullet[i].collidesWith(NPC[j])) {
						NPC[j].HP -= bulletKill;
						if (NPC[j].HP <= 0) {
							NPC[j].setAlive(false);
							if (NPC[j].id == 1) {
								NPC[j].setAlive(false);
								myscore += 5;
							}
							if (NPC[j].id == 2) {
								myscore += 10;
							}							
							if (NPC[j].id == 3) {
								gunIco.x = NPC[j].x;
								gunIco.y = NPC[j].y;
								gunIco_bln = true;
								myscore += 15;
							}
							if (NPC[j].id == 4) {
								myscore += 20;
							}
							if (NPC[j].id == 5) {
								gunIco2.x = NPC[j].x;
								gunIco2.y = NPC[j].y;
								gunIco_bln2 = true;
								myscore += 25;
							}
							if (NPC[j].id == 6) {
								bombIco.x = NPC[j].x;
								bombIco.y = NPC[j].y;
								bombIco_bln = true;
								myscore += 30;
							}							
						}
						bullet[i].setAlive(false);
						myBulletsCount--;
						break;
					}
				}
			}
		}
	}

	/** TODO player手雷与NPC的检测 * */
	void bombOverlaps(Graphics g, Bullets bullet) {
		if (bombtest.isAlive) {
			if (bombtest.collidesWith(map) || bombtest.y >= screenWidth) {
				bombtest.isAlive = false;
				isBaozha = true;
				s1.setBomb();
				s1.setPosition(bombtest.x, bombtest.y);
//				mc.playmidi(mc.sound.bombPlayer);
			}

			//boss
			if (gds.getMissionID() == 1) {
				if (bullet.collidesWith(boss.boss1[0])) {
					if (boss.isAlive) {
						bullet.setAlive(false);
						boss.boss_Jishu(10);
						bombtest.isAlive = false;
						isBaozha = true;
						s1.setBomb();
						s1.setPosition(bombtest.x, bombtest.y);
						if (boss.boss1_x[11] <= 0) {
							myscore += 100;
						}
					}
				}
			}
			if (gds.getMissionID() == 4) {
				if (bullet.collidesWith(boss.boss4[1])) {
					if (boss.isAlive) {
						bullet.setAlive(false);
						boss.boss4_Jishu(10);
						bombtest.isAlive = false;
						isBaozha = true;
						s1.setBomb();
						s1.setPosition(bombtest.x, bombtest.y);
						if (boss.boss4_x[2] <= 0) {
							myscore += 250;
							boss.isAlive = false;
						}
					}
				}
			}
			bombtest.doMoveBomb();
			bombtest.doDraw(g);
		}

		for (int j = 0; j < NPC.length; j++) {
			if (bombtest.isAlive() && NPC[j].isAlive()) {
				if (bombtest.collidesWith(NPC[j])) {
//					NPC[j].setHit(true);
					NPC[j].HP -= 20;
					bombtest.setAlive(false);
					isBaozha = true;
					s1.setBomb();
					s1.setPosition(bombtest.x, bombtest.y);
					if (NPC[j].HP <= 0) {
						if (NPC[j].id == 1) {
							NPC[j].setAlive(false);
							myscore += 5;
						}
						if (NPC[j].id == 2) {
							myscore += 10;
						}							
						if (NPC[j].id == 3) {
							gunIco.x = NPC[j].x;
							gunIco.y = NPC[j].y;
							gunIco_bln = true;
							myscore += 15;
						}
						if (NPC[j].id == 4) {
							myscore += 20;
						}
						if (NPC[j].id == 5) {
							gunIco2.x = NPC[j].x;
							gunIco2.y = NPC[j].y;
							gunIco_bln2 = true;
							myscore += 25;
						}
						if (NPC[j].id == 6) {
							bombIco.x = NPC[j].x;
							bombIco.y = NPC[j].y;
							bombIco_bln = true;
							myscore += 30;
						}
						NPC[j].setAlive(false);
					}
				}
			}
		}
		bomb(g);
	}

	void bomb(Graphics g) {
		i++;
		if (isBaozha) {
			s1.DrawBomb(g);
		}
		if (i == 8) {
			isBaozha = false;
			i = 0;
		}
	}

	/** TODO NPC子弹与player的碰撞检测 * */
	void npcBulletOverlaps(Graphics g, Bullets[] bullet) {
		for (int i = 0; i < bullet.length; i++) {
			if (bullet[i].isAlive) {
				bullet[i].doMoveNPC(bullet[i].getBulletDirect(),gds.getMissionID()+4);
				bullet[i].doDraw(g);
				if (bullet[i].x >= screenWidth || bullet[i].x <= 0
						|| bullet[i].y <= 0 || bullet[i].collidesWith(map)) {
					bullet[i].aa = 5;
					bullet[i].setAlive(false);
					npcBulletsCount--;
					break;
				}
			}

			if (bullet[i].isAlive() && player.isAlive) {
				if (player.playerState == 4 || player.playerState == 14
						|| player.playerState == 8 || player.playerState == 15)
					player.defineCollisionRectangle(10, 25, 14, 9);
				else
					player.defineCollisionRectangle(10, 0, 14, 34);
				if (bullet[i].collidesWith(player)) {
					bullet[i].setAlive(false);
					if (!playerWudi)playerDead();
					npcBulletsCount--;
					break;
				}
			}
		}
	}

	void npc4BulletOverlaps(Graphics g) {
		if (npc4bullet.isAlive) {
			npc4bullet.x -= 4;
			npc4bullet.y -= step1;
			step1--;
			npc4bullet.doDraw(g);
			if (npc4bullet.x >= screenWidth || npc4bullet.x <= 0
					|| npc4bullet.y <= 0 || npc4bullet.collidesWith(map)) {
				npc4bullet.setAlive(false);
				step1 = 7;
			}
			if (player.isAlive) {
				if (npc4bullet.collidesWith(player)) {
					npc4bullet.setAlive(false);
					if (!playerWudi)playerDead();
				}
			}
		}
	}

	/** TODO boss子弹与player碰撞 * */
	void bossBulletOverlaps(Bullets b) {
		if (b.live) {
			if (player.collidesWith(b)) {
				if (player.isAlive) {
					playerDead();
					b.live = false;
					b.a = 0;//????
					b.a1 = 0;
				}
			}
		}
	}

	void FuHuoPz(TiledLayer tl, NPC object1) {
		if (tl != null) {
			if (!diaoluo) {
				if (player.collidesWith(tl)) {
					player.setState(0);
				}
			}
		}
		if (object1 != null) {
			if (!diaoluo) {
				if (player.collidesWith(object1)) {
					player.setState(0);
				}
			}
		}
	}

	int yy=0;
	boolean isdead=false;
	/** TODO NPC与player的碰撞检测 * */
	void npcOverlapsPlayer(NPC npc) {
		if (npc.isAlive() && player.isAlive == true) {
			if (npc.collidesWith(player)) {
				playerDead();
				npcBulletsCount--;
			}
		}
	}
	
	/** TODO boss与player的碰撞检测 * */
	void bossOverlapsPlayer(Sprite s) {
		if (s.collidesWith(player) && boss.isAlive) {
			playerDead();
		}
	}

	/** TODO player开火 */
	void doFire(Bullets[] bullet) {
		if (myBulletsCount < bullet.length) {
			for (int i = 0; i < bullet.length; i++) {
				if (!bullet[i].isAlive) {
					//player枪类型
					switch (bulletType) {
					case 1:
						bullet[i].setImage(img[1], 6, 6);
						break;
					case 2:
						switch (player.playerDirect) {
						case Character.DIRECTION_RIGHT:
							bullet[i].setImage(img[2], 28, 7);
							break;
						case Character.DIRECTION_LEFT:
							bullet[i].setImage(img[5], 28, 7);
							break;
						case Character.DIRECTION_UP:
							bullet[i].setImage(img[6], 7, 28);
							break;
						case Character.DIRECTION_RIGHT_DOWN:

⌨️ 快捷键说明

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