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

📄 guiobject.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
字号:
package gui;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.*;
import java.io.*;
import java.util.*;

import javax.imageio.*;

import interfaces.*;
import base.*;

public class GuiObject implements GuiObjectInterface { 
	public BufferedImage texture, originalTexture;
	public String type;
	public Color bgColor;
	
	public AffineTransform newXform = new AffineTransform();
	
	private boolean firstScale = false;
	private WorldVector originalPosition, currentAngularPosition;
	public WorldVector positionOffset = new WorldVector();
	
	public GuiObject() {
		
	}
	
	public GuiObject(String type) {
		this.type = type;
	}
	
	public void setTexture(String image) {
		try {
			texture = ImageIO.read(new File(image));
			originalTexture = ImageIO.read(new File(image));
		} catch(Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
	public void updateTexture(WorldObject object) {
		if(((GuiObject) object.getGuiObject()).type == "Plane" && object.getObjectState().angularPosition != currentAngularPosition) {
			rotateTexture(object);
		}
		
		if(type == "Plane") {
			//scaleTexture(object);
		}
	}
	
	private void rotateTexture(WorldObject object) {
		WorldVector angularPosition = currentAngularPosition = object.getObjectState().angularPosition;
		
		int xRot = (int) object.objectState.position.x;
		int yRot = (int) object.objectState.position.y;
		
		newXform.rotate(-angularPosition.z, xRot, yRot);
	}
	
	private void scaleTexture(WorldObject object) {
		AffineTransform at = new AffineTransform();
		GuiObject thisGuiObject = ((GuiObject) object.getGuiObject());
		WorldVector thisPosition = object.getObjectState().position;

		if(!firstScale) {
			originalTexture = thisGuiObject.texture;
			originalPosition = new WorldVector(thisPosition);
			firstScale = true;
		}
		
		double scale = 1 + ((originalPosition.z - thisPosition.z) / (originalPosition.z * 2));
		if(scale < .55) {
			scale = .55;
		}
		
		at.scale(scale, scale);
		at.translate(0, ((originalTexture.getHeight() * scale) / 2));
		
		BufferedImageOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
		thisGuiObject.texture = bio.filter(originalTexture, null);
	}
}

⌨️ 快捷键说明

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