/* "Lizards.java" */ /* 1997 Joe Rosen */ /* java applet, "Giant Human Head Eating LIZARDS" */ import java.applet.Applet; import java.awt.*; // "Credits" class class Credits { // vars /* Credits strings' font */ Font credits_Font; /* Credits text font metrics (used to retrieve Credits string width) */ FontMetrics credits_FontMetrics; /* Credits text string */ String credits_String; /* Credits text string width */ int creditsText_Width; /* Credits text string left coord */ int creditsText_LeftCoord; // methods // constructer Credits(Graphics g) { /* Credits text strings' font */ credits_Font = new Font("Helvetica", Font.BOLD, 24); /* get Credits text font metrics (used to retrieve Credits string width) */ credits_FontMetrics = g.getFontMetrics(credits_Font); /* Credits string */ credits_String = "GIANT HUMAN HEAD EATING LIZARDS -- An Electromics Movie by Joe Rosen"; /* get Credits text string width */ creditsText_Width = credits_FontMetrics.stringWidth(credits_String); /* init Credits text string left coord (left=138) */ creditsText_LeftCoord = 138 + 4; } // methods // scroll credits public void ScrollCredits(Graphics g) { /* Credits text crop */ Graphics clip_g; /* frame Credits text box (138W X 31H) */ g.setColor(Color.black); g.drawRect(7,268+13,137+4,31); /* scroll/reset Credits text string left (left=14) */ if (creditsText_LeftCoord > -(creditsText_Width)) creditsText_LeftCoord = creditsText_LeftCoord - 2; else creditsText_LeftCoord = 138 + 4; /* create clip rect */ clip_g = g.create(); clip_g.clipRect(14,275 + 13,123 + 4,23); /* write Credits text string */ clip_g.setColor(Color.black); clip_g.setFont(credits_Font); clip_g.drawString(credits_String,creditsText_LeftCoord,293 + 13); /* dispose clip rect */ clip_g.dispose(); } // end "ScrollCredits()" } // end "Credits" class // "Lizards" applet class public class Lizards extends java.applet.Applet implements Runnable { /* program constants */ /* applet canvas size */ final int APPLET_WDTH = 480; final int APPLET_HGHT = 320; /* title width and height */ final int TITLE_WDTH = 196; final int TITLE_HGHT = 226; /* variables */ /* images */ /* title gif ("Lizards") */ Image lizards; /* titles gif ("Giant" "Human" "Head" "Eating") */ Image title_1_4; /* "See:" gif */ Image see; /* scream button gif */ Image scream_btn; /* bite button gif */ Image bite_btn; /* bleed button gif */ Image bleed_btn; /* joe's body gif */ Image joe_body; /* joe's head (mouths) gif */ Image joe_mouths; /* joe's head (bleeding necks) gif */ Image joe_bleeds; /* lizard bodies gif */ Image lizard_bodies; /* lizard tail (#1) gif */ Image lizard_tail_1; /* lizard tail (#2) gif */ Image lizard_tail_2; /* lizard tongues gif */ Image lizard_tongues; /* Lizards, MediaTracker */ MediaTracker lizards_MediaTracker; /* Lizards, offscreen graphics context (composite buffer) */ Image offLizards_Image; Graphics offLizards_Graphics; /* title index */ int title_Idx; /* title delay */ long title_Delay; /* scream_btn offset */ int scream_btn_offset; /* bite_btn offset */ int bite_btn_offset; /* bleed_btn offset */ int bleed_btn_offset; /* scream_btn flag */ boolean scream_btn_flg; /* bite_btn flag */ boolean bite_btn_flg; /* bleed_btn flag */ boolean bleed_btn_flg; /* scream anim index */ int scream_Idx; // 0= frown mouth/1= smile mouth /* bleed anim index */ int bleed_Idx; // 0= frame 1/1= frame 2 /* lizard body (eye/tongue) anim index */ int lizard_body_Idx; // 0= frame 1/1= frame 2 /* lizard body (eye/tongue) anim delay */ long lizard_body_delay; /* lizard (tail wag) anim index */ int lizard_tail_Idx; // 0= frame 1/1= frame 2 /* lizard (tail wag) anim delay */ long lizard_tail_delay; /* lizard (tongue) anim index */ int lizard_tongue_Idx; // 0= short tongue/1= long tongue /* Credits object */ Credits theCredits; /* Credits visible flag (flip-flop visibility) */ boolean theCredits_flag; // true= visible/false= invisible /* Lizards, animation thread */ Thread animation_Thread = null; /* methods invoked by Java */ /* "init()" * initialize the applet */ public void init() { // initialization loop counter int lpCnt; /* resize canvas */ resize(APPLET_WDTH,APPLET_HGHT); /* create offscreen graphics context, Lizards composite buffer */ offLizards_Image = createImage(APPLET_WDTH,APPLET_HGHT); offLizards_Graphics = offLizards_Image.getGraphics(); /* retrieve .gif images */ /* title ("Lizards") */ lizards = getImage(getCodeBase(),"images/lizards.gif"); /* titles ("Giant" "Human" "Head" "Eating") */ title_1_4 = getImage(getCodeBase(),"images/title_1_4.gif"); /* "See:" */ see = getImage(getCodeBase(),"images/see.gif"); /* scream button */ scream_btn = getImage(getCodeBase(),"images/scream_btn.gif"); /* bite button */ bite_btn = getImage(getCodeBase(),"images/bite_btn.gif"); /* bleed button */ bleed_btn = getImage(getCodeBase(),"images/bleed_btn.gif"); /* joe's body */ joe_body = getImage(getCodeBase(),"images/joe_body.gif"); /* joe's head (mouths) */ joe_mouths = getImage(getCodeBase(),"images/joe_mouths.gif"); /* joe's head (bleeding necks) */ joe_bleeds = getImage(getCodeBase(),"images/joe_bleeds.gif"); /* lizard bodies */ lizard_bodies = getImage(getCodeBase(),"images/lizard_bodies.gif"); /* lizard tail (#1) */ lizard_tail_1 = getImage(getCodeBase(),"images/lizard_tail_1.gif"); /* lizard tail (#2) */ lizard_tail_2 = getImage(getCodeBase(),"images/lizard_tail_2.gif"); /* tongues */ lizard_tongues = getImage(getCodeBase(),"images/lizard_tongues.gif"); /* init Lizards MediaTracker */ lizards_MediaTracker = new MediaTracker(this); lizards_MediaTracker.addImage(lizards,0); lizards_MediaTracker.addImage(title_1_4,1); lizards_MediaTracker.addImage(see,2); lizards_MediaTracker.addImage(scream_btn,3); lizards_MediaTracker.addImage(bite_btn,4); lizards_MediaTracker.addImage(bleed_btn,5); lizards_MediaTracker.addImage(joe_body,6); lizards_MediaTracker.addImage(joe_mouths,7); lizards_MediaTracker.addImage(joe_bleeds,8); lizards_MediaTracker.addImage(lizard_bodies,9); lizards_MediaTracker.addImage(lizard_tail_1,10); lizards_MediaTracker.addImage(lizard_tail_2,11); lizards_MediaTracker.addImage(lizard_tongues,12); /* init title index */ title_Idx = 0; /* init title delay (.75 sec delay) */ title_Delay = System.currentTimeMillis(); /* init scream btn offset */ scream_btn_offset = 0; /* init bite btn offset */ bite_btn_offset = 0; /* init bleed btn offset */ bleed_btn_offset = 0; /* init scream_btn flag */ scream_btn_flg = true; /* init bite_btn flag */ bite_btn_flg = false; /* init bleed_btn flag */ bleed_btn_flg = false; /* init scream anim index */ scream_Idx = 0; // initially 0 (0= frown mouth/1= smile mouth) /* init bleed anim index */ bleed_Idx = 0; // initially 0 (0= frame 1/1= frame 2) /* init lizard body (eye/tongue) anim index */ lizard_body_Idx = 0; // 0= frame 1/1= frame 2 /* init lizard (tail wag) anim index */ lizard_tail_Idx = 0; // 0= frame 1/1= frame 2 /* lizard body (eye/tongue) anim delay (change every .50 to 1.5 seconds) */ lizard_body_delay = System.currentTimeMillis() + (((long) (Math.random() * 1000)) + 500); /* lizard (tail wag) anim delay (change every .50 to 1.5 seconds) */ lizard_tail_delay = System.currentTimeMillis() + (((long) (Math.random() * 1000)) + 500); /* instantiate Credits object */ theCredits = new Credits(offLizards_Graphics); /* init Credits visible flag (flip-flop visibility; true= visible/false= invisible) */ theCredits_flag = false; // initially invisible (false= invisible) } /* end method "init" */ /* "start()" * called when the applet becomes visible on screen */ public void start() { /* start animator thread */ animation_Thread = new Thread(this); animation_Thread.start(); } /* end method "start" */ /* "run()" * called (repeatedly) by the Thread created in "start()" */ public void run() { /* update animator thread */ while (Thread.currentThread() == animation_Thread) { /* repaint (update) the screen */ repaint(); /* begin: thread delay (125 milliseconds) */ try { Thread.sleep(125); } catch (InterruptedException e) { break; } /* end: thread delay */ } /* end "while (Thread.currentThread() == animation_Thread)" */ } /* end method "run" */ /* "stop()" * called when the applet is no longer visible on screen */ public void stop() { /* stop animator thread */ if (animation_Thread != null) animation_Thread.stop(); animation_Thread = null; } /* end method "stop" */ /* "destroy()" * called just before the browser exits */ public void destroy() { /* dispose offscreen graphics context, Lizards composite buffer */ offLizards_Graphics.dispose(); offLizards_Graphics = null; } /* end method "destroy" */ /* "update()" * update the screen */ public void update(Graphics g) { /* (intercepting "update" avoids background erase) */ /* call "paint" */ paint(g); } /* end method "update" */ /* "mouseDown()" * called when the mouse button is down */ public boolean mouseDown(Event evt, int x, int y) { // begin: scream btn if ( ((x >= 390) && (x <= (390 + 83))) && ((y >= 42) && (y <= (42 + 58))) ) { // toggle if (scream_btn_flg == false) scream_btn_flg = true; if (bite_btn_flg == true) bite_btn_flg = false; else if (bleed_btn_flg == true) bleed_btn_flg = false; /* force repaint */ repaint(); } // end: scream btn // begin: bite btn else if ( ((x >= 390) && (x <= (390 + 83))) && ((y >= 149) && (y <= (149 + 58))) ) { // toggle if (bite_btn_flg == false) { bite_btn_flg = true; /* lizard (tongue) anim index (0= short tongue/1= long tongue) */ lizard_tongue_Idx = 0; // initially 0= short tongue } if (scream_btn_flg == true) scream_btn_flg = false; else if (bleed_btn_flg == true) bleed_btn_flg = false; /* force repaint */ repaint(); } // end: bite btn // begin: bleed btn else if ( ((x >= 390) && (x <= (390 + 83))) && ((y >= 255) && (y <= (255 + 58))) ) { // toggle if (bleed_btn_flg == false) bleed_btn_flg = true; if (scream_btn_flg == true) scream_btn_flg = false; else if (bite_btn_flg == true) bite_btn_flg = false; /* force repaint */ /* force repaint */ repaint(); } // end: bleed btn // Credits visible flag (flip-flop visibility; true= visible/false= invisible) else if (theCredits_flag == true) theCredits_flag = false; else theCredits_flag = true; return true; } /* end method "mouseDown" */ /* "paint()" * paint the screen */ public void paint(Graphics g) { /* font */ Font txt_Font; /* image crop */ Graphics clip_g; /* fill buffer with white paint */ offLizards_Graphics.setColor(Color.white); offLizards_Graphics.fillRect(0,0,APPLET_WDTH,APPLET_HGHT); /* wait for images to laod before drawing */ if (lizards_MediaTracker.checkAll(true) == true) { /* draw title ("Lizards") */ offLizards_Graphics.drawImage(lizards,0,0,this); /* draw titles ("Giant" "Human" "Head" "Eating") */ if (title_Idx < 4) { clip_g = offLizards_Graphics.create(); clip_g.clipRect(0,0,115,106); clip_g.drawImage(title_1_4,(title_Idx * -115),0,this); clip_g.dispose(); } /* next title (Giant, Human, Head, Eating, BLANK) every .75 secs */ if (System.currentTimeMillis() >= title_Delay) { title_Delay = System.currentTimeMillis() + 750; if (title_Idx < 4) title_Idx++; else title_Idx = 0; } /* end "title" */ /* draw "See:" */ offLizards_Graphics.drawImage(see,387,7,this); offLizards_Graphics.drawImage(see,387,114,this); offLizards_Graphics.drawImage(see,387,220,this); /* scream btn */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(390,42,83,58); clip_g.drawImage(scream_btn,390,(42 - scream_btn_offset),this); clip_g.dispose(); /* inc/reset scream btn offset */ if (scream_btn_offset < (57 * 3)) scream_btn_offset = scream_btn_offset + 57; else scream_btn_offset = 0; /* bite btn */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(390,149,83,58); clip_g.drawImage(bite_btn,390,(149 - bite_btn_offset),this); clip_g.dispose(); /* inc/reset bite btn offset */ if (bite_btn_offset < (57 * 3)) bite_btn_offset = scream_btn_offset + 57; else bite_btn_offset = 0; /* bleed btn */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(390,255,83,58); clip_g.drawImage(bleed_btn,390,(255 - bleed_btn_offset),this); clip_g.dispose(); /* inc/reset bleed btn offset */ if (scream_btn_offset < (57 * 3)) bleed_btn_offset = bleed_btn_offset + 57; else bleed_btn_offset = 0; /* hilite btns */ offLizards_Graphics.setColor(Color.black); if (scream_btn_flg == true) { offLizards_Graphics.drawRect(388,40,86,61); offLizards_Graphics.drawRect(387,39,88,63); } else if (bite_btn_flg == true) { offLizards_Graphics.drawRect(388,147,86,61); offLizards_Graphics.drawRect(387,146,88,63); } else if (bleed_btn_flg == true) { offLizards_Graphics.drawRect(388,253,86,61); offLizards_Graphics.drawRect(387,252,88,63); } /* draw joe's body */ offLizards_Graphics.drawImage(joe_body,259,80,this); /* begin: draw joe's head */ /* create temp clip rect */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(282,11,64,78); /* scream */ if (scream_btn_flg == true) /* flip-flop scream anim index */ if (scream_Idx == 0) { clip_g.drawImage(joe_mouths,282,11,this); scream_Idx = 1; } else { clip_g.drawImage(joe_mouths,282 - 64,11,this); scream_Idx = 0; } /* bite */ else if (bite_btn_flg == true) clip_g.drawImage(joe_mouths,282 - 64,11,this); /* bleed */ else if (bleed_btn_flg == true) /* flip-flop bleed anim index */ if (bleed_Idx == 0) { clip_g.drawImage(joe_bleeds,282,11,this); bleed_Idx = 1; } else { clip_g.drawImage(joe_bleeds,282 - 64,11,this); bleed_Idx = 0; } /* we're done, destroy temp clip rect */ clip_g.dispose(); /* end: draw joe's head */ /* draw lizard body */ /* create temp clip rect */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(117,59,141,156); if (lizard_body_Idx == 0) clip_g.drawImage(lizard_bodies,117,59,this); else if (lizard_body_Idx == 1) clip_g.drawImage(lizard_bodies,(117 - 141),59,this); /* we're done, destroy temp clip rect */ clip_g.dispose(); /* lizard body (eye/tongue) anim index (0= frame 1/1= frame 2) */ if (lizard_body_delay <= System.currentTimeMillis()) { if (lizard_body_Idx == 0) lizard_body_Idx = 1; else if (lizard_body_Idx == 1) lizard_body_Idx = 0; /* re-init lizard body (eye/tongue) anim delay (change every .50 to 1.5 seconds) */ lizard_body_delay = System.currentTimeMillis() + (((long) (Math.random() * 1000)) + 500); } /* draw lizard tail */ if (lizard_tail_Idx == 0) offLizards_Graphics.drawImage(lizard_tail_1,126,215,this); else if (lizard_tail_Idx == 1) offLizards_Graphics.drawImage(lizard_tail_2,8,215,this); /* lizard (tail wag) anim index (0= frame 1/1= frame 2) */ if (lizard_tail_delay <= System.currentTimeMillis()) { if (lizard_tail_Idx == 0) lizard_tail_Idx = 1; else if (lizard_tail_Idx == 1) lizard_tail_Idx = 0; /* re-init lizard (tail wag) anim delay (change every .50 to 1.5 seconds) */ lizard_tail_delay = System.currentTimeMillis() + (((long) (Math.random() * 1000)) + 500); } /* bite */ if (bite_btn_flg == true) { /* create temp clip rect */ clip_g = offLizards_Graphics.create(); clip_g.clipRect(188,8,174,106); /* draw lizard tongue (flip-flop short and long tongues) */ if (lizard_tongue_Idx == 0) { clip_g.drawImage(lizard_tongues,188,8,this); lizard_tongue_Idx = 1; } else { clip_g.drawImage(lizard_tongues,(188 - 174),8,this); lizard_tongue_Idx = 0; } /* we're done, destroy temp clip rect */ clip_g.dispose(); } // scroll credits (theCredits_flag: true= visible/false= invisible) if (theCredits_flag == true) theCredits.ScrollCredits(offLizards_Graphics); } // end "if (lizards_MediaTracker.checkAll(true) == true)" /* begin: write text message, "Loading Images..." */ else { /* text font */ txt_Font = new Font("Helvetica", Font.PLAIN, 9); /* set text string font */ offLizards_Graphics.setFont(txt_Font); /* set text string color */ offLizards_Graphics.setColor(Color.black); /* write/draw text message */ offLizards_Graphics.drawString("Loading Images...",25,25); } /* end: write text message, "Loading Images..." */ /* frame entire buffer with black color */ offLizards_Graphics.setColor(Color.black); offLizards_Graphics.drawRect(0,0,APPLET_WDTH - 1,APPLET_HGHT - 1); /* blast buffer to screen */ g.drawImage(offLizards_Image,0,0,this); } /* end method "paint" */ } /* end class "Lizards" */ /* end file "Lizards.java" */