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

import javax.imageio.ImageIO;

public class Dinosaur {
	int x, y;// 坐标
	BufferedImage image;// 图片
	BufferedImage image1, image2, image3;
	int stepTimer = 0;// 计时器
	int fresh = GamePanel.FRESH;// 刷新时间

	boolean jumpState = false;// 跳跃的状态

	int jumpHeight = 130;// 跳跃的高度
	final int LOWEST_Y = 120;// 最低坐标

	int jumpValue = 0;// 跳跃增变量

	public Dinosaur() {
		try {
			image1 = ImageIO.read(new File("image/恐龙1.png"));
			image2 = ImageIO.read(new File("image/恐龙2.png"));
			image3 = ImageIO.read(new File("image/恐龙3.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		x = 50;
		y = LOWEST_Y;

	}

	public void move() {// 移动
		step();// 踏步
		if (jumpState) {// 当起跳的时候
			if (y >= LOWEST_Y) {// 如果站在地上
				jumpValue = -5;
			}
			if (y <= LOWEST_Y - jumpHeight) {
				jumpValue = 5;
			}
			y += jumpValue;
			if (y >= LOWEST_Y) {
				jumpState = false;
			}

		}
	}

	void step() {// 踏步
		int tmp = stepTimer / 250 % 3; // 每四分之一秒换一张图片
		switch (tmp) {
		case 0:
			image = image1;
			break;
		case 1:
			image = image2;
			break;
		default:
			image = image3;
			break;
		}

		stepTimer += fresh;// 计时器递增

	}

	public void jump() {// 跳跃
		jumpState = true;
	}

	public Rectangle getHeadBounds() {
		return new Rectangle(x + 66, y + 25, 34, 24);
	}

	public Rectangle getfeedBounds() {
		return new Rectangle(x + 26, y + 60, 40, 19);
	}
}
