home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 12,000 to 12,999 / 12000.zip / AOLDLs / Online-Tools / Java-Applets / JAVAAPPS.lzh / JAVAAPPS / CENTIPED / CENTIPED.EXE / centipedo.java < prev    next >
Encoding:
Java Source  |  1996-05-13  |  36.9 KB  |  1,709 lines

  1. /* Centipedo.java - based on the arcade game Centipede. */
  2.  
  3.  
  4.  
  5. /* 
  6.  
  7.  * Copyright (C) 1996 Mark Boyns <boyns@sdsu.edu>
  8.  
  9.  *
  10.  
  11.  * Centipedo <URL:http://www.sdsu.edu/~boyns/java/centipedo/>
  12.  
  13.  *
  14.  
  15.  * This program is free software; you can redistribute it and/or modify
  16.  
  17.  * it under the terms of the GNU General Public License as published by
  18.  
  19.  * the Free Software Foundation; either version 2 of the License, or
  20.  
  21.  * (at your option) any later version.
  22.  
  23.  *
  24.  
  25.  * This program is distributed in the hope that it will be useful,
  26.  
  27.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.  
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  
  31.  * GNU General Public License for more details.
  32.  
  33.  *
  34.  
  35.  * You should have received a copy of the GNU General Public License
  36.  
  37.  * along with this program; if not, write to the Free Software
  38.  
  39.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40.  
  41.  */
  42.  
  43.  
  44.  
  45. /**
  46.  
  47.  * Centipedo is a fast-paced action game based on the arcade game
  48.  
  49.  * Centipede.
  50.  
  51.  *
  52.  
  53.  * @version 1.0 26 Mar 1996
  54.  
  55.  * @author Mark Boyns
  56.  
  57.  */
  58.  
  59.  
  60.  
  61. import java.applet.Applet;
  62.  
  63. import java.applet.AudioClip;
  64.  
  65. import java.awt.Color;
  66.  
  67. import java.awt.Graphics;
  68.  
  69. import java.awt.Point;
  70.  
  71. import java.awt.Font;
  72.  
  73. import java.awt.FontMetrics;
  74.  
  75. import java.awt.Image;
  76.  
  77. import java.awt.MediaTracker;
  78.  
  79. import java.awt.Event;
  80.  
  81. import java.awt.Polygon;
  82.  
  83.  
  84.  
  85. /**
  86.  
  87.  * Mushroom - extend Point to keep track of damage.
  88.  
  89.  */
  90.  
  91. class Mushroom extends Point
  92.  
  93. {
  94.  
  95.     int damage = 0;
  96.  
  97.  
  98.  
  99.     Mushroom (int x, int y)
  100.  
  101.     {
  102.  
  103.     super (x, y);
  104.  
  105.     }
  106.  
  107. }
  108.  
  109.  
  110.  
  111. /**
  112.  
  113.  * Centipede - extend Point to keep track of vertical and horizontal
  114.  
  115.  * direction.
  116.  
  117.  */
  118.  
  119. class Centipede extends Point
  120.  
  121. {
  122.  
  123.     int hort_dir = 0;
  124.  
  125.     int vert_dir = 0;
  126.  
  127.     
  128.  
  129.     Centipede (int x, int y, int hort_dir, int vert_dir)
  130.  
  131.     {
  132.  
  133.     super (x, y);
  134.  
  135.     this.hort_dir = hort_dir;
  136.  
  137.     this.vert_dir = vert_dir;
  138.  
  139.     }
  140.  
  141. }
  142.  
  143.  
  144.  
  145. /**
  146.  
  147.  * Scorpion - extend Point to keep track of horizontal direction.
  148.  
  149.  */
  150.  
  151. class Scorpion extends Point
  152.  
  153. {
  154.  
  155.     int hort_dir = 0;
  156.  
  157.  
  158.  
  159.     Scorpion (int x, int y, int hort_dir)
  160.  
  161.     {
  162.  
  163.     super (x, y);
  164.  
  165.     this.hort_dir = hort_dir;
  166.  
  167.     }
  168.  
  169. }
  170.  
  171.  
  172.  
  173. /**
  174.  
  175.  * Beetle - extend Point to keep track of horizontal direction.
  176.  
  177.  */
  178.  
  179. class Beetle extends Point
  180.  
  181. {
  182.  
  183.     int hort_dir = 0;
  184.  
  185.  
  186.  
  187.     Beetle (int x, int y, int hort_dir)
  188.  
  189.     {
  190.  
  191.     super (x, y);
  192.  
  193.     this.hort_dir = hort_dir;
  194.  
  195.     }
  196.  
  197. }
  198.  
  199.  
  200.  
  201. /**
  202.  
  203.  * Spider - extend Point to keep track of vertical and horizontal
  204.  
  205.  * direction and starting direction.
  206.  
  207.  */
  208.  
  209. class Spider extends Point
  210.  
  211. {
  212.  
  213.     int hort_dir = 0;
  214.  
  215.     int vert_dir = 0;
  216.  
  217.     int start_dir = 0;
  218.  
  219.     
  220.  
  221.     Spider (int x, int y, int hort_dir, int vert_dir)
  222.  
  223.     {
  224.  
  225.     super (x, y);
  226.  
  227.     this.hort_dir = hort_dir;
  228.  
  229.     this.vert_dir = vert_dir;
  230.  
  231.     }
  232.  
  233. }
  234.  
  235.  
  236.  
  237. /**
  238.  
  239.  * Centipdo - everything else
  240.  
  241.  */
  242.  
  243. public class centipedo extends java.applet.Applet implements Runnable
  244.  
  245. {
  246.  
  247.     /**
  248.  
  249.      * Screen sizes.
  250.  
  251.      */
  252.  
  253.     final int screen_width = 600;
  254.  
  255.     final int field_height = 416;
  256.  
  257.     final int stats_height = 32;
  258.  
  259.  
  260.  
  261.     /**
  262.  
  263.      * Points
  264.  
  265.      */
  266.  
  267.     final int mushroom_points = 5;
  268.  
  269.     final int centipede_points = 10;
  270.  
  271.     final int beetle_points = 20;
  272.  
  273.     final int flea_points = 50;
  274.  
  275.     final int spider_points = 75;
  276.  
  277.     final int scorpion_points = 500;
  278.  
  279.     final int extra_life_points = 4000;
  280.  
  281.  
  282.  
  283.     /**
  284.  
  285.      * MediaTracker IDs used for image loading.
  286.  
  287.      */
  288.  
  289.     final int tracker_player_id = 0;
  290.  
  291.     final int tracker_shot_id = 1;
  292.  
  293.     final int tracker_mushroom_id = 2;
  294.  
  295.     final int tracker_centipede_id = 3;
  296.  
  297.     final int tracker_beetle_id = 4;
  298.  
  299.     final int tracker_scorpion_id = 5;
  300.  
  301.     final int tracker_spider_id = 6;
  302.  
  303.     final int tracker_flea_id = 6;
  304.  
  305.  
  306.  
  307.     /**
  308.  
  309.      * Colors
  310.  
  311.      */
  312.  
  313.     final Color missing_image_color = Color.black;
  314.  
  315.     final Color background_colors[] = 
  316.  
  317.     {
  318.  
  319.     Color.white,
  320.  
  321.     Color.cyan,
  322.  
  323.     Color.yellow,
  324.  
  325.     Color.orange,
  326.  
  327.     Color.green,
  328.  
  329.     Color.pink,
  330.  
  331.     };
  332.  
  333.     
  334.  
  335.     /**
  336.  
  337.      * Fonts
  338.  
  339.      */
  340.  
  341.     Font big_font;
  342.  
  343.     FontMetrics big_font_metrics;
  344.  
  345.  
  346.  
  347.     /**
  348.  
  349.      * MediaTracker and Images
  350.  
  351.      */
  352.  
  353.     MediaTracker tracker;
  354.  
  355.     Image player_image;
  356.  
  357.     Image dead_player_image;
  358.  
  359.     Image shot_image;
  360.  
  361.     Image mushroom_image;
  362.  
  363.     Image centipede_images[];
  364.  
  365.     Image beetle_images[];
  366.  
  367.     Image scorpion_images[];
  368.  
  369.     Image spider_image;
  370.  
  371.     Image flea_image;
  372.  
  373.  
  374.  
  375.     /**
  376.  
  377.      * Sounds
  378.  
  379.      */
  380.  
  381.     AudioClip fire_shot_sound = null;
  382.  
  383.     AudioClip destroy_mushroom_sound = null;
  384.  
  385.     AudioClip destroy_centipede_sound = null;
  386.  
  387.     AudioClip destroy_beetle_sound = null;
  388.  
  389.     AudioClip destroy_scorpion_sound = null;
  390.  
  391.     AudioClip destroy_spider_sound = null;
  392.  
  393.     AudioClip destroy_flea_sound = null;
  394.  
  395.     AudioClip destroy_player_sound = null;
  396.  
  397.     AudioClip new_level_sound = null;
  398.  
  399.     AudioClip extra_life_sound = null;
  400.  
  401.  
  402.  
  403.     /**
  404.  
  405.      * Status flags
  406.  
  407.      */
  408.  
  409.     boolean game_over = true;
  410.  
  411.     boolean clear_screen = false;
  412.  
  413.     boolean mouse_down = false;
  414.  
  415.     boolean need_reset = false;
  416.  
  417.     boolean update_mushrooms = true;
  418.  
  419.     boolean update_level = true;
  420.  
  421.     boolean update_score = true;
  422.  
  423.     boolean update_lives = true;
  424.  
  425.     boolean update_player = true;
  426.  
  427.     boolean expand_mushrooms = false;
  428.  
  429.     boolean paused = false;
  430.  
  431.  
  432.  
  433.     /**
  434.  
  435.      * The mouse
  436.  
  437.      */
  438.  
  439.     Point mouse;
  440.  
  441.     Point mouse_loc;
  442.  
  443.  
  444.  
  445.     /**
  446.  
  447.      * The creatures
  448.  
  449.      */
  450.  
  451.     Beetle beetles[] = null;
  452.  
  453.     Centipede centipede[] = null;
  454.  
  455.     Point fleas[] = null;
  456.  
  457.     Scorpion scorpions[] = null;
  458.  
  459.     Spider spiders[] = null;
  460.  
  461.  
  462.  
  463.     /**
  464.  
  465.      * Mushrooms
  466.  
  467.      */
  468.  
  469.     Mushroom mushrooms[] = null;
  470.  
  471.  
  472.  
  473.     /**
  474.  
  475.      * Shots
  476.  
  477.      */
  478.  
  479.     Point shots[] = null;
  480.  
  481.  
  482.  
  483.     /**
  484.  
  485.      * The game thread.
  486.  
  487.      */
  488.  
  489.     Thread thread = null;
  490.  
  491.  
  492.  
  493.     /**
  494.  
  495.      * Misc. game parameters.
  496.  
  497.      */
  498.  
  499.     int centipede_length = 12;
  500.  
  501.     int max_shots = 5;
  502.  
  503.     int max_mushrooms = 40;
  504.  
  505.     int max_beetles = 0;
  506.  
  507.     int max_scorpions = 0;
  508.  
  509.     int max_spiders = 0;
  510.  
  511.     int max_fleas = 0;
  512.  
  513.     int max_creature_count = 100;
  514.  
  515.     int shot_speed = 40;
  516.  
  517.     int mushroom_count = 0;
  518.  
  519.     int lives = 0;
  520.  
  521.     int level = 0;
  522.  
  523.     int score = 0;
  524.  
  525.     int lscore = 0;
  526.  
  527.     
  528.  
  529.     public void init ()
  530.  
  531.     {
  532.  
  533.     int i;
  534.  
  535.  
  536.  
  537.     /* Load the font */
  538.  
  539.     big_font = new Font ("TimesRoman", Font.BOLD, 24);
  540.  
  541.     big_font_metrics = getFontMetrics (big_font);
  542.  
  543.     setFont (big_font);
  544.  
  545.  
  546.  
  547.     /* Load all the images using MediaTracker. */
  548.  
  549.     tracker = new MediaTracker (this);
  550.  
  551.     
  552.  
  553.     player_image = getImage (getCodeBase (), "images/player.gif");
  554.  
  555.     tracker.addImage (player_image, tracker_player_id);
  556.  
  557.  
  558.  
  559.     dead_player_image = getImage (getCodeBase (), "images/dead_player.gif");
  560.  
  561.     tracker.addImage (dead_player_image, tracker_player_id);
  562.  
  563.  
  564.  
  565.     shot_image = getImage (getCodeBase (), "images/shot.gif");
  566.  
  567.     tracker.addImage (shot_image, tracker_shot_id);
  568.  
  569.  
  570.  
  571.     mushroom_image = getImage (getCodeBase (), "images/mushroom.gif");
  572.  
  573.     tracker.addImage (mushroom_image, tracker_mushroom_id);
  574.  
  575.  
  576.  
  577.     beetle_images = new Image[2];
  578.  
  579.     beetle_images[0] = getImage (getCodeBase (), "images/beetle_right.gif");
  580.  
  581.     beetle_images[1] = getImage (getCodeBase (), "images/beetle_left.gif");
  582.  
  583.     tracker.addImage (beetle_images[0], tracker_beetle_id);
  584.  
  585.     tracker.addImage (beetle_images[1], tracker_beetle_id);
  586.  
  587.  
  588.  
  589.     scorpion_images = new Image[2];
  590.  
  591.     scorpion_images[0] = getImage (getCodeBase (), "images/scorpion_right.gif");
  592.  
  593.     scorpion_images[1] = getImage (getCodeBase (), "images/scorpion_left.gif");
  594.  
  595.     tracker.addImage (scorpion_images[0], tracker_scorpion_id);
  596.  
  597.     tracker.addImage (scorpion_images[1], tracker_scorpion_id);
  598.  
  599.  
  600.  
  601.     spider_image = getImage (getCodeBase (), "images/spider.gif");
  602.  
  603.     tracker.addImage (spider_image, tracker_spider_id);
  604.  
  605.     
  606.  
  607.     flea_image = getImage (getCodeBase (), "images/flea.gif");
  608.  
  609.     tracker.addImage (flea_image, tracker_flea_id);
  610.  
  611.     
  612.  
  613.     centipede_images = new Image[2];
  614.  
  615.     centipede_images[0] = getImage (getCodeBase (), "images/head.gif");
  616.  
  617.     centipede_images[1] = getImage (getCodeBase (), "images/body.gif");
  618.  
  619.     tracker.addImage (centipede_images[0], tracker_centipede_id);
  620.  
  621.     tracker.addImage (centipede_images[1], tracker_centipede_id);
  622.  
  623.  
  624.  
  625.     /* Load all the sounds. */
  626.  
  627.     fire_shot_sound = getAudioClip (getCodeBase (), "sounds/shot.au");
  628.  
  629.     destroy_mushroom_sound = getAudioClip (getCodeBase (), "sounds/drip.au");
  630.  
  631.     destroy_centipede_sound = getAudioClip (getCodeBase (), "sounds/Water.au");
  632.  
  633.     destroy_beetle_sound = getAudioClip (getCodeBase (), "sounds/crunch.au");
  634.  
  635.     destroy_scorpion_sound = getAudioClip (getCodeBase (), "sounds/wohoo.au");
  636.  
  637.     destroy_spider_sound = getAudioClip (getCodeBase (), "sounds/hammer.au");
  638.  
  639.     destroy_flea_sound = getAudioClip (getCodeBase (), "sounds/hehehehe.au");
  640.  
  641.     destroy_player_sound = getAudioClip (getCodeBase (), "sounds/crap1.au");
  642.  
  643.     new_level_sound = getAudioClip (getCodeBase (), "sounds/magic.au");
  644.  
  645.     extra_life_sound = getAudioClip (getCodeBase (), "sounds/bleep.au");
  646.  
  647.  
  648.  
  649.     /* Create the array of player shots.  Only needs to be done once. */
  650.  
  651.     shots = new Point[max_shots];
  652.  
  653.     for (i = 0; i < shots.length; i++)
  654.  
  655.     {
  656.  
  657.         shots[i] = new Point (0, 0);
  658.  
  659.     }
  660.  
  661.  
  662.  
  663.     /* Mouse */
  664.  
  665.     mouse_loc = new Point (screen_width/2, field_height/2);
  666.  
  667.     mouse = new Point (screen_width/2, field_height/2);
  668.  
  669.  
  670.  
  671.     setBackground (background_colors[0]);
  672.  
  673.     resize (screen_width, field_height + stats_height);
  674.  
  675.  
  676.  
  677.     /* Start the game! */
  678.  
  679.     thread = new Thread (this);
  680.  
  681.     thread.start ();
  682.  
  683.     }
  684.  
  685.  
  686.  
  687.     public void start ()
  688.  
  689.     {
  690.  
  691.     if (thread == null)
  692.  
  693.     {
  694.  
  695.         thread = new Thread (this);
  696.  
  697.         thread.start ();
  698.  
  699.     }
  700.  
  701.     }
  702.  
  703.  
  704.  
  705.     public void stop ()
  706.  
  707.     {
  708.  
  709.     if (thread != null && thread.isAlive ())
  710.  
  711.     {
  712.  
  713.         thread.stop ();
  714.  
  715.         thread = null;
  716.  
  717.     }
  718.  
  719.     }
  720.  
  721.  
  722.  
  723.     public void run ()
  724.  
  725.     {
  726.  
  727.     int i;
  728.  
  729.     int tick;
  730.  
  731.     double chance;
  732.  
  733.     boolean have_mushroom_image = false;
  734.  
  735.  
  736.  
  737.     /* Start loading the images */
  738.  
  739.     tracker.checkAll (true);
  740.  
  741.  
  742.  
  743.     /* Demo settings */
  744.  
  745.     max_beetles = 3;
  746.  
  747.     max_scorpions = 1;
  748.  
  749.     max_spiders = 1;
  750.  
  751.     max_fleas = 3;
  752.  
  753.         reset_creatures ();
  754.  
  755.     generate_centipede ();
  756.  
  757.     generate_mushrooms ();
  758.  
  759.  
  760.  
  761.     for (;;)
  762.  
  763.     {
  764.  
  765.         /* Randomly generate creatures. */
  766.  
  767.         chance = Math.random ();
  768.  
  769.         if (chance < 0.50)
  770.  
  771.         {
  772.  
  773.         generate_beetle ();
  774.  
  775.         }
  776.  
  777.         if (chance < 0.30)
  778.  
  779.         {
  780.  
  781.         generate_spider ();
  782.  
  783.         }
  784.  
  785.         if (chance < 0.05)
  786.  
  787.         {
  788.  
  789.         generate_scorpion ();
  790.  
  791.         }
  792.  
  793.  
  794.  
  795.         /* Generate fleas to generate mushrooms. */
  796.  
  797.         if (mushroom_count < max_mushrooms)
  798.  
  799.         {
  800.  
  801.         generate_flea ();
  802.  
  803.         }
  804.  
  805.  
  806.  
  807.         /* Fire player shots */
  808.  
  809.         if (mouse_down)
  810.  
  811.         {
  812.  
  813.         fire_shot (mouse_loc.x, mouse_loc.y);
  814.  
  815.         }
  816.  
  817.  
  818.  
  819.         if (!have_mushroom_image)
  820.  
  821.         {
  822.  
  823.         have_mushroom_image = tracker.checkID (tracker_mushroom_id, true);
  824.  
  825.         if (have_mushroom_image)
  826.  
  827.         {
  828.  
  829.             clear_screen = true;
  830.  
  831.             update_mushrooms = true;
  832.  
  833.             update_lives = true;
  834.  
  835.             update_score = true;
  836.  
  837.             update_level = true;
  838.  
  839.         }
  840.  
  841.         }
  842.  
  843.         
  844.  
  845.         /* Update the screen. */
  846.  
  847.         repaint ();
  848.  
  849.  
  850.  
  851.         /* Sleep for 1/10 a second. */
  852.  
  853.         try
  854.  
  855.         {
  856.  
  857.         Thread.sleep (100);
  858.  
  859.         }
  860.  
  861.         catch (Exception e)
  862.  
  863.         {
  864.  
  865.         return;
  866.  
  867.         }
  868.  
  869.     }
  870.  
  871.     }
  872.  
  873.  
  874.  
  875.     void start_game ()
  876.  
  877.     {
  878.  
  879.     lives = 3;
  880.  
  881.     level = 1;
  882.  
  883.     score = 0;
  884.  
  885.     lscore = 0;
  886.  
  887.     max_beetles = 1;
  888.  
  889.     max_scorpions = 0;
  890.  
  891.     max_spiders = 1;
  892.  
  893.     max_fleas = 1;
  894.  
  895.     game_over = false;
  896.  
  897.     clear_screen = true;
  898.  
  899.     setBackground (background_colors[(level-1) % background_colors.length]);
  900.  
  901.     update_lives = true;
  902.  
  903.     update_score = true;
  904.  
  905.     update_level = true;
  906.  
  907.     reset_creatures ();
  908.  
  909.     generate_mushrooms ();
  910.  
  911.     generate_centipede ();
  912.  
  913.     }
  914.  
  915.  
  916.  
  917.     void reset_creatures ()
  918.  
  919.     {
  920.  
  921.     int i;
  922.  
  923.  
  924.  
  925.     beetles = new Beetle[Math.min (max_beetles, max_creature_count)];
  926.  
  927.     for (i = 0; i < beetles.length; i++)
  928.  
  929.     {
  930.  
  931.         beetles[i] = new Beetle (0, 0, 0);
  932.  
  933.     }
  934.  
  935.  
  936.  
  937.     scorpions = new Scorpion[Math.min (max_scorpions, max_creature_count)];
  938.  
  939.     for (i = 0; i < scorpions.length; i++)
  940.  
  941.     {
  942.  
  943.         scorpions[i] = new Scorpion (0, 0, 0);
  944.  
  945.     }
  946.  
  947.  
  948.  
  949.     spiders = new Spider[Math.min (max_spiders, max_creature_count)];
  950.  
  951.     for (i = 0; i < spiders.length; i++)
  952.  
  953.     {
  954.  
  955.         spiders[i] = new Spider (0, 0, 0, 0);
  956.  
  957.     }
  958.  
  959.  
  960.  
  961.     fleas = new Point[Math.min (max_fleas, max_creature_count)];
  962.  
  963.     for (i = 0; i < fleas.length; i++)
  964.  
  965.     {
  966.  
  967.         fleas[i] = new Point (0, 0);
  968.  
  969.     }
  970.  
  971.     }
  972.  
  973.     
  974.  
  975.     void reset_game ()
  976.  
  977.     {
  978.  
  979.     int i;
  980.  
  981.  
  982.  
  983.     for (i = 0; i < shots.length; i++)
  984.  
  985.     {
  986.  
  987.         shots[i].x = 0;
  988.  
  989.         shots[i].y = 0;
  990.  
  991.     }
  992.  
  993.  
  994.  
  995.     if (centipede != null)
  996.  
  997.     {
  998.  
  999.         generate_centipede ();
  1000.  
  1001.     }
  1002.  
  1003.  
  1004.  
  1005.     clear_screen = true;
  1006.  
  1007.     update_mushrooms = true;
  1008.  
  1009.     update_lives = true;
  1010.  
  1011.     update_score = true;
  1012.  
  1013.     update_level = true;
  1014.  
  1015.     reset_creatures ();
  1016.  
  1017.     }
  1018.  
  1019.  
  1020.  
  1021.     void new_level ()
  1022.  
  1023.     {
  1024.  
  1025.     if (new_level_sound != null)
  1026.  
  1027.     {
  1028.  
  1029.         new_level_sound.play ();
  1030.  
  1031.     }
  1032.  
  1033.     
  1034.  
  1035.     level++;
  1036.  
  1037.  
  1038.  
  1039.     setBackground (background_colors[(level-1) % background_colors.length]);
  1040.  
  1041.     clear_screen = true;
  1042.  
  1043.     update_mushrooms = true;
  1044.  
  1045.     update_lives = true;
  1046.  
  1047.     update_score = true;
  1048.  
  1049.     update_level = true;
  1050.  
  1051.     update_player = true;
  1052.  
  1053.  
  1054.  
  1055.     generate_centipede ();
  1056.  
  1057.  
  1058.  
  1059.     if ((level % 3) == 0)
  1060.  
  1061.     {
  1062.  
  1063.         if (max_scorpions == 0)
  1064.  
  1065.         {
  1066.  
  1067.         max_scorpions = Math.min (max_scorpions + 1, max_creature_count);
  1068.  
  1069.         }
  1070.  
  1071.         max_beetles = Math.min (max_beetles + 1, max_creature_count);
  1072.  
  1073.         max_fleas = Math.min (max_fleas + 1, max_creature_count);
  1074.  
  1075.     }
  1076.  
  1077.     if ((level % 5) == 0)
  1078.  
  1079.     {
  1080.  
  1081.         max_spiders = Math.min (max_spiders + 1, max_creature_count);
  1082.  
  1083.         max_scorpions = Math.min (max_scorpions + 1, max_creature_count);
  1084.  
  1085.     }
  1086.  
  1087.  
  1088.  
  1089.     reset_creatures ();
  1090.  
  1091.     }
  1092.  
  1093.  
  1094.  
  1095.     void suspend_game ()
  1096.  
  1097.     {
  1098.  
  1099.     if (thread != null && !game_over)
  1100.  
  1101.     {
  1102.  
  1103.         thread.suspend ();
  1104.  
  1105.         paused = true;
  1106.  
  1107.         clear_screen = true;
  1108.  
  1109.         repaint ();
  1110.  
  1111.     }
  1112.  
  1113.     }
  1114.  
  1115.  
  1116.  
  1117.     void resume_game ()
  1118.  
  1119.     {
  1120.  
  1121.     if (thread != null && !game_over)
  1122.  
  1123.     {
  1124.  
  1125.         thread.resume ();
  1126.  
  1127.         paused = false;
  1128.  
  1129.         clear_screen = true;
  1130.  
  1131.         update_mushrooms = true;
  1132.  
  1133.         update_lives = true;
  1134.  
  1135.         update_score = true;
  1136.  
  1137.         update_level = true;
  1138.  
  1139.         update_player = true;
  1140.  
  1141.     }
  1142.  
  1143.     }
  1144.  
  1145.     
  1146.  
  1147.     /* Handle mouse up events. */
  1148.  
  1149.     public boolean mouseUp (Event e, int x, int y)
  1150.  
  1151.     {
  1152.  
  1153.     if (game_over)
  1154.  
  1155.     {
  1156.  
  1157.          start_game ();
  1158.  
  1159.     }
  1160.  
  1161.     mouse_down = false;
  1162.  
  1163.     return true;
  1164.  
  1165.     }
  1166.  
  1167.     
  1168.  
  1169.     /* Handle mouse down events. */
  1170.  
  1171.     public boolean mouseDown (Event e, int x, int y)
  1172.  
  1173.     {
  1174.  
  1175.     mouse_down = true;
  1176.  
  1177.     return true;
  1178.  
  1179.     }
  1180.  
  1181.  
  1182.  
  1183.     void move_mouse (int x, int y)
  1184.  
  1185.     {
  1186.  
  1187.     int min_y = field_height - field_height/3;
  1188.  
  1189.     if (y < min_y)
  1190.  
  1191.     {
  1192.  
  1193.         y = min_y;
  1194.  
  1195.     }
  1196.  
  1197.     else if (y > field_height - 16)
  1198.  
  1199.     {
  1200.  
  1201.         y = field_height - 16;
  1202.  
  1203.     }
  1204.  
  1205.     mouse_loc.move (x, y);
  1206.  
  1207.     }
  1208.  
  1209.     
  1210.  
  1211.     /* Handle mouse move events. */
  1212.  
  1213.     public boolean mouseMove (Event e, int x, int y)
  1214.  
  1215.     {
  1216.  
  1217.     move_mouse (x, y);
  1218.  
  1219.     return true;
  1220.  
  1221.     }
  1222.  
  1223.  
  1224.  
  1225.     /* Handle mouse drag events. */
  1226.  
  1227.     public boolean mouseDrag (Event e, int x, int y)
  1228.  
  1229.     {
  1230.  
  1231.     move_mouse (x, y);
  1232.  
  1233.     return true;
  1234.  
  1235.     }
  1236.  
  1237.     
  1238.  
  1239.     /* Handle keyboard events. */
  1240.  
  1241.     public boolean keyDown (Event e, int key)
  1242.  
  1243.     {
  1244.  
  1245.     switch (key)
  1246.  
  1247.     {
  1248.  
  1249.     case 'g':
  1250.  
  1251.     case 'G':
  1252.  
  1253.         if (!paused)
  1254.  
  1255.         {
  1256.  
  1257.         start_game ();
  1258.  
  1259.         }
  1260.  
  1261.         break;
  1262.  
  1263.  
  1264.  
  1265.     case 'p':
  1266.  
  1267.     case 'P':
  1268.  
  1269.         if (paused)
  1270.  
  1271.         {
  1272.  
  1273.         resume_game ();
  1274.  
  1275.         }
  1276.  
  1277.         else
  1278.  
  1279.         {
  1280.  
  1281.         suspend_game ();
  1282.  
  1283.         }
  1284.  
  1285.         break;
  1286.  
  1287.         
  1288.  
  1289.     case 'x':
  1290.  
  1291.         new_level ();
  1292.  
  1293.         break;
  1294.  
  1295.     }
  1296.  
  1297.     
  1298.  
  1299.     return true;
  1300.  
  1301.     }
  1302.  
  1303.  
  1304.  
  1305.     /* Handle mouse enter events. */
  1306.  
  1307.     public boolean mouseEnter (Event e, int x, int y)
  1308.  
  1309.     {
  1310.  
  1311.     if (!game_over)
  1312.  
  1313.     {
  1314.  
  1315.         resume_game ();
  1316.  
  1317.     }
  1318.  
  1319.     return true;
  1320.  
  1321.     }
  1322.  
  1323.  
  1324.  
  1325.     /* Handle mouse exit events. */
  1326.  
  1327.     public boolean mouseExit (Event e, int x, int y)
  1328.  
  1329.     {
  1330.  
  1331.     if (!game_over)
  1332.  
  1333.     {
  1334.  
  1335.         suspend_game ();
  1336.  
  1337.     }
  1338.  
  1339.     return true;
  1340.  
  1341.     }
  1342.  
  1343.  
  1344.  
  1345.     boolean collision (Point p1, int r1, Point p2, int r2)
  1346.  
  1347.     {
  1348.  
  1349.     int dist = (int) Math.sqrt (((p2.x - p1.x) * (p2.x - p1.x)) + ((p2.y - p1.y) * (p2.y - p1.y)));
  1350.  
  1351.     int range = r1 + r2;
  1352.  
  1353.     //System.out.println ("dist = " + dist + " range = " + range);
  1354.  
  1355.     return dist <= range;
  1356.  
  1357.     }
  1358.  
  1359.  
  1360.  
  1361.     void fire_shot (int x, int y)
  1362.  
  1363.     {
  1364.  
  1365.     int i;
  1366.  
  1367.  
  1368.  
  1369.     if (game_over)
  1370.  
  1371.     {
  1372.  
  1373.         return;
  1374.  
  1375.     }
  1376.  
  1377.  
  1378.  
  1379.     for (i = 0; i < shots.length; i++)
  1380.  
  1381.     {
  1382.  
  1383.         if (shots[i].y == 0)
  1384.  
  1385.         {
  1386.  
  1387.         shots[i].x = x;
  1388.  
  1389.         shots[i].y = y;
  1390.  
  1391.         break;
  1392.  
  1393.         }
  1394.  
  1395.     }
  1396.  
  1397.  
  1398.  
  1399.     if (i < shots.length)
  1400.  
  1401.     {
  1402.  
  1403.         if (fire_shot_sound != null)
  1404.  
  1405.         {
  1406.  
  1407.         fire_shot_sound.play ();
  1408.  
  1409.         }
  1410.  
  1411.     }
  1412.  
  1413.     }
  1414.  
  1415.  
  1416.  
  1417.     void increment_score (int points)
  1418.  
  1419.     {
  1420.  
  1421.     score += points;
  1422.  
  1423.     lscore += points;
  1424.  
  1425.     if (lscore >= extra_life_points)
  1426.  
  1427.     {
  1428.  
  1429.         if (extra_life_sound != null)
  1430.  
  1431.         {
  1432.  
  1433.         extra_life_sound.play ();
  1434.  
  1435.         }
  1436.  
  1437.         lscore -= extra_life_points;
  1438.  
  1439.         lives++;
  1440.  
  1441.         update_lives = true;
  1442.  
  1443.     }
  1444.  
  1445.     update_score = true;
  1446.  
  1447.     }
  1448.  
  1449.  
  1450.  
  1451.     void destroy_mushroom (Graphics g, int i)
  1452.  
  1453.     {
  1454.  
  1455.     increment_score (mushroom_points);
  1456.  
  1457.  
  1458.  
  1459.     if (destroy_mushroom_sound != null)
  1460.  
  1461.     {
  1462.  
  1463.         destroy_mushroom_sound.play ();
  1464.  
  1465.     }
  1466.  
  1467.     
  1468.  
  1469.     mushrooms[i].damage++;
  1470.  
  1471.     if (mushrooms[i].damage < 3)
  1472.  
  1473.     {
  1474.  
  1475.         g.clearRect (mushrooms[i].x - 16, mushrooms[i].y - 16, 32, 32);
  1476.  
  1477.         paint_mushroom_collision (g, mushrooms[i], 16);
  1478.  
  1479.         return;
  1480.  
  1481.     }
  1482.  
  1483.     
  1484.  
  1485.     Point p = new Point (mushrooms[i].x, mushrooms[i].y);
  1486.  
  1487.  
  1488.  
  1489.     g.clearRect (mushrooms[i].x - 16, mushrooms[i].y - 16, 32, 32);
  1490.  
  1491.  
  1492.  
  1493.     mushrooms[i].x = 0;
  1494.  
  1495.     mushrooms[i].y = 0;
  1496.  
  1497.     mushroom_count--;
  1498.  
  1499.  
  1500.  
  1501.     paint_mushroom_collision (g, p, 16);
  1502.  
  1503.     }
  1504.  
  1505.  
  1506.  
  1507.     void destroy_centipede (Graphics g, int i)
  1508.  
  1509.     {
  1510.  
  1511.     Point p = new Point (centipede[i].x, centipede[i].y);
  1512.  
  1513.     int j;
  1514.  
  1515.  
  1516.  
  1517.     increment_score (centipede_points);
  1518.  
  1519.  
  1520.  
  1521.     if (destroy_centipede_sound != null)
  1522.  
  1523.     {
  1524.  
  1525.         destroy_centipede_sound.play ();
  1526.  
  1527.     }
  1528.  
  1529.     
  1530.  
  1531.     g.clearRect (centipede[i].x - 8, centipede[i].y - 8, 16, 16);
  1532.  
  1533.  
  1534.  
  1535.     centipede[i].x = 0;
  1536.  
  1537.     centipede[i].y = 0;
  1538.  
  1539.  
  1540.  
  1541.     j = generate_mushroom (p.x, p.y);
  1542.  
  1543.     if (j != -1)
  1544.  
  1545.     {
  1546.  
  1547.         paint_mushroom (g, j);
  1548.  
  1549.     }
  1550.  
  1551.  
  1552.  
  1553.     for (j = 0; j < centipede.length; j++)
  1554.  
  1555.     {
  1556.  
  1557.         if (centipede[j].x != 0 && centipede[j].y != 0)
  1558.  
  1559.         {
  1560.  
  1561.         break;
  1562.  
  1563.         }
  1564.  
  1565.     }
  1566.  
  1567.     if (j == centipede.length)
  1568.  
  1569.     {
  1570.  
  1571.         new_level ();
  1572.  
  1573.     }
  1574.  
  1575.     
  1576.  
  1577.     paint_mushroom_collision (g, p, 8);
  1578.  
  1579.     }
  1580.  
  1581.  
  1582.  
  1583.     void destroy_spider (Graphics g, int i)
  1584.  
  1585.     {
  1586.  
  1587.     Point p = new Point (spiders[i].x, spiders[i].y);
  1588.  
  1589.  
  1590.  
  1591.     if (destroy_spider_sound != null)
  1592.  
  1593.     {
  1594.  
  1595.         destroy_spider_sound.play ();
  1596.  
  1597.     }
  1598.  
  1599.     
  1600.  
  1601.     increment_score (spider_points);
  1602.  
  1603.     
  1604.  
  1605.     g.clearRect (spiders[i].x - 16, spiders[i].y - 16, 32, 32);
  1606.  
  1607.  
  1608.  
  1609.     spiders[i].x = 0;
  1610.  
  1611.     spiders[i].y = 0;
  1612.  
  1613.  
  1614.  
  1615.     paint_mushroom_collision (g, p, 16);
  1616.  
  1617.     }
  1618.  
  1619.  
  1620.  
  1621.     void destroy_scorpion (Graphics g, int i)
  1622.  
  1623.     {
  1624.  
  1625.     Point p = new Point (scorpions[i].x, scorpions[i].y);
  1626.  
  1627.  
  1628.  
  1629.     if (destroy_scorpion_sound != null)
  1630.  
  1631.     {
  1632.  
  1633.         destroy_scorpion_sound.play ();
  1634.  
  1635.     }
  1636.  
  1637.     
  1638.  
  1639.     increment_score (scorpion_points);
  1640.  
  1641.     
  1642.  
  1643.     g.clearRect (scorpions[i].x - 16, scorpions[i].y - 16, 32, 32);
  1644.  
  1645.  
  1646.  
  1647.     scorpions[i].x = 0;
  1648.  
  1649.     scorpions[i].y = 0;
  1650.  
  1651.  
  1652.  
  1653.     paint_mushroom_collision (g, p, 16);
  1654.  
  1655.     }
  1656.  
  1657.  
  1658.  
  1659.     void destroy_beetle (Graphics g, int i)
  1660.  
  1661.     {
  1662.  
  1663.     Point p = new Point (beetles[i].x, beetles[i].y);
  1664.  
  1665.  
  1666.  
  1667.     if (destroy_beetle_sound != null)
  1668.  
  1669.     {
  1670.  
  1671.         destroy_beetle_sound.play ();
  1672.  
  1673.     }
  1674.  
  1675.     
  1676.  
  1677.     increment_score (beetle_points);
  1678.  
  1679.     
  1680.  
  1681.     g.clearRect (beetles[i].x - 16, beetles[i].y - 16, 32, 32);
  1682.  
  1683.  
  1684.  
  1685.     beetles[i].x = 0;
  1686.  
  1687.     beetles[i].y = 0;
  1688.  
  1689.  
  1690.  
  1691.     paint_mushroom_collision (g, p, 16);
  1692.  
  1693.     }
  1694.  
  1695.  
  1696.  
  1697.     void destroy_flea (Graphics g, int i)
  1698.  
  1699.     {
  1700.  
  1701.     Point p = new Point (fleas[i].x, fleas[i].y);
  1702.  
  1703.  
  1704.  
  1705.     if (destroy_flea_sound != null)
  1706.  
  1707.     {
  1708.  
  1709.         destroy_flea_sound.play ();
  1710.  
  1711.     }
  1712.  
  1713.     
  1714.  
  1715.     increment_score (flea_points);
  1716.  
  1717.     
  1718.  
  1719.     g.clearRect (fleas[i].x - 8, fleas[i].y - 8, 16, 16);
  1720.  
  1721.  
  1722.  
  1723.     fleas[i].x = 0;
  1724.  
  1725.     fleas[i].y = 0;
  1726.  
  1727.  
  1728.  
  1729.     paint_mushroom_collision (g, p, 8);
  1730.  
  1731.     }
  1732.  
  1733.  
  1734.  
  1735.     void destroy_player ()
  1736.  
  1737.     {
  1738.  
  1739.     if (game_over)
  1740.  
  1741.     {
  1742.  
  1743.         return;
  1744.  
  1745.     }
  1746.  
  1747.     
  1748.  
  1749.     if (destroy_player_sound != null)
  1750.  
  1751.     {
  1752.  
  1753.         destroy_player_sound.play ();
  1754.  
  1755.     }
  1756.  
  1757.     
  1758.  
  1759.     if (need_reset)
  1760.  
  1761.     {
  1762.  
  1763.         return;
  1764.  
  1765.     }
  1766.  
  1767.     
  1768.  
  1769.     lives--;
  1770.  
  1771.     if (lives < 0)
  1772.  
  1773.     {
  1774.  
  1775.         lives = 0;
  1776.  
  1777.         game_over = true;
  1778.  
  1779.     }
  1780.  
  1781.     else
  1782.  
  1783.     {
  1784.  
  1785.         need_reset = true;
  1786.  
  1787.         expand_mushrooms = true;
  1788.  
  1789.     }
  1790.  
  1791.     
  1792.  
  1793.     update_lives = true;
  1794.  
  1795.     }
  1796.  
  1797.  
  1798.  
  1799.     boolean check_player_collision (Point p, int r)
  1800.  
  1801.     {
  1802.  
  1803.     boolean hit = collision (p, r, mouse_loc, 16);
  1804.  
  1805.     if (hit)
  1806.  
  1807.     {
  1808.  
  1809.         destroy_player ();
  1810.  
  1811.         update_player = true;
  1812.  
  1813.     }
  1814.  
  1815.     return hit;
  1816.  
  1817.     }
  1818.  
  1819.  
  1820.  
  1821.     int generate_mushroom (int x, int y)
  1822.  
  1823.     {
  1824.  
  1825.     int j;
  1826.  
  1827.  
  1828.  
  1829.     if (y > field_height - 16)
  1830.  
  1831.     {
  1832.  
  1833.         y = field_height - 16;
  1834.  
  1835.     }
  1836.  
  1837.     
  1838.  
  1839.     for (j = 0; j < mushrooms.length; j++)
  1840.  
  1841.     {
  1842.  
  1843.         if (mushrooms[j].x == 0 && mushrooms[j].y == 0)
  1844.  
  1845.         {
  1846.  
  1847.         mushrooms[j].x = x;
  1848.  
  1849.         mushrooms[j].y = y;
  1850.  
  1851.         mushrooms[j].damage = 0;
  1852.  
  1853.         mushroom_count++;
  1854.  
  1855.         return j;
  1856.  
  1857.         }
  1858.  
  1859.     }
  1860.  
  1861.     return -1;
  1862.  
  1863.     }
  1864.  
  1865.  
  1866.  
  1867.     void generate_mushrooms ()
  1868.  
  1869.     {
  1870.  
  1871.     int i;
  1872.  
  1873.     int size = max_mushrooms + (centipede_length * 3);
  1874.  
  1875.  
  1876.  
  1877.     mushrooms = new Mushroom[size];
  1878.  
  1879.     for (i = 0; i < max_mushrooms; i++)
  1880.  
  1881.     {
  1882.  
  1883.         mushrooms[i] = new Mushroom ((int)(Math.random () * screen_width),
  1884.  
  1885.                      (int)(Math.random () * (field_height - 16)));
  1886.  
  1887.     }
  1888.  
  1889.     mushroom_count = max_mushrooms;
  1890.  
  1891.     for (; i < size; i++)
  1892.  
  1893.     {
  1894.  
  1895.         mushrooms[i] = new Mushroom (0, 0);
  1896.  
  1897.     }
  1898.  
  1899.     
  1900.  
  1901.     update_mushrooms = true;
  1902.  
  1903.     }
  1904.  
  1905.  
  1906.  
  1907.     void generate_centipede ()
  1908.  
  1909.     {
  1910.  
  1911.     int i;
  1912.  
  1913.     int x, y, h;
  1914.  
  1915.  
  1916.  
  1917.     if (Math.random () > 0.50)
  1918.  
  1919.     {
  1920.  
  1921.         x = screen_width - 8;
  1922.  
  1923.         h = -1;
  1924.  
  1925.     }
  1926.  
  1927.     else
  1928.  
  1929.     {
  1930.  
  1931.         x = 8;
  1932.  
  1933.         h = 1;
  1934.  
  1935.     }
  1936.  
  1937.     
  1938.  
  1939.     centipede = new Centipede[centipede_length];
  1940.  
  1941.     for (i = 0; i < centipede.length; i++)
  1942.  
  1943.     {
  1944.  
  1945.         if (i == 0)
  1946.  
  1947.         {
  1948.  
  1949.         centipede[i] = new Centipede (x, 8, h, 1);
  1950.  
  1951.         }
  1952.  
  1953.         else
  1954.  
  1955.         {
  1956.  
  1957.         centipede[i] = new Centipede (centipede[i-1].x + -(h*16),
  1958.  
  1959.                           centipede[i-1].y, h, 1);
  1960.  
  1961.         }
  1962.  
  1963.     }
  1964.  
  1965.     }
  1966.  
  1967.  
  1968.  
  1969.     void generate_beetle ()
  1970.  
  1971.     {
  1972.  
  1973.     int i;
  1974.  
  1975.  
  1976.  
  1977.     for (i = 0; i < max_beetles; i++)
  1978.  
  1979.     {
  1980.  
  1981.         if (beetles[i].x == 0 && beetles[i].y == 0)
  1982.  
  1983.         {
  1984.  
  1985.         if (Math.random () > 0.50)
  1986.  
  1987.         {
  1988.  
  1989.             beetles[i].hort_dir = 1;
  1990.  
  1991.             beetles[i].x = 8;
  1992.  
  1993.         }
  1994.  
  1995.         else
  1996.  
  1997.         {
  1998.  
  1999.             beetles[i].hort_dir = -1;
  2000.  
  2001.             beetles[i].x = screen_width - 8;
  2002.  
  2003.         }
  2004.  
  2005.         beetles[i].y = field_height/2 + (int)(Math.random () * (field_height/2 - 16));
  2006.  
  2007.         break;
  2008.  
  2009.         }
  2010.  
  2011.     }
  2012.  
  2013.     }
  2014.  
  2015.  
  2016.  
  2017.     void generate_scorpion ()
  2018.  
  2019.     {
  2020.  
  2021.     int i;
  2022.  
  2023.  
  2024.  
  2025.     for (i = 0; i < max_scorpions; i++)
  2026.  
  2027.     {
  2028.  
  2029.         if (scorpions[i].x == 0 && scorpions[i].y == 0)
  2030.  
  2031.         {
  2032.  
  2033.         if (Math.random () > 0.50)
  2034.  
  2035.         {
  2036.  
  2037.             scorpions[i].hort_dir = 1;
  2038.  
  2039.             scorpions[i].x = 16;
  2040.  
  2041.         }
  2042.  
  2043.         else
  2044.  
  2045.         {
  2046.  
  2047.             scorpions[i].hort_dir = -1;
  2048.  
  2049.             scorpions[i].x = screen_width - 16;
  2050.  
  2051.         }
  2052.  
  2053.         scorpions[i].y = 100;
  2054.  
  2055.         break;
  2056.  
  2057.         }
  2058.  
  2059.     }
  2060.  
  2061.     }
  2062.  
  2063.  
  2064.  
  2065.     void generate_spider ()
  2066.  
  2067.     {
  2068.  
  2069.     int i;
  2070.  
  2071.  
  2072.  
  2073.     for (i = 0; i < max_spiders; i++)
  2074.  
  2075.     {
  2076.  
  2077.         if (spiders[i].x == 0 && spiders[i].y == 0)
  2078.  
  2079.         {
  2080.  
  2081.         if (Math.random () > 0.50)
  2082.  
  2083.         {
  2084.  
  2085.             spiders[i].x = 8;
  2086.  
  2087.             spiders[i].hort_dir = 1;
  2088.  
  2089.         }
  2090.  
  2091.         else
  2092.  
  2093.         {
  2094.  
  2095.             spiders[i].x = screen_width - 8;
  2096.  
  2097.             spiders[i].hort_dir = -1;
  2098.  
  2099.         }
  2100.  
  2101.         spiders[i].y = field_height/2 + (int)(Math.random () * (field_height/2)) - 16;
  2102.  
  2103.         spiders[i].vert_dir = 1;
  2104.  
  2105.         spiders[i].start_dir = spiders[i].hort_dir;
  2106.  
  2107.         break;
  2108.  
  2109.         }
  2110.  
  2111.     }
  2112.  
  2113.     }
  2114.  
  2115.  
  2116.  
  2117.     void generate_flea ()
  2118.  
  2119.     {
  2120.  
  2121.     int i;
  2122.  
  2123.  
  2124.  
  2125.     for (i = 0; i < max_fleas; i++)
  2126.  
  2127.     {
  2128.  
  2129.         if (fleas[i].x == 0 && fleas[i].y == 0)
  2130.  
  2131.         {
  2132.  
  2133.         fleas[i].x = (int)(Math.random () * screen_width);
  2134.  
  2135.         fleas[i].y = 8;
  2136.  
  2137.         break;
  2138.  
  2139.         }
  2140.  
  2141.     }
  2142.  
  2143.     }
  2144.  
  2145.     
  2146.  
  2147.     /* Don't clear the screen; just call paint. */
  2148.  
  2149.     public void update (Graphics g)
  2150.  
  2151.     {
  2152.  
  2153.     paint (g);
  2154.  
  2155.     }
  2156.  
  2157.  
  2158.  
  2159.     void paint_mushroom (Graphics g, int i)
  2160.  
  2161.     {
  2162.  
  2163.     boolean have_image = tracker.checkID (tracker_mushroom_id, true);
  2164.  
  2165.  
  2166.  
  2167.     if (have_image)
  2168.  
  2169.     {
  2170.  
  2171.         int r = 16 - (mushrooms[i].damage * 4);
  2172.  
  2173.         g.drawImage (mushroom_image,
  2174.  
  2175.              mushrooms[i].x - r, mushrooms[i].y - r,
  2176.  
  2177.              r * 2, r * 2,
  2178.  
  2179.              this);
  2180.  
  2181.     }
  2182.  
  2183.     else
  2184.  
  2185.     {
  2186.  
  2187.         Polygon p = new Polygon ();
  2188.  
  2189.         p.addPoint (mushrooms[i].x - 16, mushrooms[i].y + 16);
  2190.  
  2191.         p.addPoint (mushrooms[i].x, mushrooms[i].y - 16);
  2192.  
  2193.         p.addPoint (mushrooms[i].x + 16, mushrooms[i].y + 16);
  2194.  
  2195.         g.setColor (missing_image_color);
  2196.  
  2197.         g.fillPolygon (p);
  2198.  
  2199.     }
  2200.  
  2201.     }
  2202.  
  2203.     
  2204.  
  2205.     boolean paint_mushroom_collision (Graphics g, Point p, int r)
  2206.  
  2207.     {
  2208.  
  2209.     int i;
  2210.  
  2211.     boolean hit = false;
  2212.  
  2213.     
  2214.  
  2215.     for (i = 0; i < mushrooms.length; i++)
  2216.  
  2217.     {
  2218.  
  2219.         if (mushrooms[i].x == 0 && mushrooms[i].y == 0)
  2220.  
  2221.         {
  2222.  
  2223.         continue;
  2224.  
  2225.         }
  2226.  
  2227.         
  2228.  
  2229.         if (collision (p, r, mushrooms[i], 16))
  2230.  
  2231.         {
  2232.  
  2233.         paint_mushroom (g, i);
  2234.  
  2235.         hit = true;
  2236.  
  2237.         }
  2238.  
  2239.     }
  2240.  
  2241.  
  2242.  
  2243.     return hit;
  2244.  
  2245.     }
  2246.  
  2247.     
  2248.  
  2249.     void paint_mushrooms (Graphics g)
  2250.  
  2251.     {
  2252.  
  2253.     int i;
  2254.  
  2255.     
  2256.  
  2257.         for (i = 0; i < mushrooms.length; i++)
  2258.  
  2259.     {
  2260.  
  2261.         if (mushrooms[i].x == 0 && mushrooms[i].y == 0)
  2262.  
  2263.         {
  2264.  
  2265.         continue;
  2266.  
  2267.         }
  2268.  
  2269.         paint_mushroom (g, i);
  2270.  
  2271.     }
  2272.  
  2273.     }
  2274.  
  2275.  
  2276.  
  2277.     void paint_mushrooms_expand (Graphics g)
  2278.  
  2279.     {
  2280.  
  2281.     int i;
  2282.  
  2283.     
  2284.  
  2285.         for (i = 0; i < mushrooms.length; i++)
  2286.  
  2287.     {
  2288.  
  2289.         if (mushrooms[i].x == 0 && mushrooms[i].y == 0)
  2290.  
  2291.         {
  2292.  
  2293.         continue;
  2294.  
  2295.         }
  2296.  
  2297.  
  2298.  
  2299.         if (mushrooms[i].damage > 0)
  2300.  
  2301.         {
  2302.  
  2303.         mushrooms[i].damage = 0;
  2304.  
  2305.         paint_mushroom (g, i);
  2306.  
  2307.         if (destroy_mushroom_sound != null)
  2308.  
  2309.         {
  2310.  
  2311.             destroy_mushroom_sound.play ();
  2312.  
  2313.         }
  2314.  
  2315.         }
  2316.  
  2317.     }
  2318.  
  2319.     }
  2320.  
  2321.     
  2322.  
  2323.     void paint_player (Graphics g)
  2324.  
  2325.     {
  2326.  
  2327.     if (!update_player && mouse.x == mouse_loc.x && mouse.y == mouse_loc.y)
  2328.  
  2329.     {
  2330.  
  2331.         return;
  2332.  
  2333.     }
  2334.  
  2335.     update_player = false;
  2336.  
  2337.  
  2338.  
  2339.     boolean have_image = tracker.checkID (tracker_player_id, true);
  2340.  
  2341.  
  2342.  
  2343.     g.clearRect (mouse.x - 16, mouse.y - 16, 32, 32);
  2344.  
  2345.  
  2346.  
  2347.     paint_mushroom_collision (g, mouse, 16);
  2348.  
  2349.  
  2350.  
  2351.     mouse.x = mouse_loc.x;
  2352.  
  2353.     mouse.y = mouse_loc.y;
  2354.  
  2355.  
  2356.  
  2357.     paint_mushroom_collision (g, mouse, 16);
  2358.  
  2359.  
  2360.  
  2361.     if (have_image)
  2362.  
  2363.     {
  2364.  
  2365.         if (game_over)
  2366.  
  2367.         {
  2368.  
  2369.         g.drawImage (dead_player_image, mouse.x - 16, mouse.y - 16, this);
  2370.  
  2371.         }
  2372.  
  2373.         else
  2374.  
  2375.         {
  2376.  
  2377.         g.drawImage (player_image, mouse.x - 16, mouse.y - 16, this);
  2378.  
  2379.         }
  2380.  
  2381.     }
  2382.  
  2383.     else
  2384.  
  2385.     {
  2386.  
  2387.         g.setColor (missing_image_color);
  2388.  
  2389.         g.fillOval (mouse.x - 16, mouse.y - 16, 32, 32);
  2390.  
  2391.     }
  2392.  
  2393.     }
  2394.  
  2395.  
  2396.  
  2397.     void paint_shots (Graphics g)
  2398.  
  2399.     {
  2400.  
  2401.     int i;
  2402.  
  2403.     int j;
  2404.  
  2405.     boolean have_image = tracker.checkID (tracker_shot_id, true);
  2406.  
  2407.     boolean hit;
  2408.  
  2409.  
  2410.  
  2411.     for (i = 0; i < shots.length; i++)
  2412.  
  2413.     {
  2414.  
  2415.         if (shots[i].x == 0 && shots[i].y == 0)
  2416.  
  2417.         {
  2418.  
  2419.         continue;
  2420.  
  2421.         }
  2422.  
  2423.         
  2424.  
  2425.         g.clearRect (shots[i].x - 8, shots[i].y - 8, 16, 16);
  2426.  
  2427.  
  2428.  
  2429.         hit = false;
  2430.  
  2431.  
  2432.  
  2433.         for (j = 0; !hit && j < centipede.length; j++)
  2434.  
  2435.         {
  2436.  
  2437.         if (collision (shots[i], 8, centipede[j], 8))
  2438.  
  2439.         {
  2440.  
  2441.             hit = true;
  2442.  
  2443.             destroy_centipede (g, j);
  2444.  
  2445.         }
  2446.  
  2447.         }
  2448.  
  2449.  
  2450.  
  2451.         for (j = 0; !hit && j < max_spiders; j++)
  2452.  
  2453.         {
  2454.  
  2455.         if (collision (shots[i], 8, spiders[j], 16))
  2456.  
  2457.         {
  2458.  
  2459.             hit = true;
  2460.  
  2461.             destroy_spider (g, j);
  2462.  
  2463.         }
  2464.  
  2465.         }
  2466.  
  2467.  
  2468.  
  2469.         for (j = 0; !hit && j < max_scorpions; j++)
  2470.  
  2471.         {
  2472.  
  2473.         if (collision (shots[i], 8, scorpions[j], 16))
  2474.  
  2475.         {
  2476.  
  2477.             hit = true;
  2478.  
  2479.             destroy_scorpion (g, j);
  2480.  
  2481.             break;
  2482.  
  2483.         }
  2484.  
  2485.         }
  2486.  
  2487.  
  2488.  
  2489.         for (j = 0; !hit && j < max_beetles; j++)
  2490.  
  2491.         {
  2492.  
  2493.         if (collision (shots[i], 8, beetles[j], 16))
  2494.  
  2495.         {
  2496.  
  2497.             hit = true;
  2498.  
  2499.             destroy_beetle (g, j);
  2500.  
  2501.         }
  2502.  
  2503.         }
  2504.  
  2505.  
  2506.  
  2507.         for (j = 0; !hit && j < max_fleas; j++)
  2508.  
  2509.         {
  2510.  
  2511.         if (collision (shots[i], 8, fleas[j], 16))
  2512.  
  2513.         {
  2514.  
  2515.             hit = true;
  2516.  
  2517.             destroy_flea (g, j);
  2518.  
  2519.         }
  2520.  
  2521.         }
  2522.  
  2523.  
  2524.  
  2525.         for (j = 0; !hit && j < mushrooms.length; j++)
  2526.  
  2527.         {
  2528.  
  2529.         if (collision (shots[i], 8, mushrooms[j], 16))
  2530.  
  2531.         {
  2532.  
  2533.             hit = true;
  2534.  
  2535.             destroy_mushroom (g, j);
  2536.  
  2537.         }
  2538.  
  2539.         }
  2540.  
  2541.  
  2542.  
  2543.         if (hit)
  2544.  
  2545.         {
  2546.  
  2547.         shots[i].x = 0;
  2548.  
  2549.         shots[i].y = 0;
  2550.  
  2551.         continue;
  2552.  
  2553.         }
  2554.  
  2555.             
  2556.  
  2557.         shots[i].y -= shot_speed;
  2558.  
  2559.  
  2560.  
  2561.         if (shots[i].y <= 0)
  2562.  
  2563.         {
  2564.  
  2565.         shots[i].x = 0;
  2566.  
  2567.         shots[i].y = 0;
  2568.  
  2569.         continue;
  2570.  
  2571.         }
  2572.  
  2573.         
  2574.  
  2575.         if (have_image)
  2576.  
  2577.         {
  2578.  
  2579.         g.drawImage (shot_image, shots[i].x - 8, shots[i].y - 8, this);
  2580.  
  2581.         }
  2582.  
  2583.         else
  2584.  
  2585.         {
  2586.  
  2587.         g.setColor (missing_image_color);
  2588.  
  2589.         g.fillOval (shots[i].x - 8, shots[i].y - 8, 16, 16);
  2590.  
  2591.         }
  2592.  
  2593.     }
  2594.  
  2595.     }
  2596.  
  2597.  
  2598.  
  2599.     void paint_centipede (Graphics g)
  2600.  
  2601.     {
  2602.  
  2603.     int i;
  2604.  
  2605.     boolean have_images = tracker.checkID (tracker_centipede_id, true);
  2606.  
  2607.     boolean hit;
  2608.  
  2609.     boolean update_vert;
  2610.  
  2611.     
  2612.  
  2613.     for (i = 0; i < centipede.length; i++)
  2614.  
  2615.     {
  2616.  
  2617.         if (centipede[i].x == 0 && centipede[i].y == 0)
  2618.  
  2619.         {
  2620.  
  2621.         continue;
  2622.  
  2623.         }
  2624.  
  2625.  
  2626.  
  2627.         g.clearRect (centipede[i].x - 8, centipede[i].y - 8, 16, 16);
  2628.  
  2629.         
  2630.  
  2631.         /* Use 0 radius to allow centipede to get closer to mushrooms */
  2632.  
  2633.         hit = paint_mushroom_collision (g, centipede[i], 0);
  2634.  
  2635.  
  2636.  
  2637.         centipede[i].x += 8 * centipede[i].hort_dir;
  2638.  
  2639.  
  2640.  
  2641.         update_vert = false;
  2642.  
  2643.         
  2644.  
  2645.         if (hit)
  2646.  
  2647.         {
  2648.  
  2649.         centipede[i].hort_dir *= -1;
  2650.  
  2651.         centipede[i].x += 16 * centipede[i].hort_dir;
  2652.  
  2653.         //centipede[i].y += 16 * centipede[i].vert_dir;
  2654.  
  2655.         update_vert = true;
  2656.  
  2657.         }
  2658.  
  2659.         else if (centipede[i].hort_dir > 0 && centipede[i].x >= screen_width - 8)
  2660.  
  2661.         {
  2662.  
  2663.         centipede[i].hort_dir = -1;
  2664.  
  2665.         centipede[i].x = screen_width - 8;
  2666.  
  2667.         //centipede[i].y += 16 * centipede[i].vert_dir;
  2668.  
  2669.         update_vert = true;
  2670.  
  2671.         }
  2672.  
  2673.         else if (centipede[i].hort_dir < 0 && centipede[i].x <= 8)
  2674.  
  2675.         {
  2676.  
  2677.         centipede[i].x = 8;
  2678.  
  2679.         centipede[i].hort_dir = 1;
  2680.  
  2681.         //centipede[i].y += 16 * centipede[i].vert_dir;
  2682.  
  2683.         update_vert = true;
  2684.  
  2685.         }
  2686.  
  2687.  
  2688.  
  2689.         if (update_vert)
  2690.  
  2691.         {
  2692.  
  2693.         centipede[i].y += 16 * centipede[i].vert_dir;
  2694.  
  2695.         if (centipede[i].y < 8 || centipede[i].y > (field_height - 8))
  2696.  
  2697.         {
  2698.  
  2699.             centipede[i].vert_dir *= -1;
  2700.  
  2701.             centipede[i].y += 32 * centipede[i].vert_dir;
  2702.  
  2703.         }
  2704.  
  2705.         }
  2706.  
  2707.  
  2708.  
  2709.         if (have_images)
  2710.  
  2711.         {
  2712.  
  2713.         /* head */
  2714.  
  2715.         if (i == 0 || (centipede[i-1].x == 0 && centipede[i-1].y == 0))
  2716.  
  2717.         {
  2718.  
  2719.             g.drawImage (centipede_images[0],
  2720.  
  2721.                  centipede[i].x - 8, centipede[i].y - 8, this);
  2722.  
  2723.         }
  2724.  
  2725.         /* body */
  2726.  
  2727.         else
  2728.  
  2729.         {
  2730.  
  2731.             g.drawImage (centipede_images[1],
  2732.  
  2733.                  centipede[i].x - 8, centipede[i].y - 8, this);
  2734.  
  2735.         }
  2736.  
  2737.         }
  2738.  
  2739.         else
  2740.  
  2741.         {
  2742.  
  2743.         g.setColor (missing_image_color);
  2744.  
  2745.         g.fillOval (centipede[i].x - 8, centipede[i].y - 8, 16, 16);
  2746.  
  2747.         }
  2748.  
  2749.  
  2750.  
  2751.         check_player_collision (centipede[i], 8);
  2752.  
  2753.     }
  2754.  
  2755.     }
  2756.  
  2757.  
  2758.  
  2759.     void paint_beetles (Graphics g)
  2760.  
  2761.     {
  2762.  
  2763.     int i;
  2764.  
  2765.     boolean have_image = tracker.checkID (tracker_beetle_id, true);
  2766.  
  2767.  
  2768.  
  2769.     for (i = 0; i < max_beetles; i++)
  2770.  
  2771.     {
  2772.  
  2773.         if (beetles[i].x == 0 && beetles[i].y == 0)
  2774.  
  2775.         {
  2776.  
  2777.         continue;
  2778.  
  2779.         }
  2780.  
  2781.         
  2782.  
  2783.         g.clearRect (beetles[i].x - 8, beetles[i].y - 8, 16, 16);
  2784.  
  2785.  
  2786.  
  2787.         paint_mushroom_collision (g, beetles[i], 8);
  2788.  
  2789.  
  2790.  
  2791.         if (Math.random () > 0.75)
  2792.  
  2793.         {
  2794.  
  2795.         beetles[i].x += beetles[i].hort_dir * 32;
  2796.  
  2797.         }
  2798.  
  2799.  
  2800.  
  2801.         if (beetles[i].x < 0 || beetles[i].x > screen_width)
  2802.  
  2803.         {
  2804.  
  2805.         beetles[i].x = 0;
  2806.  
  2807.         beetles[i].y = 0;
  2808.  
  2809.         continue;
  2810.  
  2811.         }
  2812.  
  2813.         
  2814.  
  2815.         if (have_image)
  2816.  
  2817.         {
  2818.  
  2819.         if (beetles[i].hort_dir == 1)
  2820.  
  2821.         {
  2822.  
  2823.             g.drawImage (beetle_images[0], beetles[i].x - 8, beetles[i].y - 8, this);
  2824.  
  2825.         }
  2826.  
  2827.         else
  2828.  
  2829.         {
  2830.  
  2831.             g.drawImage (beetle_images[1], beetles[i].x - 8, beetles[i].y - 8, this);
  2832.  
  2833.         }
  2834.  
  2835.         }
  2836.  
  2837.         else
  2838.  
  2839.         {
  2840.  
  2841.         g.setColor (missing_image_color);
  2842.  
  2843.         g.fillOval (beetles[i].x - 8, beetles[i].y - 8, 16, 16);
  2844.  
  2845.         }
  2846.  
  2847.  
  2848.  
  2849.         check_player_collision (beetles[i], 8);
  2850.  
  2851.     }
  2852.  
  2853.     }
  2854.  
  2855.  
  2856.  
  2857.     void paint_scorpions (Graphics g)
  2858.  
  2859.     {
  2860.  
  2861.     int i;
  2862.  
  2863.     boolean have_image = tracker.checkID (tracker_scorpion_id, true);
  2864.  
  2865.  
  2866.  
  2867.     for (i = 0; i < max_scorpions; i++)
  2868.  
  2869.     {
  2870.  
  2871.         if (scorpions[i].x == 0 && scorpions[i].y == 0)
  2872.  
  2873.         {
  2874.  
  2875.         continue;
  2876.  
  2877.         }
  2878.  
  2879.         
  2880.  
  2881.         g.clearRect (scorpions[i].x - 16, scorpions[i].y - 16, 32, 32);
  2882.  
  2883.  
  2884.  
  2885.         paint_mushroom_collision (g, scorpions[i], 16);
  2886.  
  2887.     
  2888.  
  2889.         scorpions[i].x += scorpions[i].hort_dir * 32;
  2890.  
  2891.  
  2892.  
  2893.         if (scorpions[i].x < 0 || scorpions[i].x > screen_width)
  2894.  
  2895.         {
  2896.  
  2897.         scorpions[i].x = 0;
  2898.  
  2899.         scorpions[i].y = 0;
  2900.  
  2901.         continue;
  2902.  
  2903.         }
  2904.  
  2905.         
  2906.  
  2907.         if (have_image)
  2908.  
  2909.         {
  2910.  
  2911.         if (scorpions[i].hort_dir == 1)
  2912.  
  2913.         {
  2914.  
  2915.             g.drawImage (scorpion_images[0], scorpions[i].x - 16, scorpions[i].y - 16, this);
  2916.  
  2917.         }
  2918.  
  2919.         else
  2920.  
  2921.         {
  2922.  
  2923.             g.drawImage (scorpion_images[1], scorpions[i].x - 16, scorpions[i].y - 16, this);
  2924.  
  2925.         }
  2926.  
  2927.         }
  2928.  
  2929.         else
  2930.  
  2931.         {
  2932.  
  2933.         g.setColor (missing_image_color);
  2934.  
  2935.         g.fillOval (scorpions[i].x - 16, scorpions[i].y - 16, 32, 32);
  2936.  
  2937.         }
  2938.  
  2939.  
  2940.  
  2941.         check_player_collision (scorpions[i], 16);
  2942.  
  2943.     }
  2944.  
  2945.     }
  2946.  
  2947.  
  2948.  
  2949.     void paint_spiders (Graphics g)
  2950.  
  2951.     {
  2952.  
  2953.     int i;
  2954.  
  2955.     boolean have_image = tracker.checkID (tracker_spider_id, true);
  2956.  
  2957.     double chance = Math.random ();
  2958.  
  2959.     int speed = 16;
  2960.  
  2961.  
  2962.  
  2963.     for (i = 0; i < max_spiders; i++)
  2964.  
  2965.     {
  2966.  
  2967.         if (spiders[i].x == 0 && spiders[i].y == 0)
  2968.  
  2969.         {
  2970.  
  2971.         continue;
  2972.  
  2973.         }
  2974.  
  2975.  
  2976.  
  2977.         g.clearRect (spiders[i].x - 16, spiders[i].y - 16, 32, 32);
  2978.  
  2979.  
  2980.  
  2981.         paint_mushroom_collision (g, spiders[i], 16);
  2982.  
  2983.  
  2984.  
  2985.         if (spiders[i].y < field_height/2 || spiders[i].y > field_height - 16)
  2986.  
  2987.         {
  2988.  
  2989.         spiders[i].vert_dir *= -1;
  2990.  
  2991.         spiders[i].y += spiders[i].vert_dir * speed * 2;
  2992.  
  2993.         }
  2994.  
  2995.         else if (chance < 0.10)
  2996.  
  2997.         {
  2998.  
  2999.         spiders[i].hort_dir *= -1;
  3000.  
  3001.         spiders[i].x += spiders[i].hort_dir * speed;
  3002.  
  3003.         }
  3004.  
  3005.         else if (chance > 0.90)
  3006.  
  3007.         {
  3008.  
  3009.         spiders[i].vert_dir *= -1;
  3010.  
  3011.         spiders[i].y += spiders[i].vert_dir * speed;
  3012.  
  3013.         }
  3014.  
  3015.         else
  3016.  
  3017.         {
  3018.  
  3019.         spiders[i].x += spiders[i].hort_dir * speed;
  3020.  
  3021.         }
  3022.  
  3023.  
  3024.  
  3025.         if (spiders[i].x < 16 || spiders[i].x > screen_width - 16)
  3026.  
  3027.         {
  3028.  
  3029.         if (spiders[i].hort_dir == spiders[i].start_dir)
  3030.  
  3031.         {
  3032.  
  3033.             spiders[i].hort_dir *= -1;
  3034.  
  3035.             spiders[i].x += spiders[i].hort_dir * speed * 2;
  3036.  
  3037.         }
  3038.  
  3039.         else /* spider is gone */
  3040.  
  3041.         {
  3042.  
  3043.             spiders[i].x = 0;
  3044.  
  3045.             spiders[i].y = 0;
  3046.  
  3047.             continue;
  3048.  
  3049.         }
  3050.  
  3051.         }
  3052.  
  3053.         
  3054.  
  3055.         if (have_image)
  3056.  
  3057.         {
  3058.  
  3059.         g.drawImage (spider_image, spiders[i].x - 16, spiders[i].y - 16, this);
  3060.  
  3061.         }
  3062.  
  3063.         else
  3064.  
  3065.         {
  3066.  
  3067.         g.setColor (missing_image_color);
  3068.  
  3069.         g.fillOval (spiders[i].x - 16, spiders[i].y - 16, 32, 32);
  3070.  
  3071.         }
  3072.  
  3073.         
  3074.  
  3075.         check_player_collision (spiders[i], 16);
  3076.  
  3077.     }
  3078.  
  3079.     }
  3080.  
  3081.  
  3082.  
  3083.     void paint_fleas (Graphics g)
  3084.  
  3085.     {
  3086.  
  3087.     int i;
  3088.  
  3089.     boolean have_image = tracker.checkID (tracker_flea_id, true);
  3090.  
  3091.  
  3092.  
  3093.     for (i = 0; i < max_fleas; i++)
  3094.  
  3095.     {
  3096.  
  3097.         if (fleas[i].x == 0 && fleas[i].y == 0)
  3098.  
  3099.         {
  3100.  
  3101.         continue;
  3102.  
  3103.         }
  3104.  
  3105.         
  3106.  
  3107.         g.clearRect (fleas[i].x - 8, fleas[i].y - 8, 16, 16);
  3108.  
  3109.  
  3110.  
  3111.         paint_mushroom_collision (g, fleas[i], 8);
  3112.  
  3113.  
  3114.  
  3115.         fleas[i].y += 16;
  3116.  
  3117.  
  3118.  
  3119.         if (fleas[i].y > field_height - 8)
  3120.  
  3121.         {
  3122.  
  3123.         fleas[i].x = 0;
  3124.  
  3125.         fleas[i].y = 0;
  3126.  
  3127.         continue;
  3128.  
  3129.         }
  3130.  
  3131.  
  3132.  
  3133.         if (Math.random () < 0.20)
  3134.  
  3135.         {
  3136.  
  3137.         int j = generate_mushroom (fleas[i].x, fleas[i].y);
  3138.  
  3139.         if (j != -1)
  3140.  
  3141.         {
  3142.  
  3143.             paint_mushroom (g, j);
  3144.  
  3145.         }
  3146.  
  3147.         }
  3148.  
  3149.         
  3150.  
  3151.         if (have_image)
  3152.  
  3153.         {
  3154.  
  3155.         g.drawImage (flea_image, fleas[i].x - 8, fleas[i].y - 8, this);
  3156.  
  3157.         }
  3158.  
  3159.         else
  3160.  
  3161.         {
  3162.  
  3163.         g.setColor (missing_image_color);
  3164.  
  3165.         g.fillOval (fleas[i].x - 8, fleas[i].y - 8, 16, 16);
  3166.  
  3167.         }
  3168.  
  3169.  
  3170.  
  3171.         check_player_collision (fleas[i], 8);
  3172.  
  3173.     }
  3174.  
  3175.     }
  3176.  
  3177.  
  3178.  
  3179.     void paint_string (Graphics g, String s)
  3180.  
  3181.     {
  3182.  
  3183.     int h = big_font_metrics.getHeight ();
  3184.  
  3185.     int w = big_font_metrics.stringWidth (s);
  3186.  
  3187.     g.setColor (Color.black);
  3188.  
  3189.     g.drawString (s, screen_width/2 - w/2, field_height/2);
  3190.  
  3191.     }
  3192.  
  3193.     
  3194.  
  3195.     void paint_game_over (Graphics g)
  3196.  
  3197.     {
  3198.  
  3199.     paint_string (g, "GAME OVER");
  3200.  
  3201.     }
  3202.  
  3203.  
  3204.  
  3205.     void paint_paused (Graphics g)
  3206.  
  3207.     {
  3208.  
  3209.     paint_string (g, "PAUSED");
  3210.  
  3211.     }
  3212.  
  3213.  
  3214.  
  3215.     void paint_score_and_level (Graphics g)
  3216.  
  3217.     {
  3218.  
  3219.     g.clearRect (0, field_height, screen_width/2, stats_height);
  3220.  
  3221.              
  3222.  
  3223.     g.setColor (Color.black);
  3224.  
  3225.     g.drawLine (0, field_height, screen_width, field_height);
  3226.  
  3227.  
  3228.  
  3229.     g.drawString ("Score: " + score + "  Level: " + level,
  3230.  
  3231.               0,
  3232.  
  3233.               field_height + big_font_metrics.getHeight ());
  3234.  
  3235.     }
  3236.  
  3237.  
  3238.  
  3239.     void paint_lives (Graphics g)
  3240.  
  3241.     {
  3242.  
  3243.     int x, y;
  3244.  
  3245.  
  3246.  
  3247.     g.clearRect (screen_width/2, field_height, screen_width, stats_height);
  3248.  
  3249.     
  3250.  
  3251.     g.setColor (Color.black);
  3252.  
  3253.     g.drawLine (0, field_height, screen_width, field_height);
  3254.  
  3255.     
  3256.  
  3257.     String s = "" + lives;
  3258.  
  3259.  
  3260.  
  3261.     int w = big_font_metrics.stringWidth (s);
  3262.  
  3263.     
  3264.  
  3265.     g.setColor (Color.black);
  3266.  
  3267.     g.drawString (s,
  3268.  
  3269.               screen_width - w,
  3270.  
  3271.               field_height + big_font_metrics.getHeight ());
  3272.  
  3273.  
  3274.  
  3275.     g.drawImage (lives > 0 ? player_image : dead_player_image,
  3276.  
  3277.              screen_width - w - 32,
  3278.  
  3279.              field_height, this);
  3280.  
  3281.     }
  3282.  
  3283.     
  3284.  
  3285.     /* Paint the screen. */
  3286.  
  3287.     public void paint (Graphics g)
  3288.  
  3289.     {
  3290.  
  3291.     if (need_reset)
  3292.  
  3293.     {
  3294.  
  3295.         reset_game ();
  3296.  
  3297.         need_reset = false;
  3298.  
  3299.     }
  3300.  
  3301.  
  3302.  
  3303.     if (clear_screen)
  3304.  
  3305.     {
  3306.  
  3307.         g.clearRect (0, 0, screen_width, field_height + stats_height);
  3308.  
  3309.         clear_screen = false;
  3310.  
  3311.     }
  3312.  
  3313.     
  3314.  
  3315.     if (paused)
  3316.  
  3317.     {
  3318.  
  3319.         paint_paused (g);
  3320.  
  3321.         return;
  3322.  
  3323.     }
  3324.  
  3325.     
  3326.  
  3327.     if (update_mushrooms)
  3328.  
  3329.     {
  3330.  
  3331.         paint_mushrooms (g);
  3332.  
  3333.         update_mushrooms = false;
  3334.  
  3335.     }
  3336.  
  3337.  
  3338.  
  3339.     paint_shots (g);
  3340.  
  3341.     paint_centipede (g);
  3342.  
  3343.     paint_beetles (g);
  3344.  
  3345.     paint_scorpions (g);
  3346.  
  3347.     paint_fleas (g);
  3348.  
  3349.     paint_spiders (g);
  3350.  
  3351.     paint_player (g);
  3352.  
  3353.  
  3354.  
  3355.     if (update_score || update_level)
  3356.  
  3357.     {
  3358.  
  3359.         paint_score_and_level (g);
  3360.  
  3361.         update_score = update_level = false;
  3362.  
  3363.     }
  3364.  
  3365.     
  3366.  
  3367.     if (update_lives)
  3368.  
  3369.     {
  3370.  
  3371.         paint_lives (g);
  3372.  
  3373.         update_lives = false;
  3374.  
  3375.     }
  3376.  
  3377.     
  3378.  
  3379.     if (expand_mushrooms)
  3380.  
  3381.     {
  3382.  
  3383.         paint_mushrooms_expand (g);
  3384.  
  3385.         expand_mushrooms = false;
  3386.  
  3387.     }
  3388.  
  3389.  
  3390.  
  3391.     if (game_over)
  3392.  
  3393.     {
  3394.  
  3395.         paint_game_over (g);
  3396.  
  3397.     }
  3398.  
  3399.     }
  3400.  
  3401. }
  3402.  
  3403.  
  3404.  
  3405. /*
  3406.  
  3407. Local variables:
  3408.  
  3409. eval: (progn (make-local-variable 'compile-command) (setq compile-command (concat "javac " buffer-file-name)))
  3410.  
  3411. End:
  3412.  
  3413.  
  3414.  
  3415. */
  3416.  
  3417.