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

📄 deltahealer.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		n=0;
		for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
			zlna[n++] = zln;
		}
		for(n=0;n<zlna.length;n++) {
			zlna[n].getThing().update();
		}
		zol.update();
	}
	
	/** Do the processing for a frame of animation while rotating right.  */
	protected void animateRotateRight() {
		lowerHalf.rotate(vr[0], Point3D.unitUp, 350);
		vr[1].doRotate(Point3D.origin, Point3D.unitUp, 350);
		vr[2].doRotate(Point3D.origin, Point3D.unitUp, 350);
		ZListNode zln;
		int n=0;
		for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
			n++;
		}
		ZListNode zlna[] = new ZListNode[n];
		n=0;
		for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
			zlna[n++] = zln;
		}
		for(n=0;n<zlna.length;n++) {
			zlna[n].getThing().update();
		}
		zol.update();
	}
	
	/** Returns the number of damage points to be ignored from each hit.
	 * Under standard health/armor rules, a unit cannot take less than 1 damage per hit.
	 * @return The armor value of the unit.
	 */
	protected int armor() {
		return 2;
	}
	
	/** Returns the number of Hexes to get within if in Pursuit Mode.
	 * As long as the Unit is this close to its target, it will remain stationary and fire.
	 * This allows long range Units to abuse their range advantage by staying back while firing.
	 * @return The range to approach to, in hexes.
	 */
	public int followRange() {
		return 3;
	}
	
	/** Returns the number of frames needed to move forward one hex.
	 * @return How many frames it takes to move one hex.
	 */
	protected int framesToMove() {
		return 12;
	}
	
	/** Returns the number of frames needed to rotate one hex-side.
	 * @return How many frames it takes to rotate sixty degrees.
	 */
	protected int framesToRotate() {
		return 6;
	}
	
	/** Returns The maximum value of health for this Unit, which is the initial value for health.
	 * @return The amount of damage that must be taken to destroy the Unit.
	 */
	protected int maxHealth() {
		return 200;
	}
	
	/** If a turret is available, rotate it toward the target.
	 * @return true iff the target is within the firing arc.
	 */
	protected boolean aim() {
		if(target != null && !target.repairable()) {
			target = null;
			targetSSMDS = null;
			if(mode == 2)
				mode = 0;
			return false;
		}
		Point3D vec;
		if(target != null) vec = targetSSMDS.getVector(this);
		else vec = vr[1]; //Aim forward (don't fire)
		float fore = (vec.x * vr[3].x + vec.y * vr[3].y);
		float left = (vec.y * vr[4].y + vec.x * vr[4].x);
		float cosine = (float)(fore / (Math.sqrt(fore * fore + left * left)));
		boolean aimLeft = (left > 0);
		int aimAngle;
		if(cosine > Trig.cos(1)) {
			aimAngle = 0;
		}else if(cosine > Trig.cos(2)) {
			aimAngle = 1;
		}else if(cosine > Trig.cos(3)) {
			aimAngle = 2;
		}else if(cosine > Trig.cos(4)) {
			aimAngle = 3;
		}else if(cosine > Trig.cos(5)) {
			aimAngle = 4;
		}else if(cosine > Trig.cos(10)){
			aimAngle = 5;
		}else{
			aimAngle = 10;
		}
		if(aimAngle == 0) aimLeft = true;
		upperHalf.rotate(upperHalf.getPoint(1), Point3D.unitUp, (aimLeft)?(aimAngle):(360 - aimAngle));
		vr[3].doRotate(Point3D.origin, Point3D.unitUp, (aimLeft)?(aimAngle):(360 - aimAngle));
		vr[4].doRotate(Point3D.origin, Point3D.unitUp, (aimLeft)?(aimAngle):(360 - aimAngle));
		
		int vertAngle = 0;
		if(target != null) {
			vec.z = targetSSMDS.getOther(this).getHeight() / 2f - upperHalf.getPoint(12).z;
			cosine = (float)Math.sqrt(targetSSMDS.getDistanceSquared() / vec.getLengthSquared());
		}else{
			cosine = 1;
		}
		if(cosine > Trig.cos(verticalAngle)) {
			//Aim up
			while(vertAngle < 5 && cosine > Trig.cos(verticalAngle)) {
				vertAngle++;
				verticalAngle--;
			}
			upperHalf.getPoint(14).doRotate(upperHalf.getPoint(12), vr[4], 360 - vertAngle);
			upperHalf.getPoint(15).doRotate(upperHalf.getPoint(13), vr[4], 360 - vertAngle);
		}else if(cosine < Trig.cos(verticalAngle + 1)) {
			//Aim down
			while(vertAngle < 5 && cosine < Trig.cos(verticalAngle)) {
				vertAngle++;
				verticalAngle++;
			}
			upperHalf.getPoint(14).doRotate(upperHalf.getPoint(12), vr[4], vertAngle);
			upperHalf.getPoint(15).doRotate(upperHalf.getPoint(13), vr[4], vertAngle);
		}
		
		ZListNode zln;
		int n=0;
		for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
			n++;
		}
		ZListNode zlna[] = new ZListNode[n];
		n=0;
		for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
			zlna[n++] = zln;
		}
		for(n=0;n<zlna.length;n++) {
			zlna[n].getThing().update();
		}
		zol.update();
		return (aimAngle < 5 && vertAngle < 5 && target != null && target.getPlayer() == myPlayer);		
	}
	
	/** Perform the data changes for one frame of animation while dying. */
	protected void animateDie() {
		if(frame == framesToDie())
			zol.explode(vr[0]);
		frame--;
		if(frame == 0) {
			remove();
			Hex.getHex(resX,resY).unreserve();
			Hex.getHex(x,y).leave(this);
		}
	}
	
	protected void animateMake() {
	}
	
	/** Draw this GameObject onto GameViewer v, by using v's drawing methods.
	 * @param v The GameViewer which will display this GameObject.
	 * @see netwar.gui.HexViewer
	 */
	public void draw(GameViewer v) {
		zol.draw(v);
	}
	
	/** Returns the number of frames of animation for the death sequence.
	 * @return The number of frames needed to animate death.
	 */
	protected int framesToDie() {
		return 5;
	}
	
	/** Returns the number of frames of animation for the creation sequence.
	 * @return The number of frames needed to animate creation.
	 */
	protected int framesToMake() {
		return 20;
	}
	
	/** Return the height of this GameObject for selection box and explosion hit calculations.
	 * @return The height of the GameObject in game-space units.
	 */
	public float getHeight() {
		return upperHalf.getPoint(1).z;
	}
	
	/** Return the width of this GameObject for selection box and explosion hit calculations.
	 * @return The width of the GameObject in game-space units.
	 */
	public float getWidth() {
		return 7.0f;
	}
	
	/** Return the number of frames to wait between firing shots.
	 */
	public int weaponDelay() {
		return 4;
	}
	
	/** Return the square of the maximum weapon range of this GameObject.
	 * @return The square of the weapons range in game-space units.
	 */
	public float weaponRangeSquared() {
		return 6400f;
	}
	
	public float scanRangeSquared() {
		return 25600f;
	}
	/** Target validation. If a target meets this criteria it can be acquired by scan().
	 * This version is for a healing unit.
	 */
	protected boolean validTarget(GameObject go) {
		return (go.getPlayer() != null && go.getPlayer() == myPlayer && go.repairable());
	}

	
	/** DeltaHealer fires a Laser with negative damage.
	 * Laser is a straight flying shot which can only damage its intended target.
	 * It explodes when the angle between it velocity and the vector to its target exceeds 90 degrees.
	 * <BR> Initial location = varies.
	 * <BR> Initial velocity = five units, level with the ground, in the aimed direction.
	 * <BR> Base damage = -10
	 * <BR> Radius of explosion = 5 units.
	 * <BR> Life of projectile = 18 cycles.
	 */
	protected boolean fire() {
		Projectile.newProjectile(new Laser(Color.cyan), (leftFire)?(upperHalf.getPoint(14)):(upperHalf.getPoint(15)), (leftFire)?(upperHalf.getPoint(14).getDifference(upperHalf.getPoint(12))):(upperHalf.getPoint(15).getDifference(upperHalf.getPoint(13))), -10, 25, 18, this, target);
		leftFire = !leftFire;
		return true;
	}
        public int cost() {
                return 250;
        }
}

⌨️ 快捷键说明

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