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

📄 cpc.java

📁 这个游戏的关卡使用mapwin制作的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
						p_direction1d = 1;
					} else if (t_var == t_ai_alpha) {

						t_direction_1d[p_direction1d] = Canvas.LEFT; // left
						p_direction1d++;

					}
				}
				if (isTileXYNull(t_ogre_x + 1, t_ogre_y)
						&& isCanOGREMOVETO(t_ogre_x + 1, t_ogre_y)) {
					// right
					int t_var = 30;
					if (bDirection == Canvas.LEFT) { // left
						t_var -= 20;
					} else if (MyGameCanvas.instance.npcLisa.nX - nX <= 0) {
						t_var -= 10;
					}
					if (t_var > t_ai_alpha) {
						t_ai_alpha = t_var;
						t_direction_1d[0] = Canvas.RIGHT; // right
						p_direction1d = 1;
					} else if (t_var == t_ai_alpha) {

						t_direction_1d[p_direction1d] = Canvas.RIGHT; // right
						p_direction1d++;

					}
				}
				if (p_direction1d == 1) {
					// 目标方向
					bDirection = t_direction_1d[0];
				} else {
					// 随机方向
					bDirection = (byte) t_direction_1d[Math
							.abs(MyGameCanvas.instance.random.nextInt())
							% p_direction1d];

				}
			}
			if (t_direct != bDirection) {
				anim.changeAction(bDirection);
			}
			switch (bDirection) {
			case Canvas.UP: {
				yCalc -= nSpeed;
			}
				break;
			case Canvas.DOWN: {
				yCalc += nSpeed;
			}
				break;
			case Canvas.LEFT: {
				xCalc -= nSpeed;
			}
				break;
			case Canvas.RIGHT: {
				xCalc += nSpeed;
			}
				break;

			}
			nX = xCalc / 10;
			nY = yCalc / 10;
			int r1x1 = MyGameCanvas.instance.npcLisa.nX;
			int r1y1 = MyGameCanvas.instance.npcLisa.nY;
			int r1x2 = r1x1 + 16;
			int r1y2 = r1y1 + 16;
			//
			int r2x1 = nX;
			int r2y1 = nY;
			int r2x2 = r2x1 + 16;
			int r2y2 = r2y1 + 16;

			if (MyGameCanvas.isIntersectRect(r1x1, r1y1, r1x2, r1y2, r2x1,
					r2y1, r2x2, r2y2)) {
				MyGameCanvas.instance.npcLisa.delHp(-1);
			}
		}
			break;
		case B_VAR_BOMB: {
			switch (bBombState) {
			case B_BOMB_STATE_STATIC: {
				if (nTimer < nTimerMax) {
					nTimer++;
					break;
				}
				setBoom();
			}
				break;
			case B_BOMB_STATE_BOMBING: {
			}
				break;
			}
		}
			break;
		case B_VAR_BOMBSFIRE: {

			int r1x1 = nX;
			int r1y1 = nY;
			int r1x2 = nX + Consts.SN_TILE_WIDTH;
			int r1y2 = nY + Consts.SN_TILE_HEIGHT;

			if (nBombFireToDisappear < nBombFireToDisappearMax) {
				//
				// System.out.println("nBombFireToDisappear : " +
				// nBombFireToDisappear);
				if (nBombFireToDisappear == 0) {
					//
					if (Consts.SB_TILE_BRICK == Consts
							.getTileVar(MyGameCanvas.snsTiles[nY
									/ Consts.SN_TILE_HEIGHT][nX
									/ Consts.SN_TILE_WIDTH])) {
						// make the bricks to can be bricked tiles
						MyGameCanvas.snsTiles[nY / Consts.SN_TILE_HEIGHT][nX
								/ Consts.SN_TILE_WIDTH] = (byte) 25;
					}
					// cpc
					for (int i = 0; i < MyGameCanvas.instance.vecticUnits
							.size(); i++) {
						CPC cpc = (CPC) MyGameCanvas.instance.vecticUnits
								.elementAt(i);
						if (cpc.bVar == B_VAR_BOSS_SIMPLY
								|| cpc.bVar == B_VAR_OGRE
								|| cpc.bVar == B_VAR_WORM
								|| cpc.bVar == B_VAR_RABIT
								|| cpc.bVar == B_VAR_BOSS_SNAKE
								|| cpc.bVar == B_VAR_BOSS_UFO) {
							int r2x1 = cpc.nX;
							int r2y1 = cpc.nY;
							int r2x2 = cpc.nX + Consts.SN_TILE_WIDTH;
							int r2y2 = cpc.nY + Consts.SN_TILE_HEIGHT;
							if (MyGameCanvas.isIntersectRect(r1x1, r1y1, r1x2,
									r1y2, r2x1, r2y1, r2x2, r2y2)) {

								// cpc.nHP--;
								cpc.delHp(-1);
								if (cpc.bVar == B_VAR_BOSS_SIMPLY
										|| cpc.bVar == B_VAR_BOSS_SNAKE
										|| cpc.bVar == B_VAR_BOSS_UFO) {
									if (cpc.nHP <= 0) {
										cpc.nHP = 1;
									}
								}
							}
						}

					}
					//
					// npc
					if (MyGameCanvas.instance.npcLisa.nHpTimer < MyGameCanvas.instance.npcLisa.nHpTimerMax) {

					} else {
						int r2x1 = MyGameCanvas.instance.npcLisa.nX;
						int r2y1 = MyGameCanvas.instance.npcLisa.nY;
						int r2x2 = r2x1 + Consts.SN_TILE_WIDTH;
						int r2y2 = r2y1 + Consts.SN_TILE_HEIGHT;
						if (MyGameCanvas.isIntersectRect(r1x1, r1y1, r1x2,
								r1y2, r2x1, r2y1, r2x2, r2y2)) {
							MyGameCanvas.instance.npcLisa.delHp(-1);
						}
					}

				}
				nBombFireToDisappear++;

				break;
			}
			nHP = 0;
		}
			break;
		}

		//
		nXInScreen = nX - MyGameCanvas.snMapX + MyGameCanvas.snWindowX;
		nYInScreen = nY - MyGameCanvas.snMapY + MyGameCanvas.snWindowY;
	}

	public void draw(Graphics g) {

		if (isInScreen()) {
			int t_x = nXInScreen;
			int t_y = nYInScreen;
			boolean isDrawHP = false;
			switch (bVar) {
			case B_VAR_ZHEN: {
				if (bBossState == 0) {
					MyGameCanvas.blt(g, MyGameCanvas.imageCi, 0, 0, 16, 16,
							t_x, t_y);
				} else if (bBossState == 1 || bBossState == 3) {
					MyGameCanvas.blt(g, MyGameCanvas.imageCi, 16, 0, 16, 16,
							t_x, t_y);

				} else {
					MyGameCanvas.blt(g, MyGameCanvas.imageCi, 32, 0, 16, 16,
							t_x, t_y);

				}
				// g.fillRect(t_x, t_y, 16, 16);

			}
				break;
			case B_VAR_BOX: {
				if (isHandleByNPC) {
					t_y = nYInScreen - 24;
				}
				g.drawImage(MyGameCanvas.imageBox, t_x, t_y, Graphics.LEFT
						| Graphics.TOP);

			}
				break;
			case B_VAR_MAGIC_CPC_FIRE: {

			}
				break;
			case B_VAR_MAGIC_CPC_FIRE_BALL: {
				g.drawImage(MyGameCanvas.imageBall, t_x, t_y, Graphics.LEFT
						| Graphics.TOP);

			}
				break;
			case B_VAR_MAGIC_LISA_FIRE: {

			}
				break;
			case B_VAR_NPC: {
				t_y = nYInScreen - 10;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }

			}
				break;
			case B_VAR_RABIT: {
				// isDrawHP = true;
				t_y = nYInScreen;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }
			}
				break;
			case B_VAR_SAVING: {

				anim.draw(g, t_x, t_y);

			}
				break;
			case B_VAR_WORM: {
				t_y = nYInScreen;
				isDrawHP = true;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }
			}
				break;
			case B_VAR_DOOR: {
			}
				break;
			case B_VAR_OGRE: {
				isDrawHP = true;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }

			}
				break;
			case B_VAR_BOMB: {
				// g.drawImage(MyGameCanvas.instance.imageBomb, t_x, t_y,
				// Graphics.TOP | Graphics.LEFT);

				anim.draw(g, t_x, t_y);

			}
				break;

			case B_VAR_BOMBSFIRE: {
				// g.setColor(0xfff000);
				// g.fillRect(t_x, t_y, 16, 16);
				// if (anim == null) {
				// System.out.println("null");
				// }
				anim.draw(g, t_x, t_y);
				// g.drawImage(MyGameCanvas.imageFire, t_x, t_y, Graphics.TOP
				// | Graphics.LEFT);

			}
				break;
			case B_VAR_BOSS_SIMPLY: {
				isDrawHP = true;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }

			}
				break;
			case B_VAR_BOSS_UFO: {
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }
			}
				break;

			case B_VAR_BOSS_SNAKE: {
				// isDrawHP = true;
				if (anim != null) {
					if (nHpTimer < nHpTimerMax) {
						if (nHpTimer % 2 == 0) {
							anim.draw(g, t_x, t_y);
						}
					} else {
						anim.draw(g, t_x, t_y);
					}

				}
				if (super.nHP <= 1) {
					int a_x = 0;
					int a_y = 0;
					switch (bDirection) {
					case Canvas.UP: {
						a_x = 4;
						a_y = 8;
					}
						break;
					case Canvas.DOWN: {
						a_x = 4;
						a_y = 1;
					}
						break;
					case Canvas.LEFT: {
						a_x = 4;
						a_y = 3;
					}
						break;
					case Canvas.RIGHT: {
						a_x = 1;
						a_y = 3;
					}
						break;
					}
					g.drawImage(MyGameCanvas.imageX, t_x + a_x, t_y + a_y,
							Graphics.TOP | Graphics.LEFT);
				}

				// if (isDrawHP) {
				// if (nHpTimer < nHpTimerMax) {
				// if (nHpTimer % 2 == 0) {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				// } else {
				// drawHP(g, t_x, t_y - 10, 16, 2);
				// }
				//
				// }
			}
				break;

			}

			//
		}

	}

	// public void drawHP(Graphics g, int x, int y, int width, int height) {
	// // DRAW HP
	// g.setColor(0xffffff);
	// g.drawRect(x, y, width + 1, height + 1);
	// int length = 0;
	// length = nHP * width / nHPMax;
	// g.setColor(0xff0000);
	// g.fillRect(x + 1, y + 1, length, height);
	// }

	public boolean isInScreen() {
		return true;
	}

	public void upBox() {
		//
		isHandleByNPC = true;
		nX = MyGameCanvas.instance.npcLisa.nX;
		nY = MyGameCanvas.instance.npcLisa.nY;
	}

	public void downBox() {

		int tempx = nX;
		int tempy = nY;

		switch (MyGameCanvas.instance.npcLisa.bDirection) {
		case Canvas.UP: {
			nX = MyGameCanvas.instance.npcLisa.nX;
			nY = MyGameCanvas.instance.npcLisa.nY - 16;
		}
			break;
		case Canvas.DOWN: {
			nX = MyGameCanvas.instance.npcLisa.nX;
			nY = MyGameCanvas.instance.npcLisa.nY + 16;
		}
			break;
		case Canvas.LEFT: {
			nX = MyGameCanvas.instance.npcLisa.nX - 16;
			nY = MyGameCanvas.instance.npcLisa.nY;
		}
			break;
		case Canvas.RIGHT: {
			nX = MyGameCanvas.instance.npcLisa.nX + 16;
			nY = MyGameCanvas.instance.npcLisa.nY;
		}
			break;
		}
		//
		// Consts.log("判断是否能落下箱子:)");
		if (nX % Consts.SN_TILE_WIDTH != 0 || nY % Consts.SN_TILE_HEIGHT != 0) {
			// 不能落下
			// Consts.log("判断是否能落下箱子:)1");
			nX = tempx;
			nY = tempy;
			return;
		}
		// 探测地图
		if (Consts.SB_TILE_NULL != Consts.getTileVar(MyGameCanvas.snsTiles[nY
				/ Consts.SN_TILE_HEIGHT][nX / Consts.SN_TILE_WIDTH])) {
			// Consts.log("判断是否能落下箱子:)2");
			nX = tempx;
			nY = tempy;
			return;
		}
		for (int i = 0; i < MyGameCanvas.vecticUnits.size(); i++) {
			CPC cpc = (CPC) MyGameCanvas.vecticUnits.elementAt(i);
			int r1x1 = cpc.nX;
			int r1y1 = cpc.nY;
			int r1x2 = cpc.nX + 16;
			int r1y2 = cpc.nY + 16;
			int r2x1 = nX;
			int r2y1 = nY;
			int r2x2 = nX + 16;
			int r2y2 = nY + 16;
			if (cpc.equals(this)) {
				// 不和自己比较:)
			} else {
				if (MyGameCanvas.isIntersectRect(r1x1, r1y1, r1x2, r1y2, r2x1,
						r2y1, r2x2, r2y2)) {
					// Consts.log("判断是否能落下箱子:)3");
					nX = tempx;
					nY = tempy;
					return;
				}
			}

		}
		// 当能放下箱子的时候改变:)
		isHandleByNPC = false;
		MyGameCanvas.instance.npcLisa.isHandleCPC = false;

	}

	public boolean isLisaNear(int dis) {

		boolean flag = false;
		if (Math.abs(nX - MyGameCanvas.instance.npcLisa.nX) < dis
				&& Math.abs(nY - MyGameCanvas.instance.npcLisa.nY) < dis) {
			flag = true;
		}

⌨️ 快捷键说明

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