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

📄 enemybullet2.java

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

import java.awt.Image;
import javax.swing.JFrame;
import com.lovo.factory.BulletCreate;
import com.lovo.sprite.plane.PlaneSprite;

/**
 *  <p>敌方子弹2,捕捉飞机位置设为子弹飞行方向</p>
 * @author mlz
 * @version 1.00 2006/9/25 mlz
 * 
 *
 */
public class EnemyBullet2 extends BulletSprite
{
	/** 设置子弹初始化执行一次 */
	boolean	isStepAccount	= true;

	public EnemyBullet2(Image bulletImgage, PlaneSprite plane)
	{
		super(bulletImgage, plane);
	}

	/**
	 * 构造器,处理子弹移动
	 */
	public void updateState()
	{
		/** 子弹显示时移动 */
		if (this.isVisible() == true)
		{
			/** 子弹超出边界时设置隐藏 */
			if (Y > this.frameHeight || X < 0 || X > this.frameWidth)
			{
				this.setVisible(false);
				isStepAccount = true;
			} else
			{
				/** 设置子弹飞行的步长,并只设置一次 */
				if (isStepAccount)
				{
					/** 设置子弹移动步长VX、VY */
					try
					{
						VX = (this.getX() - BulletCreate.friendps.getX())
								/ ((this.getY() - BulletCreate.friendps.getY()) / VY);
					} catch (Exception e)
					{
						VX = 0;
					}
					/** 友机在敌机下时,设置子弹移动步长-VX、-VY */
					if (this.getY() > BulletCreate.friendps.getY())
					{
						this.setStep(-VX, -VY);
					} else
					{
						/** 友机在敌机上面时,设置子弹移动步长VX、VY */
						this.setStep(VX, VY);
					}
					isStepAccount = false;
				}
				/** 设置子弹的位置 */
				Y = this.getY() + speed * (int) (VY / 1.5);
				X = this.getX() + speed * (int) (VX / 1.5);
			}
		} else
		{
			/** 开火时设置子弹显示并初始化其位置 */
			if (plane.isFire() && plane.isVisible())
			{
				this.setVisible(true);
				this.setLocation(plane.getX() + plane.getWidth() / 2
						- this.getWidth() / 2, plane.getY() + plane.getHeight()
						+ this.getHeight() / 2);
			}
		}
	}
}

⌨️ 快捷键说明

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