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

📄 beamsniper.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		vr[0].set(lowerHalf.getPoint(14).x, lowerHalf.getPoint(14).y, 0);
		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();
	}
	
	protected void animateRotateLeft() {
		lowerHalf.rotate(vr[0], Point3D.unitUp, 5);
		vr[1].doRotate(Point3D.origin, Point3D.unitUp, 5);
		vr[2].doRotate(Point3D.origin, Point3D.unitUp, 5);
		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();
	}
	
	protected void animateRotateRight() {
		lowerHalf.rotate(vr[0], Point3D.unitUp, 355);
		vr[1].doRotate(Point3D.origin, Point3D.unitUp, 355);
		vr[2].doRotate(Point3D.origin, Point3D.unitUp, 355);
		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();
	}
	
	protected int armor() {
		return 2;
	}
	
	public int followRange() {
		return 15;
	}
	
	protected int framesToMove() {
		return 36;
	}
	
	protected int framesToRotate() {
		return 12;
	}
	
	protected int maxHealth() {
		return 175;
	}
	
	protected void update() {
		super.update();
		black.setCurrent(reload + 1);
		gray.setCurrent(reload + 1);
		team.setCurrent(reload + 1);
		darker.setCurrent(reload + 1);
		brighter.setCurrent(reload + 1);
	}
	
	public Color getMinimapColor() {
		Color hexC = Hex.getHex(x,y).getMinimapColor();
		Color mapC = new Color(
			(hexC.getRed()   * (255 - team.getAlpha()) + team.getRed()   * team.getAlpha()) / 255,
			(hexC.getGreen() * (255 - team.getAlpha()) + team.getGreen() * team.getAlpha()) / 255,
			(hexC.getBlue()  * (255 - team.getAlpha()) + team.getBlue()  * team.getAlpha()) / 255,
			255);
		return mapC;
	}
	
	/** 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.isDead()) {
			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(snipeAngle)) {
			//Aim up
			while(vertAngle < 5 && cosine > Trig.cos(snipeAngle)) {
				vertAngle++;
				snipeAngle--;
			}
			upperHalf.getPoint(13).doRotate(upperHalf.getPoint(12), vr[4], 360 - vertAngle);
		}else{
			//Aim down
			while(vertAngle < 5 && cosine < Trig.cos(snipeAngle)) {
				vertAngle++;
				snipeAngle++;
			}
			upperHalf.getPoint(13).doRotate(upperHalf.getPoint(12), 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);		
	}
	
	protected void animateDie() {
		if(frame == framesToDie())
			zol.explode((new Point3D(0,0,-5)).doSum(vr[0]));
		frame--;
		if(frame == 0) {
			remove();
			Hex.getHex(resX,resY).unreserve();
			Hex.getHex(x,y).leave(this);
		}
	}
	
	protected void animateMake() {
	}
	
	public void draw(GameViewer v) {
		zol.draw(v);
	}
	
	protected int framesToDie() {
		return 5;
	}
	
	protected int framesToMake() {
		return 20;
	}
	
	public float getHeight() {
		return upperHalf.getPoint(12).z;
	}
	
	public float getWidth() {
		return 7.0f;
	}
	
	public int weaponDelay() {
		return 99;
	}
	
	public float weaponRangeSquared() {
		return 90000f;
	}
	
	public float scanRangeSquared() {
		return 25600f;
	}
	
	/** Beam Sniper fires a Laser.
	 * 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 = twenty units, aimed at the enemies half-height, in the aimed direction.
	 * <BR> Base damage = 105
	 * <BR> Radius of explosion = 5 units.
	 * <BR> Life of projectile = 17 cycles.
	 */
	protected boolean fire() {
		Projectile.newProjectile(new Laser(Color.blue), upperHalf.getPoint(13), upperHalf.getPoint(13).getDifference(upperHalf.getPoint(12)).doProduct(4), 105, 25, 17, this, target);
		return true;
	}
        public int cost() {
                return 750;
        }
}

⌨️ 快捷键说明

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