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

📄 itemsprite.java

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

import java.awt.Graphics;
import java.awt.Image;

/**
 *  <p>道具类</p>
 *  
 * @author 袁渝波
 * @version 1.00 2006/9/25 袁渝波
 * <p>      1.03 2006/09/27 袁渝波 优化代码,优化注释</p>
 * @see    SuperSprite
 *
 */
public class ItemSprite extends SuperSprite
{
	/**道具图片 */
	Image		itemImage;

	public int	itemType;

	public ItemSprite(Image itemImage, int itemType)
	{
		this.itemType = itemType;
		this.itemImage = itemImage;
		this.setStep(8, -5);
		this.width = itemImage.getWidth(null);
		this.height = itemImage.getHeight(null);
	}

	/**
	 *  绘制道具
	 */
	public void paintSprite(Graphics g)
	{
		/**
		 *  道具为显示时就绘制
		 */
		if (this.visible == true)
			g.drawImage(itemImage, X, Y, null);
	}

	/**
	 *  计算道具运行路线
	 */
	public void updateState()
	{
		/**
		 * 道具显示了更新坐标移动
		 */
		if (this.isVisible())
		{
			Y = this.getY() + VY;
			X = this.getX() + VX;
			if (this.getX() <= 10)
				this.setStep(8, VY);
			if (this.getX() >= 470)
				this.setStep(-8, VY);
			if (this.getY() <= 10)
				this.setStep(VX, 4);
		}
	}
}

⌨️ 快捷键说明

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