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

📄 stealthfighter.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 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.game.unit;
import netwar.game.*;
import netwar.utils.*;
import netwar.utils.vectorgraphics.*;
import netwar.game.projectile.BallisticShell;
import java.awt.*;

/** Temporary Unit class. This will be removed in Iteration 2, when the real Units are created.
 * This is a moderate speed, fragile, long range combatant.
 * It has low armor, and uses a slow fire weapon (which is good against high armor targets).
 * @author Group N2 - Project Netwar
 * @author Daniel Grund
 */
public class StealthFighter extends Unit {
	OrderedGraphicSet ogs;
	/** Constuctor. This Unit has no special parameters. */
	public StealthFighter(){
	}
	/** Unit default2 requires 10 frames to move forward one hex.
	 * @return 10
	 */
	protected int framesToMove(){
		return 10; //return the number of frames needed to move one hex.
	}
	/** Unit default2 requires 6 frames to rotate one hex-side.
	 * @return 6
	 */
	protected int framesToRotate(){
		return 6; //return the number of frames needed to rotate one hex-side.
	}
	/** Unit default2 requires 10 frames to be created.
	 * @return 10
	 */
	protected int framesToMake(){
		return 20;
	}
	/** Unit default2 uses 10 frames to display a death scene.
	 * @return 10
	 */
	protected int framesToDie(){
		return 10;
	}
	protected void createVectors()
	{
		int i = f * 60 + 30;
		vr = new Point3D[1];

		vr[0] = Hex.getMapPoint(x,y);
		ogs = new OrderedGraphicSet(new GraphicTriangle(new Point3D(5, 0, 0),
								     new Point3D(-3, -4, 0),
								     new Point3D(-3, 4, 0),
                                                                     new Color(0,0,0,48)),
									4);
                Color c = new Color(myPlayer.getColor().getRed(), myPlayer.getColor().getGreen(), myPlayer.getColor().getBlue(), 48);
		ogs.add(new GraphicTriangle(new Point3D(5, 0, 0),
					     new Point3D(-3, 0, 0),
					     new Point3D(-3, 0, 5),
					     myPlayer.getColor()),
					     false);
		ogs.add(new GraphicLine(new Point3D(5,0,0), new Point3D(-3, 0, 5), myPlayer.getColor()), false);
		ogs.add(new GraphicLine(new Point3D(-3,0,0), new Point3D(-3, 0, 5), myPlayer.getColor()), false);
		ogs.translate(vr[0]);
		ogs.rotate(vr[0], Point3D.unitUp, i);
//		netwar.gui.HexViewer.getHexViewer().add(ogs);
	}
	/** Unit default 2 is drawn as two triangles.
	 * A black triangle is drawn on ground level.
	 * A team-color triangle is drawn like a fin, extending up from the black triangle.
	 */
	public void draw(GameViewer v) {
		ogs.draw(v);
	}
	/** Requests that the GraphicThing(s) used by this object be added to GameViewer v.
	 * @param v The GameViewer which will be displaying the object.
	 */
	public void addTo(GameViewer v) {
		v.add(ogs);
	}
	public void killGraphics() {
		ogs.kill();
	}
	
	/** Unit default2 moves forward by sliding. No articulate animation is used. */
	protected void animateMove(){
		//Update the necessary vectors to move forward during one frame.
		int i = Trig.normalize(f * 60 + 30);
		Point3D pt = new Point3D(Trig.cos(i) * 2, Trig.sin(i) * 2,0);
		vr[0].doSum(pt);
		ogs.translate(pt);
	}			
	/** Unit default2 rotates left by sliding. No articulate animation is used. */
	protected void animateRotateLeft(){
		ogs.rotate(vr[0], Point3D.unitUp, 10);
	}
	/** Unit default2 rotates right by sliding. No articulate animation is used. */
	protected void animateRotateRight(){
		ogs.rotate(vr[0], Point3D.unitUp, 350);
	}
	/** Unit default2 is created by the fin extending up from the black triangle. */
	protected void animateMake() {
//		vr[5].z += 0.5f;
	}
	/** Unit default2 dies by shrinking into a point. */
	protected void animateDie() {
/*		int i;
		for(i = 1; i < 6; i++)
		{
			vr[i].x /= 2f;
			vr[i].y /= 2f;
		}
		vr[5].z -= 0.5f;
*/
		frame--;
		if(frame == 0)
		{
			ogs.kill();
			remove();
			Hex.getHex(x,y).leave(this);
			Hex.getHex(resX,resY).unreserve();
		}
	}

//	protected void think() { //Default is ok for this one.

	
	/** Unit default2 is 5 units tall.
	 * @return 5
	 */
	public float getHeight() {
		return 5.0f;
	}
	/** Unit default2 is 5 units wide.
	 * @return 5
	 */
	public float getWidth() {
		return 5.0f;
	}

	/** Unit default2 has a weapon range of 200 units, or 10 hexes.
	 * @return 40000
	 */
	public float weaponRangeSquared(){
		return 40000.0f;
	}
	/** Unit default2 pursues to a range of 8 hexes.
	 * @return 8
	 */
	public int followRange(){
		return 8;
	}

	/** Unit default2 must wait 20 frames between shots.
	 * @return 20
	 */
	public int weaponDelay(){
		return 20;
	}

	/** Unit default2 fires a ProjectileDefault2.
	 * Projectile default2 is an arcing shot which can only damage its intended target.
	 * It explodes when it hits the ground.
	 * <BR> Initial location = the upper tip of the fin.
	 * <BR> Initial velocity = 10 units horizontally toward the target, plus a vertical component determined by the range.
	 * <BR> Base damage = 25
	 * <BR> Radius of explosion = 10 units.
	 * <BR> Life of projectile = 50 cycles.
	 */
	protected boolean fire() {
		Point3D pt = new Point3D(targetSSMDS.getVector(this));
		float up = (pt.getLength() - 20f) / 20f;
		pt.Normalize();
		pt.doProduct(10);
		pt.z += up;
		
		Projectile.newProjectile(new BallisticShell(), vr[0].getSum(new Point3D(0,0,3.125)), pt, 25, 100, 50, this, target);
		return true;

	}
	/** Unit default2 has a maximum of 120 health.
	 * @return 120
	 */
	protected int maxHealth() {
		return 120;
	}
	/** Unit default2 has an armor rating of 3
	 * @return 3
	 */
	protected int armor() {
		return 3;
	}
	/** Returns the cost to build this object.
	 * Non-buildable objects have a cost of zero.
	 * @return The cost of the object.
	 */
	public int cost() {
		return 150;
	}

}


⌨️ 快捷键说明

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