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

📄 graphicline.java

📁 NetWar是一个实时策略游戏
💻 JAVA
字号:
/*
	Netwar
	Copyright (C) 2002  Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
 
	This file is part of Netwar.
 
	Netwar is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
 
	Netwar is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
 
	You should have received a copy of the GNU General Public License
	along with Netwar; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package netwar.utils.vectorgraphics;
import netwar.utils.*;
import java.awt.Color;
import netwar.game.GameViewer;

/** Primitive GraphicThing.
 * This represents a line to be drawn from one point to another in a particular color.
 */
public class GraphicLine extends GraphicThing {
	private SelfConvertingPoint a;
	private SelfConvertingPoint b;
	private Color c;
	/** Create a GraphicLine without external point control.
	 * The object can only be moved by calling translate and rotate.
	 * @param A One initial endpoint.
	 * @param B The other initial endpoint.
	 * @param C The color of the line segment.
	 */
	public GraphicLine(Point3D A, Point3D B, Color C) {
		a = new SelfConvertingPoint(A);
		b = new SelfConvertingPoint(B);
		c = C;
	}
	/** Create a GraphicLine with external point control.
	 * The object can be manipulated by changing A and B outside the class.
	 * @param A One endpoint.
	 * @param B The other endpoint.
	 * @param C The color of the line segment.
	 */
	public GraphicLine(SelfConvertingPoint A, SelfConvertingPoint B, Color C) {
		a = A;
		b = B;
		c = C;
	}
	public float getZ(Transform t) {
		Point3D pt = new Point3D(a);
		float Z;
		Z = a.getScreenPoint(t).z;
		Z += b.getScreenPoint(t).z;
		Z /= 2;
		return Z;
	}
	public void draw(GameViewer v) {
		if(!isOnScreen(v.getTransform()))
			return;
		v.setColor(c);
		v.drawLine(a,b);
	}
	public GraphicThing rotate(Point3D axisPt, Point3D axisDir, int angle) {
		a.doRotate(axisPt, axisDir, angle);
		b.doRotate(axisPt, axisDir, angle);
		update();
		return this;
	}
	public GraphicThing translate(Point3D offset) {
		a.doSum(offset);
		b.doSum(offset);
		update();
		return this;
	}
	public boolean isOnScreen(Transform t) {
		return (a.isOnScreen(t) || b.isOnScreen(t));
	}
	public void explode(Point3D epicenter) {
		kill();
		unlink();
		Point3D center = getCenter();
		Point3D velocity = center.getDifference(epicenter);
		netwar.game.Projectile.newProjectile(new netwar.game.projectile.DebrisFragment(this), center, velocity, 0, 0, 100, null, null);
	}
	Point3D getCenter() {
		return a.getSum(b).doProduct(0.5f);
	}
	void unlink() {
		a = new SelfConvertingPoint(a);
		b = new SelfConvertingPoint(b);
	}
	public GraphicThing copy() {
		GraphicLine gl = new GraphicLine(a,b,c);
		gl.unlink();
		return gl;
	}
}

⌨️ 快捷键说明

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