?? flamebeetle.java
字號(hào):
/*
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.utils.*;
import netwar.utils.vectorgraphics.*;
import netwar.game.*;
import netwar.game.projectile.FlameWeapon;
import java.awt.*;
/** Temporary Unit class. This will be removed in Iteration 2, when the real Units are created.
* This is a fast, durable, short range combatant.
* It has good armor, and uses a rapid fire weapon (which is good against low armor targets).
* Because of its long range, it has an extended scan range so that it can automatically approach enemies.
* @author Group N2 - Project Netwar
* @author Daniel Grund
*/
public class FlameBeetle extends Unit{
ZOrderedList zol;
CoherentPointSet cps;
/** Constructor. This Unit has no special parameters. */
public FlameBeetle(){
netwar.utils.vectorgraphics.Transform t;
if(netwar.Mapper.theApp == null) t = netwar.gui.HexViewer.getHexViewer().getTransform();
else t = netwar.mapper.HexViewerM.getHexViewer().getTransform();
zol = new ZOrderedList(t);
cps = new CoherentPointSet(34);
// The following line is slowing the game down a lot
// netwar.Netwar.netwar.soundPlayer.play("sound/UnitBuy1.wav");
}
/** Flame Beetle requires 5 frames to move forward one hex.
* @return 5
*/
protected int framesToMove(){
return 5; //return the number of frames needed to move one hex.
}
/** Flame Beetle requires 5 frames to rotate one hex-side.
* @return 5
*/
protected int framesToRotate(){
return 5; //return the number of frames needed to rotate one hex-side.
}
/** Flame Beetle requires 10 frames to be created.
* @return 10
*/
protected int framesToMake(){
return 20;
}
/** Flame Beetle spends 10 frames doing 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);
//Pilot Lite
cps.add(new SelfConvertingPoint(9,0,0)); //0
cps.add(new SelfConvertingPoint(9.2f,0.2f,0)); //1
cps.add(new SelfConvertingPoint(9.4f,0,0)); //2
cps.add(new SelfConvertingPoint(9.2f,-0.2f,0)); //3
cps.add(new SelfConvertingPoint(9.2f,0,0.4f)); //4
zol.add(new GraphicTriangle(cps.getPoint(0), cps.getPoint(2), cps.getPoint(4), Color.red));
zol.add(new GraphicTriangle(cps.getPoint(1), cps.getPoint(3), cps.getPoint(4), Color.red));
zol.add(new GraphicParallelogram(cps.getPoint(0), cps.getPoint(1), cps.getPoint(2), cps.getPoint(3), Color.red));
//Front panel with SIGMA
cps.add(new SelfConvertingPoint(9,-4,0)); //5
cps.add(new SelfConvertingPoint(9,4,0)); //6
cps.add(new SelfConvertingPoint(7,-4,2)); //7
cps.add(new SelfConvertingPoint(7,4,2)); //8
cps.add(new SelfConvertingPoint(7.5f,2,1.5f)); //9
cps.add(new SelfConvertingPoint(7.5f,-2,1.5f)); //10
cps.add(new SelfConvertingPoint(8,0,1)); //11
cps.add(new SelfConvertingPoint(8.5f,-2,0.5f)); //12
cps.add(new SelfConvertingPoint(8.5f,2,0.5f)); //13
OrderedGraphicSet ogs = new OrderedGraphicSet(
new GraphicParallelogram(cps.getPoint(5), cps.getPoint(6), cps.getPoint(8), cps.getPoint(7), myPlayer.getColor()), 5);
ogs.add(new GraphicLine(cps.getPoint(9), cps.getPoint(10), myPlayer.getColor().darker()), false);
ogs.add(new GraphicLine(cps.getPoint(10), cps.getPoint(11), myPlayer.getColor().darker()), false);
ogs.add(new GraphicLine(cps.getPoint(11), cps.getPoint(12), myPlayer.getColor().darker()), false);
ogs.add(new GraphicLine(cps.getPoint(12), cps.getPoint(13), myPlayer.getColor().darker()), false);
zol.add(ogs);
//Side and rear panels.
cps.add(new SelfConvertingPoint(7,-4,0)); //14
cps.add(new SelfConvertingPoint(-7,-4,0)); //15
cps.add(new SelfConvertingPoint(-7,-4,2)); //16
cps.add(new SelfConvertingPoint(-9,-2,0)); //17
cps.add(new SelfConvertingPoint(-9,-2,2)); //18
cps.add(new SelfConvertingPoint(-9,2,0)); //19
cps.add(new SelfConvertingPoint(-9,2,2)); //20
cps.add(new SelfConvertingPoint(-7,4,0)); //21
cps.add(new SelfConvertingPoint(-7,4,2)); //22
cps.add(new SelfConvertingPoint(7,4,0)); //23
zol.add(new GraphicTriangle(cps.getPoint(14), cps.getPoint(5), cps.getPoint(7), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(14), cps.getPoint(7), cps.getPoint(16), cps.getPoint(15), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(15), cps.getPoint(16), cps.getPoint(18), cps.getPoint(17), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(17), cps.getPoint(18), cps.getPoint(20), cps.getPoint(19), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(19), cps.getPoint(20), cps.getPoint(22), cps.getPoint(21), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(21), cps.getPoint(22), cps.getPoint(8), cps.getPoint(23), myPlayer.getColor()));
zol.add(new GraphicTriangle(cps.getPoint(23), cps.getPoint(6), cps.getPoint(8), myPlayer.getColor()));
//Top of base of unit.
cps.add(new SelfConvertingPoint(-7,0,2)); //24
cps.add(new SelfConvertingPoint(5,-4,2)); //25
cps.add(new SelfConvertingPoint(5,4,2)); //26
cps.add(new SelfConvertingPoint(7,-2,2)); //27
cps.add(new SelfConvertingPoint(7,2,2)); //28
cps.add(new SelfConvertingPoint(5,0,2)); //29
zol.add(new GraphicTriangle(cps.getPoint(24), cps.getPoint(20), cps.getPoint(18), myPlayer.getColor().darker()));
zol.add(new GraphicTriangle(cps.getPoint(27), cps.getPoint(28), cps.getPoint(29), myPlayer.getColor().darker()));
zol.add(new GraphicTriangle(cps.getPoint(27), cps.getPoint(25), cps.getPoint(7), myPlayer.getColor().darker()));
zol.add(new GraphicTriangle(cps.getPoint(28), cps.getPoint(26), cps.getPoint(8), myPlayer.getColor().darker()));
//Fuel tanks.
cps.add(new SelfConvertingPoint(5,-2,4)); //30
cps.add(new SelfConvertingPoint(5,2,4)); //31
cps.add(new SelfConvertingPoint(-7,-2,4)); //32
cps.add(new SelfConvertingPoint(-7,2,4)); //33
zol.add(new GraphicTriangle(cps.getPoint(27), cps.getPoint(30), cps.getPoint(25), Color.lightGray.brighter()));
zol.add(new GraphicTriangle(cps.getPoint(28), cps.getPoint(31), cps.getPoint(26), Color.darkGray.brighter()));
zol.add(new GraphicTriangle(cps.getPoint(27), cps.getPoint(30), cps.getPoint(29), Color.darkGray.brighter()));
zol.add(new GraphicTriangle(cps.getPoint(28), cps.getPoint(31), cps.getPoint(29), Color.lightGray.brighter()));
zol.add(new GraphicParallelogram(cps.getPoint(30), cps.getPoint(25), cps.getPoint(16), cps.getPoint(32), Color.lightGray));
zol.add(new GraphicParallelogram(cps.getPoint(31), cps.getPoint(26), cps.getPoint(22), cps.getPoint(33), Color.darkGray));
zol.add(new GraphicParallelogram(cps.getPoint(30), cps.getPoint(29), cps.getPoint(24), cps.getPoint(32), Color.darkGray));
zol.add(new GraphicParallelogram(cps.getPoint(31), cps.getPoint(29), cps.getPoint(24), cps.getPoint(33), Color.lightGray));
zol.add(new GraphicTriangle(cps.getPoint(18), cps.getPoint(32), cps.getPoint(16), Color.lightGray.darker()));
zol.add(new GraphicTriangle(cps.getPoint(20), cps.getPoint(33), cps.getPoint(22), Color.darkGray.darker()));
zol.add(new GraphicTriangle(cps.getPoint(18), cps.getPoint(32), cps.getPoint(24), Color.darkGray.darker()));
zol.add(new GraphicTriangle(cps.getPoint(20), cps.getPoint(33), cps.getPoint(24), Color.lightGray.darker()));
cps.translate(vr[0]);
cps.rotate(vr[0], Point3D.unitUp, i);
// netwar.gui.HexViewer.getHexViewer().add(zol);
}
/** Flame Beetle is drawn as two triangles.
* The triangles form together to form a triangle with a slight fold.
* One triangle is the slightly brighter than the team color,
* the other is slightly darker.
*/
public void draw(GameViewer v) {
if(health > 0)
zol.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) {
if(health > 0)
v.add(zol);
}
public void killGraphics() {
zol.kill();
}
/** Flame Beetle moves by sliding. There is no articulate animation. */
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) * 4, Trig.sin(i) * 4,0);
vr[0].doSum(pt);
cps.translate(pt);
}
/** Flame Beetle rotates left by sliding. There is no articulate animation */
protected void animateRotateLeft(){
cps.rotate(vr[0], Point3D.unitUp, 12);
}
/** Flame Beetle rotates right by sliding. There is no articulate animation */
protected void animateRotateRight(){
cps.rotate(vr[0], Point3D.unitUp, 348);
}
/** Flame Beetle forms by shifting the triangles from a nearly verticle form to the standard shape. */
protected void animateMake() {
}
/** Flame Beetle explodes. */
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 think() { //Default is ok for this one.
/** Flame Beetle is 1.0 units tall.
* @return 1
*/
public float getHeight() {
return 4.0f;
}
/** Flame Beetle is 7.0 units wide.
* @return 7
*/
public float getWidth() {
return 9.0f;
}
/** Flame Beetle has a weapon range of 40.0 units, or 2 hexes.
* @return 1600
*/
public float weaponRangeSquared(){
return 1600.0f;
}
/** Flame Beetle uses a scan range of 160.0 units, or 8 hexes.
* @return 25600
*/
public float scanRangeSquared(){
return 25600.0f;
}
/** Flame Beetle pursues to a range of 1 hexes.
* unless it is attacking a base. Then it has a range of two.
* @return 1 or 2
*/
public int followRange(){
if(target != null && target.getPlayer() != null && target == target.getPlayer().getBase())
return 2;
else
return 1;
}
/** Flame Beetle can fire every frame.
* @return 0
*/
public int weaponDelay(){
return 0;
}
/** Flame Beetle fires a FlameWeapon.
*/
protected boolean fire() {
Point3D pt = new Point3D(targetSSMDS.getVector(this));
pt.doSum(vr[0]).doDifference(cps.getPoint(0)).doProduct(1/6f);
Projectile.newProjectile(new FlameWeapon(), cps.getPoint(0), pt, 7, 41, 6, this, target);
return true;
}
/** Flame Beetle has a maximum of 100 health.
* @return 100
*/
protected int maxHealth() {
return 100;
}
/** Flame Beetle has an armor rating of 7
* @return 7
*/
protected int armor() {
return 7;
}
/** 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 100;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -