home *** CD-ROM | disk | FTP | other *** search
- import com.next.gt.Actor;
- import com.next.gt.Gamelication;
- import java.awt.Image;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
-
- public class Ship extends Actor implements KeyListener {
- private static int MAX_NUM_BULLETS = 5;
- public int numBullets;
- public int animationDirection = 1;
- public boolean isAnimating = true;
- public boolean thrusting = false;
-
- Ship(Gamelication var1) {
- super.owner = var1;
- super.owner.play(super.owner.getCodeBase(), "sounds/warp.au");
- super.x = (double)super.owner.getSize().width / (double)2.0F;
- super.y = (double)super.owner.getSize().height / (double)2.0F;
- super.velocity_x = (double)0.0F;
- super.velocity_y = (double)0.0F;
- Image var2 = super.owner.getImage(super.owner.getCodeBase(), "images/ship.gif");
- ((Actor)this).setImage(var2, 4, 24);
- this.isAnimating = false;
- }
-
- public void keyPressed(KeyEvent var1) {
- if (var1.getKeyCode() == 39) {
- this.rotateRight(true);
- }
-
- if (var1.getKeyCode() == 37) {
- this.rotateLeft(true);
- }
-
- if (var1.getKeyCode() == 38) {
- this.thrust(true);
- }
-
- if (var1.getKeyCode() == 32) {
- this.fire();
- }
-
- }
-
- public void keyReleased(KeyEvent var1) {
- if (var1.getKeyCode() == 39) {
- this.rotateRight(false);
- }
-
- if (var1.getKeyCode() == 37) {
- this.rotateLeft(false);
- }
-
- if (var1.getKeyCode() == 38) {
- this.thrust(false);
- }
-
- }
-
- public void keyTyped(KeyEvent var1) {
- }
-
- public void calculateNewVelocity() {
- if (this.thrusting) {
- super.velocity_x += Math.cos((double)(super.currentFrame * 2) * Math.PI / (double)super.numFrames + (Math.PI / 2D)) * (double)10.0F;
- super.velocity_y += Math.sin((double)(super.currentFrame * 2) * Math.PI / (double)super.numFrames - (Math.PI / 2D)) * (double)10.0F;
- } else {
- super.velocity_x *= 0.99;
- super.velocity_y *= 0.99;
- }
- }
-
- public void calculateCurrentFrame() {
- if (this.isAnimating) {
- if (this.animationDirection == -1) {
- if (--super.currentFrame <= 0) {
- super.currentFrame = super.numFrames - 1;
- return;
- }
- } else if (++super.currentFrame >= super.numFrames) {
- super.currentFrame = 0;
- }
- }
-
- }
-
- public void rotateLeft(boolean var1) {
- if (var1) {
- this.isAnimating = true;
- this.animationDirection = 1;
- } else {
- this.isAnimating = false;
- }
- }
-
- public void rotateRight(boolean var1) {
- if (var1) {
- this.animationDirection = -1;
- this.isAnimating = true;
- } else {
- this.isAnimating = false;
- }
- }
-
- public void thrust(boolean var1) {
- if (var1) {
- this.thrusting = true;
- } else {
- this.thrusting = false;
- }
- }
-
- public void fire() {
- if (this.numBullets < MAX_NUM_BULLETS && !((Boinkaroids)super.owner).createNewPlayer) {
- Bullet var1 = new Bullet(super.owner, this);
- ++this.numBullets;
- super.owner.play(super.owner.getCodeBase(), "sounds/bullet.au");
- super.owner.actorManager.addActor(var1);
- }
-
- }
-
- public double getTheta() {
- return (double)(super.currentFrame * 2) * Math.PI / (double)super.numFrames + (Math.PI / 2D);
- }
-
- public double getSpeed() {
- return Math.sqrt(super.velocity_x * super.velocity_x + super.velocity_y * super.velocity_y);
- }
-
- protected void collideWithActor(Actor var1) {
- String var2 = var1.getClass().getName();
- if (var2.equals("Asteroid") || var2.equals("Goobie") || var2.equals("Bigoobie")) {
- this.explode();
- }
-
- }
-
- public void explode() {
- super.owner.actorManager.removeActor(this);
- Explosion var1 = new Explosion(super.owner, this);
- super.owner.actorManager.addActor(var1);
- ((Boinkaroids)super.owner).decrementShipCount();
- }
- }
-