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

📄 orderedgraphicset.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.*;

/** Nonprimitive GraphicThing
 * Collection of graphic things, drawn together in a fixed order.
 * Use example: A triangle with writing on it in lines. 
 * Always draw the triangle first, and the lines immediately afterward.
 */
public class OrderedGraphicSet  extends GraphicThing {
	private GraphicThing gts[];
	private int count;
	private int primary;
	/** Create this OrderedGraphicSet with one GraphicThing. Tell it how many to expect. 
	 * @param gt The first GraphicThing in the set. By default, it is the 'primary'.
	 * @param expect The number of GraphicThings to expect.
	 */
	public OrderedGraphicSet(GraphicThing gt, int expect) {
		gts = new GraphicThing[expect];
		gts[0] = gt;
		count = 1;
		primary = 0;
	}
	
	/** Add a GraphicThing. 
	 * If more GraphicThings are added then expected, the array will expand to fit (slow).
	 * @param gt The new GraphicThing to add.
	 * @param pri If true, this GraphicThing will be the 'primary'
	 */
	public void add(GraphicThing gt, boolean pri) {
		if(pri)
			primary = count;
		if(count == gts.length) {
			//If an unexpected extra graphic thing comes in, don't die, but cope with it.
			GraphicThing temp[] = new GraphicThing[count + 1];
			for(int i=0; i<count; i++)
				temp[i] = gts[i];
			gts = temp;
		}
		gts[count++] = gt;
	}
	
	/** Get the Z coordinate, according to Transform t  
	 * @param t The Transform defining the Z coordinate.
	 * @return the Z value of the 'primary' GraphicThing.
	 */
	public float getZ(Transform t) {
		return gts[primary].getZ(t);
	}
	
	/** Draw all the things, in the order they were added.  
	 * @param v The object which will provide drawing services.	 
	 */
	public void draw(GameViewer v) {
		if(!isOnScreen(v.getTransform()))
			return;
		for(int i = 0; i < count; i++)
			gts[i].draw(v);
	}
	public GraphicThing translate(Point3D offset) {
		for(int i = 0; i < count; i++)
			gts[i].translate(offset);
		update();
		return this;
	}
	public GraphicThing rotate(Point3D axisPt, Point3D axisDir, int angle) {
		for(int i = 0; i < count; i++)
			gts[i].rotate(axisPt, axisDir, angle);
		update();
		return this;
	}
	
	/** Check for visibility of the 'primary' GraphicThing.
	 * @param t The transform defining the screen space in question.
	 * @return True iff the 'primary' GraphicThing is visible on that transform.
	 */
	public boolean isOnScreen(Transform t) {
		return gts[primary].isOnScreen(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.
	 * NOTE: OrderedGraphicSet explodes as a single solid object.
	 * So for our triangle with writing example, the triangle flips off with
	 * the writing still on it (visible on both sides).
	 */
	public void explode(Point3D epicenter) {
		kill();
		unlink();
		Point3D center = gts[primary].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 gts[primary].getCenter();
	}
	void unlink() {
		for(int i = 0; i < count; i++)
			gts[i].unlink();
	}
	public GraphicThing copy() {
		OrderedGraphicSet ogs = new OrderedGraphicSet(gts[0].copy(), gts.length);
		for(int i = 1; i < gts.length; i++)
			if(gts[i] != null)
				ogs.add(gts[i].copy(), primary == i);
		return ogs;
	}
}

⌨️ 快捷键说明

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