?? bush.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.object;
import netwar.game.*;
import netwar.utils.*;
import netwar.utils.vectorgraphics.*;
/** Palm tree object. Destroyable obstacle.
* @author Group N2 - Project Netwar
* @author Kyle Kakligian
*/
public class Bush extends netwar.game.GameObject {
// colors
private static java.awt.Color ltgreen = new java.awt.Color(0, 192, 0);
private static java.awt.Color drgreen = new java.awt.Color(64, 96, 0);
// point list
protected static SelfConvertingPoint _pts[] = {
new SelfConvertingPoint(0, 0, 0),
new SelfConvertingPoint(-1.20000, -0.75000, 3.45000),
new SelfConvertingPoint(-1.20000, -2.22580, 2.62082),
new SelfConvertingPoint( 0.20357, -1.20605, 2.62082),
new SelfConvertingPoint(-1.70988, -2.31924, 1.95000),
new SelfConvertingPoint(-0.26746, 2.09395, 2.47082),
new SelfConvertingPoint( 1.46746, 2.09395, 2.47082),
new SelfConvertingPoint( 1.42500, 0.63194, 3.07598),
new SelfConvertingPoint( 1.93488, 1.33373, 2.58860),
new SelfConvertingPoint(-3.05357, -0.45605, 2.02082),
new SelfConvertingPoint(-2.51746, 1.19395, 2.02082),
new SelfConvertingPoint(-3.05357, 0.45605, 0.67918),
new SelfConvertingPoint(-2.15988, 1.56924, 1.35000),
new SelfConvertingPoint( 3.35357, -0.45605, 1.27082),
new SelfConvertingPoint(-0.86746, 2.54395, 0.97082),
new SelfConvertingPoint( 0.65478, 2.38584, 1.20125),
new SelfConvertingPoint( 2.03087, 1.38403, 1.37762),
new SelfConvertingPoint(-0.86185, 1.34196, 1.49583),
new SelfConvertingPoint(-0.62304, 0.51415, 2.66026),
new SelfConvertingPoint( 0.21454, -0.41681, 2.52585),
new SelfConvertingPoint(-0.90018, -1.94722, 1.07329),
new SelfConvertingPoint(-0.04841, -1.73228, 1.57598),
new SelfConvertingPoint(-2.20240, 0.17948, 0.00000),
new SelfConvertingPoint( 3.34632, 0.51029, 0.00000),
new SelfConvertingPoint(-1.12584, -1.97007, 0.00000),
new SelfConvertingPoint( 0.66979, -2.30141, 0.00000),
new SelfConvertingPoint(-0.62976, 2.75424, 0.00000)};
protected static CoherentPointSet points = new CoherentPointSet(_pts.length);
protected static GraphicThing appearance= null;
protected VirtualCoherentGraphicThing myAppearance;;
/** Creates a new instance of PineTree */
public Bush() {
}
/** Initialize the Point3Ds used for this Base.
* These are the location of the ground-center of the Base in game-space, and
* the relative locations of the triangle/line vertices relative to that point.
*/
protected void createVectors() {
vr = new Point3D[1];
vr[0] = Hex.getMapPoint(x,y);
if(appearance == null) {
appearance = new OrderedGraphicSet( new GraphicTriangle( _pts[19], _pts[ 3], _pts[ 21], drgreen), _pts.length);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[11], _pts[ 22], _pts[ 9], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[22], _pts[ 20], _pts[ 4], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[9], _pts[ 22], _pts[ 4], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[16], _pts[ 8], _pts[ 7], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[5], _pts[ 15], _pts[ 17], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[16], _pts[ 6], _pts[ 8], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[15], _pts[ 6], _pts[ 16], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[12], _pts[ 17], _pts[ 22], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[11], _pts[ 12], _pts[ 22], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[10], _pts[ 12], _pts[ 11], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[26], _pts[ 16], _pts[ 23], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[23], _pts[ 16], _pts[ 13], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[23], _pts[ 13], _pts[ 25], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[20 ], _pts[24], _pts[ 25], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[20], _pts[ 22], _pts[ 24], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[14], _pts[ 26], _pts[ 22], drgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[1], _pts[ 9], _pts[ 4], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[2], _pts[ 1], _pts[ 4], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[19], _pts[ 18], _pts[ 1], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[19], _pts[ 1], _pts[ 3], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[3], _pts[ 1], _pts[ 2], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[21], _pts[ 3], _pts[ 2], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[20], _pts[ 21], _pts[ 4], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[21], _pts[ 2], _pts[ 4], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[7], _pts[ 18], _pts[ 19], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[7], _pts[ 5], _pts[ 18], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[6], _pts[ 5], _pts[ 7], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[8], _pts[ 6], _pts[ 7], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[5], _pts[ 17], _pts[ 18], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[18], _pts[ 17], _pts[ 1], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[6], _pts[ 15], _pts[ 5], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[26], _pts[ 15], _pts[ 16], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[26], _pts[ 14], _pts[ 15], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[10], _pts[ 9], _pts[ 1], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[17], _pts[ 10], _pts[ 1], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[10], _pts[ 11], _pts[ 9], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[17], _pts[ 12], _pts[ 10], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[16], _pts[ 7], _pts[ 13], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[13], _pts[ 7], _pts[ 25], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[21], _pts[ 20], _pts[ 25], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[7], _pts[ 21], _pts[ 25], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[7], _pts[ 19], _pts[ 21], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[17], _pts[ 14], _pts[ 22], ltgreen), false);
((OrderedGraphicSet)appearance).add(new GraphicTriangle( _pts[15], _pts[ 14], _pts[ 17], ltgreen), false);
for(int t = 0; t < _pts.length; t++)
points.add(_pts[t]);
}
if(netwar.Mapper.theApp != null) myAppearance = new VirtualCoherentGraphicThing(appearance, points, vr[0], (new java.util.Random()).nextInt(360));
else myAppearance = new VirtualCoherentGraphicThing(appearance, points, vr[0], netwar.Netwar.netwar.random.nextInt(360));
}
/** Returns false, because the tree has no weapon.
* @return false
*/
protected boolean aim() {
return false;
}
/** Perform the data changes for one frame of animation while dying. */
protected void animateDie() {
if(frame == framesToDie()) {
Hex.getHex(x,y).unreserve();
Hex.getHex(x,y).leave(this);
myAppearance.explode(vr[0]);
}
frame--;
if(frame == 0)
remove();
}
/** Perform the data changes for one frame of animation while being made.
* Pine trees pre-exist: there is no formation animation.
*/
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) {
myAppearance.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(myAppearance);
}
public void killGraphics() {
myAppearance.kill();
}
/** Returns the number of frames of animation for the death sequence.
* @return 5
*/
protected int framesToDie() {
return 10;
}
/** Returns the number of frames of animation for the creation sequence.
* @return 0
*/
protected int framesToMake() {
return 0;
}
/** Return the height of this GameObject for selection box and explosion hit calculations.
* @return 20
*/
public float getHeight() {
return 20f;
}
/** Return the width of this GameObject for selection box and explosion hit calculations.
* @return 5
*/
public float getWidth() {
return 6.2f;
}
/** Clear the current long-term goal. */
public void setGoal() {
}
/** Set the current long-term goal to a GameObject.
* This is a tree. It does not use the goal system.
* @param u The GameObject which is the goal.
*/
public void setGoal(GameObject u) {
}
/** Set the current long-term goal to a location, at hex coordinate (gx, gy).
* This is a tree. It does not use the goal system.
* @param gx The x coordinate of the goal, in hex coords.
* @param gy The y coordinate of the goal, in hex coords.
*/
public void setGoal(int gx, int gy) {
}
/** Perform operations for this time step.
* Specifically, perform the Point3D transforms for any/all animations,
* fire at an enemy if possible, and do any required decision making.
* This is a tree. It is only animated if it is dying.
*/
protected void update() {
if(action == 5)
animateDie();
}
/** Return the number of frames to wait between firing shots.
* @return 0
*/
public int weaponDelay() {
return 0;
}
/** Return the square of the maximum weapon range of this GameObject.
* @return 0
*/
public float weaponRangeSquared() {
return 0f;
}
public boolean isDead() {
return (action == 5);
}
public boolean damageable() {
return (action != 5);
}
/** The tree uses the 'threshold damage system'.
* If sufficient damage (15 or more) is dealt in one blow,
* the tree is destroyed.
*/
public void recieveDamage(int dam) {
if(dam >= 15) {
action = 5;
frame = framesToDie();
}
}
static final String[] PROPERTIES = {};
protected String[] PROPERTIES() {
return PROPERTIES;
}
protected String getProperty(int p) {
switch(p) {
default:
Assert.notFalse(false, "getProperty(int) error.");
}
return null;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -