home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / Gamelication / examples / Boinkaroids / RCS / Boinkaroids.java,v < prev    next >
Encoding:
Text File  |  1998-04-22  |  12.5 KB  |  788 lines

  1. head    1.11;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @# @;
  6.  
  7.  
  8. 1.11
  9. date    98.04.22.19.59.10;    author mds1274;    state Exp;
  10. branches;
  11. next    1.10;
  12.  
  13. 1.10
  14. date    98.04.20.21.19.54;    author mds1274;    state Exp;
  15. branches;
  16. next    1.9;
  17.  
  18. 1.9
  19. date    98.04.19.17.36.50;    author mds1274;    state Exp;
  20. branches;
  21. next    1.8;
  22.  
  23. 1.8
  24. date    98.04.15.16.04.47;    author mds1274;    state Exp;
  25. branches;
  26. next    1.7;
  27.  
  28. 1.7
  29. date    98.04.15.15.57.57;    author mds1274;    state Exp;
  30. branches;
  31. next    1.6;
  32.  
  33. 1.6
  34. date    98.04.15.15.34.20;    author mds1274;    state Exp;
  35. branches;
  36. next    1.5;
  37.  
  38. 1.5
  39. date    98.04.15.15.32.57;    author mds1274;    state Exp;
  40. branches;
  41. next    1.4;
  42.  
  43. 1.4
  44. date    98.04.14.16.33.47;    author jgh8962;    state Exp;
  45. branches;
  46. next    1.3;
  47.  
  48. 1.3
  49. date    98.04.11.16.20.09;    author jgh8962;    state Exp;
  50. branches;
  51. next    1.2;
  52.  
  53. 1.2
  54. date    98.04.10.18.25.57;    author jgh8962;    state Exp;
  55. branches;
  56. next    1.1;
  57.  
  58. 1.1
  59. date    98.04.10.17.53.49;    author jgh8962;    state Exp;
  60. branches;
  61. next    ;
  62.  
  63.  
  64. desc
  65. @@
  66.  
  67.  
  68. 1.11
  69. log
  70. @*** empty log message ***
  71. @
  72. text
  73. @/**
  74.  *
  75.  * Boinkaroids.java
  76.  * @@author    Mark G. Tacchi (mtacchi@@next.com) 
  77.  * @@version    0.8
  78.  * Mar 27/1996
  79.  *
  80.  * Boinkaroids is an Asteroids type game developed for the purpose of showing
  81.  * off the Gamelet Toolkit.  It makes use of all of the features within the
  82.  * Gamelet Toolkit.
  83.  *
  84.  */
  85.  
  86. import java.awt.*;
  87. import java.io.*;
  88. import java.awt.event.*;
  89. import java.util.*;
  90.  
  91. import com.next.gt.*;
  92.  
  93. public class Boinkaroids extends Gamelication implements BonusHandler, KeyListener{
  94.  
  95.     //
  96.     // Boinkaroids variables
  97.     //
  98.     public Ship        player = null;
  99.     public int        numShips;
  100.     private int        badGuyCount;
  101.     public int        level;
  102.   
  103.     //
  104.     // Should a player be created?
  105.     //
  106.     public boolean    createNewPlayer = true;
  107.   
  108.     //
  109.     // Score label.
  110.     //
  111.     private Label        myLabel;
  112.   
  113.     //
  114.     // This area that has to be clear for a ship to enter level.
  115.     //
  116.     private int        SAFETY_ZONE_WIDTH= 128;
  117.     private int        SAFETY_ZONE_HEIGHT= 128;
  118.   
  119.   
  120. /**
  121.  * Initialize.
  122.  */
  123. public void init(int x, int y) {
  124.     super.init( x, y, "./" );
  125.     myLabel= new Label("Score: 00000000" + "   Ships: " + numShips
  126.               + "   Level: "+ level);
  127.     //f.add("South",myLabel);
  128.  
  129.   
  130.     //
  131.     // initialize the score manager
  132.     //
  133.     scoreManager= new ScoreManager();
  134.     scoreManager.registerForBonusNotification(this, 20000);  
  135.  
  136.   
  137.     //
  138.     // show the main window
  139.     //
  140.  
  141.     //
  142.     // cache images
  143.     //
  144.     new ImageManager(this);
  145.   
  146.     addKeyListener( this );
  147.  
  148.     this.newGame();  
  149.     //
  150.     // paint background image
  151.     //
  152.     displayManager.setBackgroundTile (getImage(getCodeBase(), "images/background.gif"));
  153.  
  154.     start();
  155.     run();
  156. } /*init*/
  157.  
  158.  
  159. /**
  160.  * Set up the new game.
  161.  */
  162. public void newGame() {
  163.     scoreManager.setScore (0);
  164.     numShips= 3;
  165.     badGuyCount= 0;
  166.     level= 0;
  167.     removePlayer();
  168.     actorManager.removeAllActors();
  169.     this.createActors();
  170. } /*newGame*/
  171.  
  172.  
  173. /**
  174.  * Advance levels.
  175.  */
  176. public void newLevel() {
  177.     level++;
  178.     actorManager.removeAllActors();
  179.     this.createActors();
  180. } /*newLevel*/
  181.  
  182.  
  183. /**
  184.  * Create the actors for this scene.
  185.  */
  186. public void createActors() {
  187.     for (int i= 0; i< 2*level; i++) {
  188.         actorManager.addActor (new Asteroid(this, null, "gumball", 
  189.                 Asteroid.LARGE_SIZE));
  190.         addOneBadGuy();
  191.     } /*nexti*/ 
  192.     for (int i= 0; i< 0.5*level; i++) {
  193.         actorManager.addActor (new Bigoobie(this));
  194.         addOneBadGuy(); 
  195.     } /*next_i*/
  196.     this.createPlayer();
  197. } /*createActors*/
  198.  
  199. /**
  200.  *  Remove one bad guy
  201.  */
  202. public void removeOneBadGuy(){
  203.     badGuyCount--;
  204. }
  205.  
  206. /**
  207.  *  Remove one bad guy
  208.  */
  209. public void addOneBadGuy(){
  210.     badGuyCount++;
  211. }
  212.  
  213. /**
  214.  * Create the player object.
  215.  */
  216. public void createPlayer() {
  217.     removePlayer();
  218.     player = new Ship(this);
  219.     addKeyListener(player);
  220.     actorManager.addActor (player);
  221.     createNewPlayer = false;
  222. } /*createPlayer*/
  223.  
  224.  
  225. /**
  226.  * Remove the player object.
  227.  */
  228. public void removePlayer() {
  229.     if (player!=null) {
  230.         actorManager.removeActor(player);
  231.         removeKeyListener( player );
  232.         player = null;
  233.     } /*endif*/
  234. } /*createPlayer*/
  235.  
  236.  
  237. /**
  238.  * Override tick to test for specific game events.
  239.  */
  240. public void tick() {
  241.     super.tick();
  242.     myLabel.setText("Score: " + scoreManager.score + "   Ships: " + numShips
  243.               + "   Level: "+ level );
  244.               
  245.     if (badGuyCount <= 0)
  246.         this.newLevel();
  247.         
  248.     if (createNewPlayer) {
  249.         Rectangle myRectangle= new Rectangle((int)this.getSize().width/2 - SAFETY_ZONE_WIDTH/2,
  250.                     (int)this.getSize().height/2 - SAFETY_ZONE_HEIGHT/2,
  251.                 SAFETY_ZONE_WIDTH,
  252.                 SAFETY_ZONE_HEIGHT);
  253.         if (!actorManager.isActorIn(myRectangle)) {
  254.             createNewPlayer = false;
  255.             this.createPlayer();
  256.         } /*endif*/
  257.     } /*endif*/
  258. } /*tick*/
  259.  
  260.  
  261. /**
  262.  * Handle keyboard events that control ship.
  263.  */
  264. public void keyPressed( KeyEvent k ){
  265.     if(k.getKeyCode() == k.VK_F1 )
  266.         this.newGame();
  267. }
  268.  
  269. public void keyReleased( KeyEvent k ){
  270. }
  271.  
  272. public void keyTyped( KeyEvent k ){
  273. }
  274.  
  275.  
  276. /**
  277.  * Give bonus ship for getting a certain score.
  278.  */
  279. public void didAchieveBonus() {
  280.     numShips++;
  281. } /*didAchieveBonus*/
  282.  
  283.  
  284. /**
  285.  * Player must have died, decrement ship count.
  286.  */
  287. public void decrementShipCount() {
  288.     if (numShips-- > 0) {
  289.           createNewPlayer= true;
  290.         removePlayer();
  291.     } /*endif*/
  292. } /*decrementShipCount*/
  293.  
  294.  
  295. /**
  296.  * Static main to begin the application.
  297.  */
  298. public static void main( String[] args ) {
  299.     Boinkaroids boinkaroids = new Boinkaroids();
  300.     Frame f = new Frame( "Boinkaroids" );
  301.     f.setSize( 500, 500 );
  302.     f.add( "Center",boinkaroids );
  303.     f.addWindowListener( new WindowDestroyer( f, boinkaroids ) );
  304.     f.setResizable( false );
  305.     f.show();  
  306.     boinkaroids.init(500,500);
  307. }
  308.  
  309. } /*Boinkaroids*/
  310. @
  311.  
  312.  
  313. 1.10
  314. log
  315. @*** empty log message ***
  316. @
  317. text
  318. @d51 2
  319. a52 4
  320. public void init() {
  321.     super.init( 500, 400, "./" );
  322.     Frame f = new Frame( "Boinkaroids" );
  323.     f.setSize( 500, 500 );
  324. d55 1
  325. a55 1
  326.     f.add("South",myLabel);
  327. a56 3
  328.     f.add( "Center",this );
  329.     f.addWindowListener( new WindowDestroyer( f, this ) );
  330.     f.setResizable( false );
  331. a67 1
  332.     f.show();  
  333. d74 1
  334. a74 1
  335.     myLabel.addKeyListener( this );
  336. d147 1
  337. a147 1
  338.     myLabel.addKeyListener(player);
  339. d159 1
  340. a159 1
  341.         myLabel.removeKeyListener( player );
  342. d228 7
  343. a234 1
  344.     boinkaroids.init();
  345. @
  346.  
  347.  
  348. 1.9
  349. log
  350. @*** empty log message ***
  351. @
  352. text
  353. @d28 1
  354. a28 1
  355.     public int        badGuyCount;
  356. d124 1
  357. a124 1
  358.         badGuyCount++; 
  359. d128 1
  360. a128 1
  361.         badGuyCount++; 
  362. d177 2
  363. a178 1
  364.               + "   Level: "+ level ); if (badGuyCount <= 0)
  365. d181 1
  366. a181 1
  367.  
  368. @
  369.  
  370.  
  371. 1.8
  372. log
  373. @*** empty log message ***
  374. @
  375. text
  376. @d133 6
  377. d141 7
  378. @
  379.  
  380.  
  381. 1.7
  382. log
  383. @*** empty log message ***
  384. @
  385. text
  386. @d39 1
  387. a39 1
  388.     public Label        myLabel;
  389. d140 1
  390. d152 1
  391. a152 1
  392.         removeKeyListener( player );
  393. @
  394.  
  395.  
  396. 1.6
  397. log
  398. @*** empty log message ***
  399. @
  400. text
  401. @d39 1
  402. a39 1
  403.     private Label        myLabel;
  404. d55 4
  405. d68 1
  406. a68 3
  407.     myLabel= new Label("Score: 00000000" + "   Ships: " + numShips
  408.               + "   Level: "+ level);
  409.     f.add("South",myLabel);
  410. d80 2
  411. a81 1
  412.     addKeyListener( this );
  413. @
  414.  
  415.  
  416. 1.5
  417. log
  418. @*** empty log message ***
  419. @
  420. text
  421. @d66 2
  422. a67 4
  423.     f.add("South",myLabel);
  424.   
  425.     //
  426.     // show the main window
  427. d69 9
  428. a77 7
  429.     f.show();  
  430.  
  431.     //
  432.     // cache images
  433.     //
  434.     new ImageManager(this);
  435.   
  436. d118 2
  437. a119 2
  438.     for (int i= 0; i< 2*level; i++) {
  439.         actorManager.addActor (new Asteroid(this, null, "gumball", 
  440. a128 1
  441.  
  442. d130 1
  443. d137 1
  444. a137 1
  445.     actorManager.addActor (player);
  446. a139 1
  447.  
  448. d141 1
  449. d147 1
  450. a147 1
  451.         actorManager.removeActor(player);
  452. d150 1
  453. a150 1
  454.     } /*endif*/
  455. d159 1
  456. a159 1
  457.     myLabel.setText("Score: " + scoreManager.score + "   Ships: " + numShips
  458. d161 2
  459. a162 2
  460.     if (badGuyCount <= 0)
  461.         this.newLevel();
  462. d209 4
  463. a212 4
  464.  
  465.  
  466. /**
  467.  * Static main to begin the application.
  468. d219 1
  469. a219 1
  470. } /*Boinkaroids*/
  471. @
  472.  
  473.  
  474. 1.4
  475. log
  476. @*** empty log message ***
  477. @
  478. text
  479. @d23 7
  480. a29 7
  481.   //
  482.   // Boinkaroids variables
  483.   //
  484.   public Ship        player = null;
  485.   public int        numShips;
  486.   public int        badGuyCount;
  487.   public int        level;
  488. d31 4
  489. a34 4
  490.   //
  491.   // Should a player be created?
  492.   //
  493.   public boolean    createNewPlayer = true;
  494. d36 4
  495. a39 4
  496.   //
  497.   // Score label.
  498.   //
  499.   private Label        myLabel;
  500. d41 5
  501. a45 5
  502.   //
  503.   // This area that has to be clear for a ship to enter level.
  504.   //
  505.   private int        SAFETY_ZONE_WIDTH= 128;
  506.   private int        SAFETY_ZONE_HEIGHT= 128;
  507. d52 6
  508. a57 7
  509.   super.init( 500, 400, "./" );
  510.   Frame f = new Frame( "Boinkaroids" );
  511.   f.setSize( 500, 500 );
  512.   f.add( this );
  513.   f.addWindowListener( new WindowDestroyer( f, this ) );
  514.   f.setResizable( false );
  515.   f.show();
  516. d59 25
  517. a83 19
  518.   
  519.   
  520.   //
  521.   // cache images
  522.   //
  523.   new ImageManager(this);  
  524.   
  525.   //
  526.   // initialize the score manager
  527.   //
  528.   scoreManager= new ScoreManager();
  529.   scoreManager.registerForBonusNotification(this, 20000);
  530.   
  531.   
  532.   myLabel= new Label("Score: 00000000" + "   Ships: " + numShips
  533.                       + "   Level: "+ level);
  534.   add("South",myLabel);
  535.   
  536.   this.newGame();
  537. d85 2
  538. a86 16
  539.  //
  540.   // register for events
  541.   //
  542.   //eventManager.
  543.   //  registerForSingleEventNotification(this,Event.KEY_ACTION_RELEASE);
  544.   
  545.   //
  546.   // paint background image
  547.   //
  548.   displayManager.setBackgroundTile (getImage(getCodeBase(), "images/background.gif"));
  549.  
  550.   //f.addKeyListener( this );
  551.  
  552.   start();
  553.   run();
  554.  
  555. a89 1
  556.  
  557. d94 7
  558. a100 7
  559.   scoreManager.setScore (0);
  560.   numShips= 3;
  561.   badGuyCount= 0;
  562.   level= 0;
  563.   removePlayer();
  564.   actorManager.removeAllActors();
  565.   createNewPlayer = true;
  566. a103 1
  567.  
  568. d108 3
  569. a110 5
  570.   level++;
  571.   actorManager.removeAllActors();
  572.   removePlayer();
  573.   this.createActors();
  574.   createNewPlayer = true;
  575. d118 10
  576. a127 8
  577.   for (int i= 0; i< 2*level; i++) {
  578.      actorManager.addActor (new Asteroid(this, null, "gumball", Asteroid.LARGE_SIZE));
  579.      badGuyCount++; 
  580.   } /*nexti*/ 
  581.   for (int i= 0; i< 0.5*level; i++) {
  582.     actorManager.addActor (new Bigoobie(this));
  583.     badGuyCount++; 
  584.   } /*next_i*/
  585. d129 1
  586. a130 2
  587.  
  588.  
  589. d135 4
  590. a138 3
  591.   removePlayer();
  592.   player = new Ship(this);
  593.   actorManager.addActor (player);
  594. d140 1
  595. d146 6
  596. a151 7
  597.   if (player!=null) {
  598.     actorManager.removeActor(player);
  599.     removeKeyListener( player );
  600.     player = null;
  601.     createNewPlayer = false;
  602.   } /*endif*/
  603. } /*removePlayer*/
  604. a153 1
  605.  
  606. d158 5
  607. a162 1
  608.   super.tick();
  609. d164 10
  610. a173 16
  611.   myLabel.setText("Score: " + scoreManager.score + "   Ships: " + numShips
  612.                       + "   Level: "+ level );
  613.  
  614.  if (badGuyCount <= 0) {
  615.    this.newLevel();
  616.  } /*endif*/
  617.  if (createNewPlayer) {
  618.    Rectangle myRectangle= new Rectangle((int)this.getSize().width/2 - SAFETY_ZONE_WIDTH/2,
  619.                                         (int)this.getSize().height/2 - SAFETY_ZONE_HEIGHT/2,
  620.                                         SAFETY_ZONE_WIDTH,
  621.                                         SAFETY_ZONE_HEIGHT);
  622.    if (!actorManager.isActorIn(myRectangle)) {
  623.     createNewPlayer = false;
  624.     this.createPlayer();
  625.    } /*endif*/
  626.  } /*endif*/
  627. a176 1
  628.  
  629. a192 9
  630.  * Override paint to display score bar.
  631.  */
  632. public void paint(Graphics g) {
  633.   super.paint(g);
  634. } /*paint*/
  635.  
  636.  
  637.  
  638. /**
  639. d196 1
  640. a196 1
  641.   numShips++;
  642. a199 1
  643.  
  644. d204 4
  645. a207 4
  646.   if (numShips-- > 0) {
  647.       removePlayer();
  648.         createNewPlayer= true;
  649.   } /*endif*/
  650. d209 5
  651. a213 1
  652.  
  653. d219 1
  654. a219 9
  655. /**
  656.  * Pass the event along to the EventManager for handling.
  657.  */
  658. //public void processEvent (AWTEvent theEvent) {
  659. //  System.out.println( "Boinkaroids processEvent called." );
  660. //  super.processEvent( theEvent );
  661. //} /*processEvent*/
  662.  
  663. } /*Boinkaroids*/
  664. @
  665.  
  666.  
  667. 1.3
  668. log
  669. @*** empty log message ***
  670. @
  671. text
  672. @d74 3
  673. a76 3
  674.   //myLabel= new Label("Score: 00000000" + "   Ships: " + numShips
  675.   //                    + "   Level: "+ level);
  676.   //f.add("South",myLabel);
  677. a108 1
  678.   //System.gc()
  679. d110 1
  680. a110 2
  681.   this.createActors();
  682.   createNewPlayer = false;
  683. d121 1
  684. d123 1
  685. a138 1
  686.   this.createPlayer();
  687. a146 1
  688.   System.out.println( "Creating a player." );
  689. a156 1
  690.     System.out.println( "Removing current player." );
  691. d160 1
  692. d162 1
  693. a162 1
  694. } /*createPlayer*/
  695. d170 1
  696. a170 1
  697. super.tick();
  698. d172 3
  699. a211 2
  700.   //myLabel.setText("Score: " + scoreManager.score + "   Ships: " + numShips
  701.   //                    + "   Level: "+ level );
  702. d230 1
  703. a231 1
  704.     removePlayer();
  705. @
  706.  
  707.  
  708. 1.2
  709. log
  710. @Blah.
  711. @
  712. text
  713. @d26 1
  714. a26 1
  715.   public Ship        player;
  716. d91 1
  717. a91 1
  718.   f.addKeyListener( this );
  719. d108 2
  720. a109 1
  721.   player= null;
  722. d122 1
  723. d148 10
  724. d159 1
  725. d161 2
  726. a163 2
  727.   player= new Ship(this);
  728.   actorManager.addActor (player);
  729. d183 2
  730. a184 2
  731.      createNewPlayer= false;
  732.      this.createPlayer();
  733. d231 2
  734. a232 2
  735.     createNewPlayer= true;
  736.     player= null;
  737. @
  738.  
  739.  
  740. 1.1
  741. log
  742. @Initial revision
  743. @
  744. text
  745. @d16 1
  746. a16 1
  747. //import java.net.*;
  748. d21 1
  749. a21 1
  750. public class Boinkaroids extends Gamelication implements BonusHandler, EventHandler{
  751. d34 1
  752. a34 1
  753.   private boolean    createNewPlayer;
  754. a56 1
  755.   f.addKeyListener( new KeyboardInput( this ));
  756. d83 2
  757. a84 2
  758.   eventManager.
  759.     registerForSingleEventNotification(this,Event.KEY_ACTION_RELEASE);
  760. d91 2
  761. d111 1
  762. d179 1
  763. a179 1
  764.  * Handle keyboard events to restart game.
  765. d181 4
  766. a184 11
  767. public boolean handleRequestedEvent (Event theEvent) {
  768.   switch(theEvent.id) {
  769.   case Event.KEY_ACTION_RELEASE:
  770.     switch(theEvent.key) {
  771.       case Event.F1:
  772.        this.newGame();
  773.         return true;
  774.     } /*endSwitch*/
  775.   } /*endSwitch*/
  776.   return false;
  777. } /*handleRequestedEvent8/
  778. d186 2
  779. d189 2
  780. d192 1
  781. d231 4
  782. a234 4
  783. public void processEvent (AWTEvent theEvent) {
  784.   System.out.println( "Boinkaroids processEvent called." );
  785.   super.processEvent( theEvent );
  786. } /*processEvent*/
  787. @
  788.