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

📄 graphicthing.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.game.GameViewer;
import netwar.utils.*;
/** Super class for a variety of drawable objects.
 * The subclasses fall into two main categories.
 * Primitive GraphicThings draw themselves directly. The represent basic shapes.
 * Nonprimitive GraphicThings contain one or more other graphic things and draw
 * themselves by drawing the GraphicThings they contain. Some or all of those
 * GraphicThings may themselves by Nonprimitive, but ultimately everything will
 * be drawn as some collection of Primitive GraphicThings.
 */
public abstract class GraphicThing {
	private ZListNode nodes[] = new ZListNode[0];
	private int numnodes = 0;
	/** Called after its data has changed, so it can inform things that are watching it.
	 * This is currently used to update the ordering of ZOrdered lists which contain this.
	 */
	public void update() {
		for(int i = 0; i < numnodes; i++)
			if(nodes[i] != null)
				nodes[i].update(getZ(nodes[i].getT()));
	}
	void addNode(ZListNode zln) {
		if(numnodes == nodes.length) {
			ZListNode nu[] = new ZListNode[numnodes + 3];
			for(int i = 0; i < numnodes; i++)
				nu[i] = nodes[i];
			nodes = nu;
		}
		nodes[numnodes++] = zln;
	}
	void remNode(ZListNode zln) {
		for(int i = 0; i < numnodes; i++) {
			if(nodes[i] == zln) {
				nodes[i] = nodes[--numnodes];
				nodes[numnodes] = null;
			}
		}
	
	}
	/** get the Z coordinate, according to Transform t
	 * Each implementation of GraphicThing defines its own rules for
	 * determining the Z value, usually using the Z values of the points
	 * that define it.
	 * @param t The transform to define the Z value.
	 * @return The Z value according to that transform.
	 */
	public abstract float getZ(Transform t);
	/** Draw this thing. 
	 * Primitive GraphicThings draw themselves.
	 * Non-primitives pass the call onto the GraphicThings they contain.
	 * @param v The object which will provide drawing services.	 
	 */
	public abstract void draw(GameViewer v);
	/** Rotate this GraphicThing.
	 * NOTE: if this GraphicThing shares points with another GraphicThing
	 * then the results could be disasterous. Use a CoherentPointSet
	 * for that situation.
	 * @param axisPt A point on the axis of rotation.
	 * @param axisDir The direction of the axis of rotation.
	 * @param angle The number of degrees to rotate.
	 * @return this GraphicThing, freshly rotated.
	 */
	public abstract GraphicThing rotate(Point3D axisPt, Point3D axisDir, int angle);
	/** Translate this GraphicThing.
	 * NOTE: if this GraphicThing shares points with another GraphicThing
	 * then the results could be disasterous. Use a CoherentPointSet
	 * for that situation.
	 * @param offset The distance and direction to move them.
	 * @return this GraphicThing, freshly rotated.
	 */
	public abstract GraphicThing translate(Point3D offset);
	/** Remove this from all Z-Ordered lists
	 * This is used when the GraphicThing is no longer part of the
	 * visible universe. (It is also used by explode to help
	 * break all previous associations).
	 */
	public void kill() {
		for(int i = numnodes - 1; i >= 0; i--)
			if(nodes[i] != null)
				nodes[i].remove();
		nodes = new ZListNode[0];
		numnodes = 0;
	}
	/** Check for visibility of the GraphicThing.
	 * @param t The transform defining the screen space in question.
	 * @return True iff the GraphicThing is visible on that transform.
	 */
	public abstract boolean isOnScreen(Transform t);
	/** Call to cause the GraphicThing to explode.
	 * The thing will replace itself with one or more DebrisFragment objects.
	 * This will call kill implicitly. Do not use this and continue using 
	 * the GraphicThing.
	 */
	public abstract void explode(Point3D epicenter);
	abstract Point3D getCenter();
	abstract void unlink();
	/** Returns a GraphicThing which is a copy of this GraphicThing.
	 * In the case of Non-primitive GraphicThings, the contained
	 * GraphicThings are also copied into the copy.
	 */
	public abstract GraphicThing copy();
}

⌨️ 快捷键说明

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