package pnf;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Fight {
	BufferedImage[] hoof = new BufferedImage[8];
	BufferedImage[] rush = new BufferedImage[8];
	BufferedImage[] stop = new BufferedImage[6];
	
	BufferedImage[] attack1 = new BufferedImage[10];
	BufferedImage[] attack2 = new BufferedImage[11];
	BufferedImage[] attack3 = new BufferedImage[9];
	BufferedImage image;
	/**人物宽高*/
	int w,h;
	/**人物位置*/
	int x,y;
	/**速度*/
	int[] speed = new int[2];
	/**人物状态*/
	int state;
	/**行走*/
	public static final int HOOF = 0;
	/**奔跑*/
	public static final int RUSH = 1;
	/**站立*/
	public static final int STOP = 2;
	/**攻击*/
	public static final int ATTACK = 3;
	
	public Fight() throws IOException {
		//人物三次攻击
		for (int i = 0; i < attack1.length; i++) {
			attack1[i] = ImageIO.read(new File("素材/pg1_"+(i+1)+".png"));
		}
		for (int i = 0; i < attack2.length; i++) {
			attack2[i] = ImageIO.read(new File("素材/pg2_"+(i+1)+".png"));
		}
		for (int i = 0; i < attack3.length; i++) {
			attack3[i] = ImageIO.read(new File("素材/pg3_"+(i+1)+".png"));
		}
		//人物行进状态
		for (int i = 0; i < hoof.length; i++) {
			hoof[i] = ImageIO.read(new File("lib/xz_"+(i+1)+".png"));
		}
		for (int i = 0; i < rush.length; i++) {
			rush[i] = ImageIO.read(new File("lib/bp_"+(i+1)+".png"));
		}
		for (int i = 0; i < stop.length; i++) {
			stop[i] = ImageIO.read(new File("lib/zl_"+(i+1)+".png"));
		}
		state = STOP;
		w = attack1[0].getWidth();
		h = attack1[0].getHeight();
		x = 100;
		y = 100;
		speed[0] = 7;
		speed[1] = 10;
		image = stop[0];
	}
	void rightMove(){
		x += speed[state];
		if(x >= 1200-w) {
			x -= speed[state];
		}
	}
	void leftMove(){
		x -= speed[state];
		if(x<=-116) {
			x += speed[state];
		}
	}
	void upMove(){
		y -= speed[0];
		if(y<=-30) {
			y += speed[0];
		}
	}
	void downMove(){
		y += speed[0];
		if(y>=660-h) {
			y -= speed[0];
		}
	}
	protected static int index = 0;
	/**人物图片切换*/
	void step(){
		BufferedImage[] fight = null;
		switch (state) {
		case STOP:
			fight = stop;
			break;
		case HOOF:
			fight = hoof;
			break;
		case RUSH:
			fight = rush;
			break;
		}
		if (fight != null) {
			this.image = fight[index++/2%fight.length];
			w = image.getWidth();
			h = image.getHeight();
		}
	}
}
