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

📄 blood.java

📁 坦克大战 有关卡 有显示 有大招 等等 功能
💻 JAVA
字号:
package leo.tank;

import java.awt.*;
import java.util.Random;

/**
 * 用于构建血块
 * @author 黄思志 030402129
 *
 */
public class Blood {
	int x,y,w,h;
	TankWar tw;
	private boolean live = false;
	private static Random r = new Random();
	private int step = 0; 	
	private boolean stepDis;
	
	/**
	 * 血块飞行轨迹设计
	 */
	private int[][] pos = {
			{300,290},{305,300},{310,310},{315,290},{325,340},
			{330,310},{335,300},{340,300},{345,310},{350,320},
			{355,310},{360,290},{365,320},{355,300},{360,320},
			{375,310},{380,320},{385,310},{390,290},{395,300},
			{400,290},{405,300},{410,310},{415,290},{425,340},
			{430,310},{435,300},{440,300},{445,310},{450,320},
			{455,310},{460,290},{465,320},{455,300},{460,320},
			{475,310},{480,320},{485,310},{490,290},{495,300}
	};
	
	public Blood() {
		x = pos[0][0];
		y = pos[0][1];
		w = 25;
		h = 15;
	}
	public Blood(TankWar tw) {
		this();
		this.tw = tw;
	}
	/**
	 * 自绘方法
	 * @param g
	 */
	public void draw(Graphics g) {
		if(!live) {
			if(Blood.r.nextInt(1000) > 999 -(tw.gameLevel+tw.gameThrough)) {
				live = true;
			} else
			return;
		}
		Color c = g.getColor();
		g.setColor(Color.MAGENTA);
		g.fillOval(x, y, w, h);
		g.setColor(c);
		move();
	}

	/**
	 * 移动方法
	 *
	 */
	private void move() {
		if(step == 0){
			stepDis = true;			
		}
		if(step == pos.length-1){
			stepDis = false;
		}
		if(stepDis) step ++;
		else step --;
		x = pos[step][0];
		y = pos[step][1];
	}
	
	/**
	 * 获取外接矩形,用于碰撞检测
	 * @return
	 */
	public Rectangle getRect() {
		return new Rectangle (x,y,w,h);
	}

	/**
	 * 是否生存
	 * @return
	 */
	public boolean isLive() {
		return live;
	}

	/**
	 * 设置是否生存
	 * @param live
	 */
	public void setLive(boolean live) {
		this.live = live;
	}
}

⌨️ 快捷键说明

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