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

📄 abstractactiveobject.java

📁 Java 编写的蛋蛋游戏 对初学者的编程有一定的帮助 需要的可下来
💻 JAVA
字号:
package mqqqvpppm.activeObject;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;


/**
 * @author mqqqvpppm
 * 
 * TODO this class offer a set of method to record and deal with
 *  a active object's state: * location, speed, mess, force... * 
 * 
 * Create on Sep 6,2005
 */
public abstract class AbstractActiveObject {

	public abstract void paint(Graphics2D g);

	public abstract boolean isInArea(Point point);

	// abstract boolean isInArea(AbstractActiveObject activeObject);

	public Point getPointAfter(int millisecond) {
		int x;
		int y;
		x = (int) (this.x + vX * millisecond + 0.5 * fX * millisecond
				* millisecond / mess);
		y = (int) (this.y + vY * millisecond + 0.5 * (fY + fG) * millisecond
				* millisecond / mess);
		return new Point(x, y);
	}	
	
	public double getVxAfter(int millisecond){
		return vX + fX*millisecond/mess;
	}
	
	public double getVyAfter(int millisecond){
		return vY + (fY+fG)*millisecond/mess;
	}

	// public int getWidth() {
	// return width;
	// }
	//
	// public int getHeight() {
	// return height;
	// }

	// public Point getCenterPoint(){
	// return new Point(centerX,centerY);
	// }

	public Dimension getDeminsion() {
		return new Dimension(width, height);
	}

	public Point getPoint() {
		return new Point(x, y);
	}

	public Rectangle getBounds() {
		return new Rectangle(x, y, width, height);
	}
	
	public double getVx(){
		return vX;
	}
	
	public double getVy(){
		return vY;
	}
	
	public int getX(){
		return x;
	}
	
	public int getY(){
		return y;
	}
	
	public int getWidth(){
		return width;
	}
	
	public int getHeight(){
		return height;
	}

	public int getPriority() {
		return priority;
	}
	
	public void setX(int x){
		this.x = x;
	}
	
	public void setY(int y){
		this.y = y;
	}

	public void setPoint(Point point) {
		this.x = point.x;
		this.y = point.y;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	
	public void setDeminsion(Dimension deminsion){
		this.width = deminsion.width;
		this.height = deminsion.height;
	}

	public void setBounds(Rectangle bounds) {
		this.x = bounds.x;
		this.y = bounds.y;
		this.width = bounds.width;
		this.height = bounds.height;
	}

	public void setFx(double fX) {
		this.fX = fX;
	}

	public void setFy(double fY) {
		this.fY = fY;
	}

	public void setFg(double FG) {
		this.fG = FG;
	}
	
	public void setVx(double vX){
		this.vX = vX;
	}
	
	public void setVy(double vY){
		this.vY = vY;
	}

	public void setMess(double mess) {
		this.mess = mess;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}
	
	public void setRandomX(double min, double max) {
		x = (int) randomBetween(min, max);
	}

	public void setRandomY(double min, double max) {
		y = (int) randomBetween(min, max);
	}
	
	public void setRandomWidth(double min, double max) {
		width = (int) randomBetween(min, max);
	}

	public void setRandomHeight(double min, double max) {
		height = (int) randomBetween(min, max);
	}

	public void setRandomPoint(int minX, int maxX, int minY, int maxY) {
		x = (int) randomBetween(minX, maxX);
		y = (int) randomBetween(minY, maxY);
	}

	public void setRandomDeminsion(int minWidth, int maxWidth, int minHeight,
			int maxHeight) {
		width = (int) randomBetween(minWidth, maxWidth);
		height = (int) randomBetween(minHeight, maxHeight);
	}

	public void setRandomVx(int min, int max){
		vX = randomBetween(min, max);
	}
	
	public void setRandomVx(double min, double max) {
		vX = randomBetween(min, max);
	}

	public void setRandomVy(double min, double max) {
		vY = randomBetween(min, max);
	}

	public void setRandomFx(double min, double max) {
		fX = randomBetween(min, max);
	}

	public void setRandomFf(double min, double max) {
		fY = randomBetween(min, max);
	}

	public void setRandomMess(double min, double max) {
		mess = randomBetween(min, max);
	}
	
	public void setImage(Image image){
		this.image = image;
	}
	
	public Image getImage(){
		return image;
	}

	// get a random value between min and max
	private double randomBetween(int min, int max) {
		return min + (int) (Math.random() * (max - min));
	}

	private double randomBetween(double min, double max) {
		return min + Math.random() * (max - min);
	}
	
	
	/*
	* If need, you can load a image to your active object, 
	* After call setImage(), 
	* the following variable will hand it
	*/
	private Image image;

	// for location and size
	private int x;

	private int y;

	// private int centerX;
	//	
	// private int centerY;

	private int width = 0;

	private int height = 0;

	// for active
	private double vX = 0; // velocity on x axis

	private double vY = 0; // velocity on y axis

	private double fX = 0; // force on x axis

	private double fY = 0; // force on y axis

	private double fG = 0; // gravitation;

	private double mess = 1; // mass

	private int priority = 0;// priority for paint

}

⌨️ 快捷键说明

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