home *** CD-ROM | disk | FTP | other *** search
- head 1.7;
- access;
- symbols;
- locks; strict;
- comment @# @;
-
-
- 1.7
- date 98.04.15.16.07.58; author mds1274; state Exp;
- branches;
- next 1.6;
-
- 1.6
- date 98.04.15.15.48.12; author mds1274; state Exp;
- branches;
- next 1.5;
-
- 1.5
- date 98.04.15.15.41.04; author mds1274; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 98.04.14.16.33.47; author jgh8962; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 98.04.11.16.20.09; author jgh8962; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 98.04.10.18.25.57; author jgh8962; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 98.04.10.17.53.49; author jgh8962; state Exp;
- branches;
- next ;
-
-
- desc
- @@
-
-
- 1.7
- log
- @*** empty log message ***
- @
- text
- @/*
- *
- * Ship.java
- * @@author Mark G. Tacchi (mtacchi@@next.com)
- * @@version 0.8
- * Mar 11/1996
- *
- * The ship is controlled by the user, it registers for specific keyboard
- * events to handle control.
- *
- * This Actor collides with Asteroids and Goobies. It is responsible for
- * creating an explosion object.
- *
- */
-
- import java.awt.event.*;
- import java.lang.Math;
- import java.awt.*;
-
- import com.next.gt.*;
-
- public class Ship extends Actor implements KeyListener{
-
- //
- // Limit number of bullets on the screen at once
- //
- private static int MAX_NUM_BULLETS= 5;
- public int numBullets= 0;
-
- //
- // Animation. ccw= 1, cw= -1
- //
- public int animationDirection= 1;
- public boolean isAnimating= true;
-
- //
- // Is thrusting
- //
- public boolean thrusting= false;
-
- Ship(Gamelication theOwner) {
- super();
-
- Image theImage;
- owner = theOwner;
-
- //owner.addKeyListener( this );
-
- //
- // play warp in sound
- //
- owner.play(owner.getCodeBase(), "sounds/warp.au");
-
- x= (owner.getSize().width/2.0);
- y= (owner.getSize().height/2.0);
- velocity_x= 0;
- velocity_y= 0;
- String theImageName= "images/ship.gif";
-
- theImage= owner.getImage(owner.getCodeBase(), "images/ship.gif");
- setImage (theImage, 4, 24);
- isAnimating= false;
-
- } /*Ship()*/
-
-
-
- /**
- * Handle keyboard events that control ship.
- */
- public void keyPressed( KeyEvent k ){
- if(k.getKeyCode() == k.VK_RIGHT )
- this.rotateRight(true);
- if(k.getKeyCode() == k.VK_LEFT )
- this.rotateLeft(true);
- if(k.getKeyCode() == k.VK_UP )
- this.thrust(true);
- if( k.getKeyCode() == k.VK_SPACE ) {
- this.fire();
- }
- }
-
- public void keyReleased( KeyEvent k ){
- if(k.getKeyCode() == k.VK_RIGHT )
- this.rotateRight(false);
- if(k.getKeyCode() == k.VK_LEFT )
- this.rotateLeft(false);
- if(k.getKeyCode() == k.VK_UP )
- this.thrust(false);
- }
-
- public void keyTyped( KeyEvent k ){
-
- }
-
-
-
- /**
- * If ship is thrusting, then velocity is increasing. Use friction if
- * not thrusting.
- */
- public void calculateNewVelocity() {
- if (thrusting) {
- velocity_x+= Math.cos(currentFrame*2*Math.PI/numFrames + Math.PI/2)*10;
- velocity_y+= Math.sin(currentFrame*2*Math.PI/numFrames - Math.PI/2)*10;
- }
- else {
- velocity_x*= 0.99;
- velocity_y*= 0.99;
- }
-
- } /*calculateNewVelocity*/
-
- /**
- * Animation of the ship is based on theta, display accordingly.
- */
- public void calculateCurrentFrame() {
- if (isAnimating) {
- if (animationDirection== -1) {
- if (--currentFrame<=0) currentFrame= numFrames - 1;
- }
- else {
- if (++currentFrame>=numFrames) currentFrame= 0;
- }
- } /*endif*/
-
- } /*calculateCurrentFrame*/
-
-
- /**
- * Handle left rotation.
- */
- public void rotateLeft (boolean keydown) {
- if (keydown) {
- isAnimating= true;
- animationDirection= 1;
- }
- else {
- isAnimating= false;
- }
-
- } /*rotateLeft*/
-
-
-
- /**
- * Handle right rotation.
- */
- public void rotateRight (boolean keydown) {
- if (keydown) {
- animationDirection= -1;
- isAnimating= true;
- }
- else {
- isAnimating= false;
- }
-
- } /*rotateRight*/
-
-
-
- /**
- * Handle thrust.
- */
- public void thrust (boolean keydown) {
- if (keydown) {
- thrusting= true;
- }
- else {
- thrusting= false;
- }
-
- } /*thrust*/
-
-
-
- /**
- * Fire bullet.
- */
- public void fire() {
- if (numBullets<MAX_NUM_BULLETS&&!((Boinkaroids)owner).createNewPlayer) {
- Bullet aBullet = new Bullet(owner, this);
-
- numBullets++;
- owner.play(owner.getCodeBase(), "sounds/bullet.au");
- owner.actorManager.addActor(aBullet);
- } /*endif*/
-
- } /*fire*/
-
-
-
- /**
- * Accessor methods (bullet uses this).
- */
-
- /**
- * Ship's angle.
- */
- public double getTheta() {
- return (currentFrame*2*Math.PI/numFrames + Math.PI/2);
- } /*getTheta*/
-
-
-
- /**
- * Ship's speed.
- */
- public double getSpeed() {
- return Math.sqrt(velocity_x*velocity_x + velocity_y*velocity_y);
- } /*getSpeed*/
-
-
-
- /**
- * Handle collision with an actor.
- */
- protected void collideWithActor (Actor theActor)
- {
- String theActorClassName= theActor.getClass().getName();
-
- if (theActorClassName.equals("Asteroid") ||
- theActorClassName.equals("Goobie") ||
- theActorClassName.equals("Bigoobie") ) {
- explode();
- } /*endif*/
-
- } /*collideWithActor*/
-
-
-
- /**
- * Explode ship.
- */
- public void explode()
- {
- Explosion anExplosion;
-
- //
- // Tell the ActorManager that I'm gone, and an Explosion Actor
- // should be added.
- //
- owner.actorManager.removeActor(this);
- anExplosion= new Explosion(owner, this);
- owner.actorManager.addActor(anExplosion);
-
- //
- // Lower ship counter.
- //
- ((Boinkaroids)owner).decrementShipCount();
-
- } /*explode*/
-
-
- } /*Ship*/
- @
-
-
- 1.6
- log
- @*** empty log message ***
- @
- text
- @d47 1
- a47 1
- owner.addKeyListener( this );
- @
-
-
- 1.5
- log
- @*** empty log message ***
- @
- text
- @a16 1
- import java.applet.AudioClip;
- d24 5
- a28 5
- //
- // Limit number of bullets on the screen at once
- //
- private static int MAX_NUM_BULLETS= 5;
- public int numBullets= 0;
- d30 5
- a34 5
- //
- // Animation. ccw= 1, cw= -1
- //
- public int animationDirection= 1;
- public boolean isAnimating= true;
- d36 4
- a39 4
- //
- // Is thrusting
- //
- public boolean thrusting= false;
- d42 1
- a42 1
- super();
- d44 2
- a45 2
- Image theImage;
- owner = theOwner;
- d47 1
- a47 1
- owner.addKeyListener( this );
- d49 4
- a52 4
- //
- // play warp in sound
- //
- owner.play(owner.getCodeBase(), "sounds/warp.au");
- d54 5
- a58 5
- x= (owner.getSize().width/2.0);
- y= (owner.getSize().height/2.0);
- velocity_x= 0;
- velocity_y= 0;
- String theImageName= "images/ship.gif";
- d60 3
- a62 3
- theImage= owner.getImage(owner.getCodeBase(), "images/ship.gif");
- setImage (theImage, 4, 24);
- isAnimating= false;
- d103 8
- a110 8
- if (thrusting) {
- velocity_x+= Math.cos(currentFrame*2*Math.PI/numFrames + Math.PI/2)*10;
- velocity_y+= Math.sin(currentFrame*2*Math.PI/numFrames - Math.PI/2)*10;
- }
- else {
- velocity_x*= 0.99;
- velocity_y*= 0.99;
- }
- d118 8
- a125 8
- if (isAnimating) {
- if (animationDirection== -1) {
- if (--currentFrame<=0) currentFrame= numFrames - 1;
- }
- else {
- if (++currentFrame>=numFrames) currentFrame= 0;
- }
- } /*endif*/
- d134 7
- a140 7
- if (keydown) {
- isAnimating= true;
- animationDirection= 1;
- }
- else {
- isAnimating= false;
- }
- d150 7
- a156 7
- if (keydown) {
- animationDirection= -1;
- isAnimating= true;
- }
- else {
- isAnimating= false;
- }
- d166 6
- a171 6
- if (keydown) {
- thrusting= true;
- }
- else {
- thrusting= false;
- }
- d181 2
- a182 3
-
- if (numBullets<MAX_NUM_BULLETS&&!((Boinkaroids)owner).createNewPlayer) {
- Bullet aBullet = new Bullet(owner, this);
- d184 4
- a187 5
- numBullets++;
- owner.play(owner.getCodeBase(), "sounds/bullet.au");
- //aBullet= new Bullet(owner, this);
- owner.actorManager.addActor(aBullet);
- } /*endif*/
- d201 1
- a201 1
- return (currentFrame*2*Math.PI/numFrames + Math.PI/2);
- d210 1
- a210 1
- return Math.sqrt(velocity_x*velocity_x + velocity_y*velocity_y);
- d220 1
- a220 1
- String theActorClassName= theActor.getClass().getName();
- d222 5
- a226 5
- if (theActorClassName.equals("Asteroid") ||
- theActorClassName.equals("Goobie") ||
- theActorClassName.equals("Bigoobie") ) {
- explode();
- } /*endif*/
- d237 1
- a237 1
- Explosion anExplosion;
- d239 7
- a245 7
- //
- // Tell the ActorManager that I'm gone, and an Explosion Actor
- // should be added.
- //
- owner.actorManager.removeActor(this);
- anExplosion= new Explosion(owner, this);
- owner.actorManager.addActor(anExplosion);
- d247 4
- a250 4
- //
- // Lower ship counter.
- //
- ((Boinkaroids)owner).decrementShipCount();
- @
-
-
- 1.4
- log
- @*** empty log message ***
- @
- text
- @d44 3
- a46 3
-
- Image theImage;
- owner= theOwner;
- d63 1
- a63 1
- isAnimating= false;
- d79 1
- a79 1
- if( k.getKeyCode() == k.VK_SPACE )
- d81 1
- a130 1
-
- @
-
-
- 1.3
- log
- @*** empty log message ***
- @
- text
- @d44 1
- a44 3
-
- System.out.println( "Making a ship." );
-
- d79 1
- a79 2
- if( k.getKeyCode() == k.VK_SPACE ) {
- System.out.println( "keyPressed calling fire." );
- a80 1
- }
- a182 1
- System.out.println( "Fire called." );
- @
-
-
- 1.2
- log
- @Blah.
- @
- text
- @d45 2
- d81 2
- a82 1
- if( k.getKeyCode() == k.VK_SPACE )
- d84 1
- d187 1
- d189 1
- a189 1
- Bullet aBullet;
- d193 1
- a193 1
- aBullet= new Bullet(owner, this);
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d16 1
- a16 1
- //import java.applet.Applet;
- d23 1
- a23 1
- public class Ship extends Actor implements EventHandler{
- d48 2
- a63 6
-
- int events[]= { Event.KEY_ACTION,
- Event.KEY_ACTION_RELEASE,
- Event.KEY_PRESS,
- Event.KEY_RELEASE
- };
- a64 2
- owner.eventManager.registerForEventNotification(this,events);
-
- d72 10
- a81 46
- public boolean handleRequestedEvent (AWTEvent theEvent) {
- switch(theEvent.getID) {
- case Event.KEY_ACTION:
- switch(theEvent.key) {
- case Event.RIGHT:
- this.rotateRight(true);
- return true;
- case Event.LEFT:
- this.rotateLeft(true);
- return true;
- case Event.UP: //THRUST ON
- this.thrust(true);
- return true;
- } /*endSwitch*/
- break;
- case Event.KEY_ACTION_RELEASE:
- switch(theEvent.key) {
- case Event.RIGHT:
- this.rotateRight(false);
- return true;
- case Event.LEFT:
- this.rotateLeft(false);
- return true;
- case Event.UP: //THRUST OFF
- this.thrust(false);
- return true;
- } /*endSwitch*/
- break;
- case Event.KEY_PRESS:
- switch(theEvent.key) {
- case 32:
- this.fire();
- return true;
- } /*endSwitch*/
- break;
- case Event.KEY_RELEASE:
- switch(theEvent.key) {
- case 32:
- return true;
- } /*endSwitch*/
- break;
- } /*endSwitch*/
-
- return false;
-
- } /*handleRequestedEvent*/
- d83 8
- d92 1
- d94 4
- a113 2
-
-
- d183 1
- a183 1
- if (numBullets<MAX_NUM_BULLETS) {
- @
-