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

📄 planecreate.java

📁 java小型游戏项目文档与源代码,内容详细
💻 JAVA
字号:
package com.lovo.sprite.plane;

import java.awt.Image;

/**
 *  <p>创建所有飞机的类</p>
 * @author 袁渝波
 * @version 1.00 2006/9/25 袁渝波
 * <p>      1.03 2006/09/25 袁渝波 优化代码,优化注释</p>
 * @see	   EnemyPlane4
 * @see	   EnemyPlane2
 * @see	   EnemyPlane3
 * @see	   BossPlane
 * @see	   FriendPlane
 */
public class PlaneCreate
{
	/**产生飞机类的数组对象 */
	PlaneSprite	planeSprite[];

	/** 飞机图片数组 */
	Image		planeImage[];

	/** 敌飞机启始点的Y坐标 */
	int			startY1	= -100;

	/** 
	 * 构造器,初始化参数
	 * @param  planeImage 图象数组对象 所有飞机的图片
	 */
	public PlaneCreate(Image planeImage[])
	{
		this.planeImage = planeImage;
		this.planeSprite = new PlaneSprite[52];
		this.createPlane(1);
	}

	/** 
	 * 创建所有飞机
	 * @param  stage 整型数据 飞机关卡
	 */
	public void createPlane(int stage)
	{
		if (stage == 1)
		{
			/**
			 * 关卡为1时,创建第一关的所有飞机
			 */
			for (int i = 0; i <= 52; i++)
			{
				if (i <= 14)
				{
					/**
					 * 飞机对象数组中0-14为第四种飞机
					 * 创建敌人飞机,随即设定飞机坐标
					 */
					planeSprite[i] = new EnemyPlane4(this.planeImage[1]);
					planeSprite[i].setLocation((int) (Math.random() * 450),
							startY1);
					startY1 = startY1 - 550;
				}
				if (i > 14 && i <= 29)
				{
					/**
					 * 飞机对象数组中14-29为第二种飞机
					 * 创建敌人飞机,随即设定飞机坐标
					 */
					planeSprite[i] = new EnemyPlane2(this.planeImage[2]);
					planeSprite[i].setLocation((int) (Math.random() * 250),
							-(int) (Math.random() * 8000));
				}
				if (i > 29 && i <= 44)
				{
					/**
					 * 飞机对象数组中30-44为第三种飞机
					 * 创建敌人飞机,随即设定飞机坐标
					 */
					planeSprite[i] = new EnemyPlane3(this.planeImage[3]);
					planeSprite[i].setLocation(
							(int) (Math.random() * 250) + 200, -(int) (Math
									.random() * 8000));
				}
				if (i > 44 && i <= 49)
				{
					/**
					 * 飞机对象数组中45-49为第一种飞机
					 * 创建敌人飞机,随即设定飞机坐标
					 */
					planeSprite[i] = new EnemyPlane1(this.planeImage[5]);
					planeSprite[i].setLocation(
							(int) (Math.random() * 250) + 200, -(int) (Math
									.random() * 900 + 900 * (i - 45)));
				}
				if (i == 50)
				{
					/**
					 * 飞机对象数组中50为BOSS飞机
					 * 创建BOSS飞机,设定初始坐标
					 */
					planeSprite[i] = new BossPlane(this.planeImage[3]);
					planeSprite[i].setLocation(255, -5000);
				}
				if (i == 51)
				{
					/**
					 * 飞机对象数组中51为玩家飞机
					 * 创建玩家飞机,设定初始坐标
					 */
					planeSprite[i] = new FriendPlane(this.planeImage[0]);
					planeSprite[i].setLocation(255, 650);
				}
			}
		}
		if (stage == 2)
		{
			/**
			 * 关卡为2时,设定第二关的所有飞机位置
			 * 为使关卡2的飞机出现有规律,用手工设定坐标
			 */
			planeSprite[0].setLocation(250, -100);
			planeSprite[1].setLocation(200, -200);
			planeSprite[2].setLocation(300, -200);
			planeSprite[3].setLocation(150, -300);
			planeSprite[4].setLocation(350, -300);
			planeSprite[5].setLocation(250, -1400);
			planeSprite[6].setLocation(200, -1500);
			planeSprite[7].setLocation(300, -1500);
			planeSprite[8].setLocation(150, -1600);
			planeSprite[9].setLocation(350, -1600);
			planeSprite[10].setLocation(250, -3700);
			planeSprite[11].setLocation(200, -3800);
			planeSprite[12].setLocation(300, -3800);
			planeSprite[13].setLocation(150, -3900);
			planeSprite[14].setLocation(350, -3900);
			planeSprite[15].setLocation(200, -500);
			planeSprite[16].setLocation(160, -600);
			planeSprite[17].setLocation(120, -700);
			planeSprite[18].setLocation(80, -800);
			planeSprite[19].setLocation(40, -900);
			planeSprite[20].setLocation(200, -1900);
			planeSprite[21].setLocation(160, -2000);
			planeSprite[22].setLocation(120, -2100);
			planeSprite[23].setLocation(100, -2200);
			planeSprite[24].setLocation(40, -2300);
			planeSprite[25].setLocation(200, -2300);
			planeSprite[26].setLocation(160, -2400);
			planeSprite[27].setLocation(120, -2500);
			planeSprite[28].setLocation(80, -2500);
			planeSprite[29].setLocation(40, -2600);
			planeSprite[30].setLocation(300, -900);
			planeSprite[31].setLocation(340, -1100);
			planeSprite[32].setLocation(380, -1200);
			planeSprite[33].setLocation(420, -1300);
			planeSprite[34].setLocation(460, -1400);
			planeSprite[35].setLocation(300, -2300);
			planeSprite[36].setLocation(340, -2400);
			planeSprite[37].setLocation(380, -2500);
			planeSprite[38].setLocation(420, -2500);
			planeSprite[39].setLocation(460, -2600);
			planeSprite[40].setLocation(300, -3700);
			planeSprite[41].setLocation(340, -3800);
			planeSprite[42].setLocation(380, -3900);
			planeSprite[43].setLocation(420, -4000);
			planeSprite[44].setLocation(460, -4100);
			planeSprite[45].setLocation((int) (Math.random() * 450), -200);
			planeSprite[46].setLocation((int) (Math.random() * 450), -1000);
			planeSprite[47].setLocation((int) (Math.random() * 450), -3000);
			planeSprite[48].setLocation((int) (Math.random() * 450), -4000);
			planeSprite[49].setLocation((int) (Math.random() * 450), -6000);
			planeSprite[50].setLocation(255, -5600);
			planeSprite[50].setPlaneLife(300);
			planeSprite[50].setStep(5, 10);
			planeSprite[51].setLocation(255, 650);
		}
	}

	/** 
	 * 获取所有飞机对象数组
	 * @return  planeSprite 对象数组 返回所有飞机的对象数组
	 */
	public PlaneSprite[] getCreatedPlane()
	{
		return this.planeSprite;
	}
}

⌨️ 快捷键说明

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