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

📄 flame.java

📁 简单的用Java做的小游戏主要是用了自己的框架来
💻 JAVA
字号:
package role;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.JFrame;

import assistant.PublicVar;

/**
 * 烟花类
 * @author Administrator
 *
 */
public class Flame extends SportRole{
	/**烟花图像数组*/
	public static Image[][] flameImage;
	
	/**烟花冲天图像*/
	public static Image flameStartImage;
	
	/**是否开始透明*/
	private boolean isAlpha;
	
	/**烟花是否爆开*/
	private boolean isSkip;
	
	/**透明度*/
	private float alpha = 1.0f; 
	
	/**烟花飞行Y坐标计数器*/
	private int tempCount;

	public Flame(int x, int y) {
		super(x, y, 3, 30, 0);
		this.img = flameStartImage;
		double tempDouble = Math.random();
		tempCount = (int)(tempDouble*40+50);
	}

	@Override
	public void move() {
		// TODO 自动生成方法存根
		if(isSkip){
			
			if(this.width<100){
			this.width+=2;
			this.height+=2;
			
			this.x-=1;
			this.y-=1;
			}
			else{
				isAlpha = true;
			}
		}
		else{
		
		if(this.y<tempCount){
			double tempDouble = Math.random();
			int tempIndex = (int)(tempDouble*4);
			
			this.img = flameImage[0][tempIndex];
			this.width = 10;
			this.height = 10;
			
			this.x-=this.width/2;
			isSkip = true;
		}
		else{
			this.y -= 3;
		}
		}
	}
	
	/**
	 * Method:       drawMyself
	 * Desctiptoin:  绘制自身图形
	 * @param g  :   画笔
	 * @param jf :   窗体画布
	 */
	public void drawMyself(Graphics g,JFrame jf){
		if(isAlpha){//开始透明
			Graphics2D g2d  =(Graphics2D)g;
			
			g2d.setComposite(AlphaComposite.getInstance(
					AlphaComposite.SRC_ATOP, alpha)); // 开始
			
			super.drawMyself(g, jf);
			
			g2d.setComposite(AlphaComposite.getInstance(
			AlphaComposite.SRC_OVER)); // 结束 
			
			alpha-=0.05f;//改变透明度
			
			if(alpha<=0){//如果透明度小于0,则移除
				PublicVar.roleList.remove(this);
			}
		}
		else{
			super.drawMyself(g, jf);
		}
	}

}

⌨️ 快捷键说明

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