?? projectile.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;
import netwar.utils.*;
import netwar.utils.vectorgraphics.*;
/** Abstract class representing one shot fired from some weapon.
* @author Group N2 - Project Netwar
* @author Daniel Grund
*/
public abstract class Projectile {
/** The game-space location of the center of the projectile. */
protected Point3D center;
/** The velocity of the projectile, in game-space units per time-step */
protected Point3D velocity;
/** The object that fired this shot (in case it is relevant) */
protected GameObject maker;
/** The object that the shot was intended to hit (in case it is relevant) */
protected GameObject enemy;
/** Graphical representation */
protected netwar.utils.vectorgraphics.GraphicThing appearance;
/** The number of frames remaining before this projectile must cease existing (it may cease before then) */
protected int life;
/** The amount of damage the shot will deal if it hits something. */
protected int damage;
/** The square of the radius of explosion for this shot. */
protected int radiusSquared;
/** The vector containing all currently existing Projectiles. */
static protected Vector Projectiles = new LVector();
/** This method initializes a Projectile.
* This performs the following processes:
* <BR> Initializes the center, velocity, damage, radiusSquared, life, maker, and enemy fields.
* <BR> Adds the Projectile into the Vector.
* @param add The Projectile to incorporate into the game.
* @param where The initial value of center.
* @param going The initial value of velocity.
* @param power The initial value of damage.
* @param rad2 The initial value of radiusSquared.
* @param duration The initial value of life.
* @param origin The initial value of maker.
* @param target The initial value of enemy.
*/
public static void newProjectile(Projectile add, Point3D where, Point3D going, int power, int rad2, int duration, GameObject origin, GameObject target) {
add.center = new Point3D(where);
add.velocity = new Point3D(going);
add.damage = power;
add.radiusSquared = rad2;
add.life = duration;
add.maker = origin;
add.enemy = target;
add.makeGraphics();
netwar.gui.HexViewer.getHexViewer().add(add.appearance);
Projectiles.append(add);
}
/** Make the GraphicThing appearance. */
protected abstract void makeGraphics();
/** Calls update() on all Projectiles in the Vector. */
public static void UpdateAll() {
Projectiles.goFirst();
while(Projectiles.isInList()) {
if(((Projectile)Projectiles.get()).basicUpdate())
((Projectile)Projectiles.get()).Update();
Projectiles.goNext();
}
}
/** Performs functions which will be needed by most Projectiles during Update().
* Specifically, it decrements life. If life reaches zero, it calls
* Explode() if mustExplode() returns true, Fizzle() if mustExplode() returns false.
* Then it returns false. If life did not reach zero, it returns true.
*/
protected boolean basicUpdate() {
life--;
if(life == 0){
if(mustExplode())
Explode();
else
Fizzle();
}
return (life > 0);
}
/** Function to perform the processing needed during a single time-step. */
protected abstract void Update();
/** Draws all projectiles in the game onto GameViewer v
* @param v The GameViewer seeking to display all the Projectiles.
*/
public static void DrawAll(GameViewer v) {
Projectiles.goFirst();
while(Projectiles.isInList()) {
//if(((Projectile)Projectiles.get()).center is on/near the screen))
((Projectile)Projectiles.get()).draw(v);
Projectiles.goNext();
}
}
/** Displays this projectile on GameViewer v.
* @param v The GameViewer seeking to display this Projectile.
*/
public void draw(GameViewer v) {
appearance.draw(v);
}
/** Return true iff it should detonate when it's life runs out.
* @return true if this should not just Fizzle() when life runs out.
*/
protected abstract boolean mustExplode();
/** Deals damage to nearby GameObjects, makes flashy graphics, and calls Fizzle(). */
protected abstract void Explode();
/** Removes this from the game */
protected void Fizzle() {
appearance.kill();
Projectiles.goFirst();
while(Projectiles.get() != this)
Projectiles.goNext();
Projectiles.remove();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -