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

📄 smallplane.java

📁 一个J2ME的游戏,有源程序.是原创!适合S60的176*208的规格.
💻 JAVA
字号:
package src;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SmallPlane {

	KingCanvas KC;

	PlayerMusic PM = new PlayerMusic();

	int PlaneX, PlaneY;

	int PlaneWidth, PlaneHeight;

	int BulletState, PlaneState, MusicTest;

	boolean bFlagSmallPlaneHP, bFlagSmallPlaneState, bFlagBulletsState,
			bFlagBulletsDisplay, isMusic;

	static Image Plane, Bullets, PlaneExplosion;

	int ExplosionNumber, PlaneNumber;

	int PlaneHP, fraction, ColorCounter;

	int Explosion_X, Explosion_Y, Bullets_X, Bullets_Y;

	public SmallPlane(KingCanvas KC, int PlaneStem) {
		this.KC = KC;
		InitPlane(PlaneStem);
	}

	/**
	 * 初始化小飞机相关属性以及加载相关图片处理方法
	 */

	public void InitPlane(int PlaneStem) {
		PlaneX = KC.GetRandom(160);
		PlaneY = -16 - PlaneStem;
		PlaneWidth = 20;
		PlaneHeight = 16;
		PlaneHP = 24;
		MovePlaneState();
		bFlagBulletsDisplay = true;
		try {
			Plane = Image.createImage("/res/picture/smallplane_.png");
			Bullets = Image.createImage("/res/picture/bullet.png");
			PlaneExplosion = Image
					.createImage("/res/picture/smallplanebom_.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 移动小飞机处理方法
	 */

	public void MoveSmallPlane() {
		if (PlaneY > KC.LeadingPlane_Y - PlaneHeight) {
			PlaneY = KC.LeadingPlane_Y - PlaneHeight;
			MovePlaneState();
			bFlagSmallPlaneState = true;
		} else {
			if (bFlagSmallPlaneState == false) {
				switch (PlaneState) {
				case 1:
					PlaneX -= 2;
					if (PlaneX <= 0)
						PlaneState = 2;
					break;
				case 2:
					PlaneX += 2;
					if (PlaneX + PlaneWidth >= KingCanvas.SCREEN_WIDTH)
						PlaneState = 1;
					break;
				}
				PlaneY += 3;
				if (PlaneY == 20) {
					bFlagBulletsDisplay = false;
					bFlagBulletsState = true;
					Bullets_X = PlaneX + 5;
					Bullets_Y = PlaneY + 16;
					if (Bullets_X > KC.LeadingPlane_X + 24) {
						BulletState = 1;
					} else {
						if (Bullets_X < KC.LeadingPlane_X - 24) {
							BulletState = 2;
						} else {
							BulletState = 0;
						}
					}
				}
			}
		}

		if (bFlagSmallPlaneState == true) {
			switch (PlaneState) {
			case 1:
				PlaneX -= 2;
				if (PlaneX <= 0)
					PlaneState = 2;
				break;
			case 2:
				PlaneX += 2;
				if (PlaneX + PlaneWidth >= KingCanvas.SCREEN_WIDTH)
					PlaneState = 1;
				break;
			}
			PlaneY -= 4;
			if (PlaneY + Plane.getHeight() <= 0) {
				PlaneY = -PlaneHeight;
				PlaneX = KC.GetRandom(160);
				PlaneHP = 24;
				MovePlaneState();
				bFlagSmallPlaneState = false;
			}
		}
		if (bFlagSmallPlaneHP == true) {
			KC.ScoreCounter += 2;
			PlaneY = -PlaneHeight;
			PlaneX = KC.GetRandom(160);
			PlaneHP = 24;
			MovePlaneState();
			bFlagSmallPlaneState = false;
		}
	}

	/**
	 * 小飞机发射的子弹移动及碰撞处理方法
	 */

	public void MoveBullets() {
		if (Bullets_Y > KingCanvas.SCREEN_HEIGHT) {
			bFlagBulletsState = false;
			bFlagBulletsDisplay = true;
		} else {
			if (bFlagBulletsState == true) {
				switch (BulletState) {
				case 1:
					Bullets_X--;
					break;
				case 2:
					Bullets_X++;
					break;
				}
				Bullets_Y += KC.SmallPlaneSpeed;
				if (KC.bFlagLeadingPlaneCollide == false) {
					if (KC.isRam(Bullets_X, Bullets_Y, Bullets.getWidth(),
							Bullets.getHeight(), KC.LeadingPlane_X + 4,
							KC.LeadingPlane_Y + 4, KingCanvas.imageLeadingPlane
									.getWidth() - 8,
							(KingCanvas.imageLeadingPlane.getHeight() / 3) - 8)) {
						Bullets_X += KingCanvas.SCREEN_WIDTH;
						Bullets_Y += KingCanvas.SCREEN_HEIGHT;
						KC.BulletsPlantState = 1;
						KC.bFlagLeadingPlaneHPchangeDisplay = true;
						bFlagBulletsDisplay = true;
					}
				}
			}
		}
	}

	/**
	 * 移动小飞机状态处理方法
	 */

	public void MovePlaneState() {
		if (PlaneX > KC.LeadingPlane_X + 24) {
			PlaneState = 1;
		} else {
			if (PlaneX < KC.LeadingPlane_X - 24) {
				PlaneState = 2;
			} else {
				PlaneState = 0;
			}
		}
	}

	/**
	 * 小飞机受损减血处理方法
	 */

	public void procBeHurt() {
		if (PlaneHP > 0) {
			switch (KingCanvas.LeadingPlaneType) {
			case 0:
				switch (KC.BulletsPowerCounter) {
				case 0:
					PlaneHP -= 5;
					break;
				case 1:
					PlaneHP -= 7;
					break;
				case 2:
					PlaneHP -= 9;
					break;
				}
				break;
			case 1:
				switch (KC.BulletsPowerCounter) {
				case 0:
					PlaneHP--;
					break;
				case 1:
					PlaneHP -= 3;
					break;
				case 2:
					PlaneHP -= 5;
					break;
				}
				break;
			case 2:
				switch (KC.BulletsPowerCounter) {
				case 0:
					PlaneHP -= 2;
					break;
				case 1:
					PlaneHP -= 4;
					break;
				case 2:
					PlaneHP -= 6;
					break;
				}
				break;
			}

		} else {
			Explosion_X = PlaneX;
			Explosion_Y = PlaneY;
			isMusic = true;
			MusicTest = 0;
			bFlagSmallPlaneHP = true;
		}
	}

	// -------------------------------------------- 画笔

	/**
	 * 小飞机画笔
	 */

	public void drawSmallPlane(Graphics g) {
		if (bFlagSmallPlaneState == false) {
			KingCanvas.Brush(g, Plane, PlaneX, PlaneY, PlaneWidth, PlaneHeight,
					PlaneNumber, 0);
		} else {
			KingCanvas.Brush(g, Plane, PlaneX, PlaneY, PlaneWidth, PlaneHeight,
					5, 0);
		}

	}

	/**
	 * 小飞机爆炸画笔
	 */

	public void drawSmallPlaneExplosion(Graphics g) {
		KingCanvas.Brush(g, PlaneExplosion, Explosion_X, Explosion_Y,
				PlaneWidth, PlaneHeight, ExplosionNumber, 0);
	}

	/**
	 * 小飞机发射的子弹画笔
	 */

	public void drawSmallPlaneBullets(Graphics g) {
		KingCanvas.Brush(g, Bullets, Bullets_X, Bullets_Y, Bullets.getWidth(),
				Bullets.getHeight(), 0, 0);
	}

	/**
	 * 移动小飞机被打掉显示分数处理方法
	 */

	public void SmallPlanefraction(Graphics g) {
		g.setColor(ColorCounter, ColorCounter, ColorCounter);
		if (ColorCounter <= 240) {
			ColorCounter += 15;
		} else {
			ColorCounter = 0;
		}
		if (bFlagSmallPlaneHP == true || ExplosionNumber > 6) {
			g.drawString("16", Explosion_X, Explosion_Y - 10 - fraction,
					Graphics.TOP | Graphics.LEFT);
			fraction++;
		} else {
			fraction = 0;
		}
	}

	// -------------------------------------------------

	/**
	 * 小飞机相关处理方法
	 */

	public void SmallPlanePacket() {
		MoveSmallPlane();
		MoveBullets();
		// bFlagMusic();
	}

	/**
	 * 小飞机相关画笔
	 */

	public void drawEnemySmallPlane(Graphics g) {
		SmallPlanefraction(g);
		if (bFlagSmallPlaneHP == false) {
			drawSmallPlane(g);
		} else {
			drawSmallPlaneExplosion(g);
			if (ExplosionNumber < 8) {
				ExplosionNumber++;
			} else {
				isMusic = false;
				ExplosionNumber = 0;
				PlaneNumber++;
				if (PlaneNumber > 4)
					PlaneNumber = 0;
				bFlagSmallPlaneHP = false;
			}
		}
		if (bFlagBulletsDisplay == false) {
			drawSmallPlaneBullets(g);
		}
	}
}

⌨️ 快捷键说明

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