//******************************************************************************** // Mecha.java // // "FROG MECHA"(ビックリどっきりメカがえる) // // (c) 1997 Maeda Mameo http://www.alles.or.jp/~mameo/ //******************************************************************************** import java.applet.*; import java.awt.*; import java.awt.image.ImageObserver; import java.awt.image.PixelGrabber; import java.awt.image.MemoryImageSource; public class Mecha extends Applet implements Runnable{ private static final byte FONTDATA[] = { 5, 0x7c, 0x12, 0x11, 0x12, 0x7c, 0, 0, //A 5, 0x7e, 0x49, 0x49, 0x49, 0x36, 0, 0, //B 5, 0x1c, 0x22, 0x41, 0x41, 0x41, 0, 0, //C 5, 0x7f, 0x41, 0x41, 0x22, 0x1c, 0, 0, //D 5, 0x7f, 0x49, 0x49, 0x49, 0x41, 0, 0, //E 5, 0x7f, 0x09, 0x09, 0x09, 0x01, 0, 0, //F 5, 0x1c, 0x22, 0x41, 0x49, 0x79, 0, 0, //G 6, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x7f, 0, //H 3, 0x41, 0x7f, 0x41, 0, 0, 0, 0, //I 5, 0x20, 0x40, 0x41, 0x3f, 0x01, 0, 0, //J 5, 0x7f, 0x08, 0x14, 0x22, 0x41, 0, 0, //K 5, 0x7f, 0x40, 0x40, 0x40, 0x40, 0, 0, //L 7, 0x78, 0x07, 0x18, 0x60, 0x18, 0x07, 0x78, //M 5, 0x7f, 0x06, 0x08, 0x30, 0x7f, 0, 0, //N 6, 0x3e, 0x41, 0x41, 0x41, 0x41, 0x3e, 0, //O 5, 0x7f, 0x09, 0x09, 0x09, 0x06, 0, 0, //P 5, 0x3e, 0x41, 0x51, 0x21, 0x5e, 0, 0, //Q 5, 0x7f, 0x09, 0x19, 0x29, 0x46, 0, 0, //R 5, 0x46, 0x49, 0x49, 0x49, 0x31, 0, 0, //S 7, 0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, //T 5, 0x3f, 0x40, 0x40, 0x40, 0x3f, 0, 0, //U 5, 0x1f, 0x20, 0x40, 0x20, 0x1f, 0, 0, //V 7, 0x3f, 0x40, 0x20, 0x10, 0x20, 0x40, 0x3f, //W 5, 0x63, 0x14, 0x08, 0x14, 0x63, 0, 0, //X 7, 0x03, 0x04, 0x08, 0x70, 0x08, 0x04, 0x03, //Y 5, 0x61, 0x55, 0x49, 0x55, 0x43, 0, 0, //Z 3, 0x00, 0x5f, 0x00, 0, 0, 0, 0, //! 6, 0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0, //? 5, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0 // }; private static final int X[] = { 0, 84, 116, 148, 180, 212, 84, 96, 108, 120}; private static final int Y[] = { 0, 0, 0, 0, 0, 0, 50, 50, 50, 50}; private static final int W[] = { 84, 32, 32, 32, 32, 32, 12, 12, 12, 12}; private static final int H[] = { 84, 48, 48, 48, 48, 48, 12, 12, 12, 12}; private static Image imageMecha, imagePart[] = new Image[10]; //--------------------------------------------------- private int imcompleteImageCount; private Image imageOff; private Graphics gOff; private int wOff, hOff; private FontMetrics FM; private Thread theThread; private String Kaerugo; //--------------------------------------------------- public void init(){ setBackground( Color.white); Kaerugo = getParameter( "Kaerugo"); Dimension d = size(); wOff = d.width; hOff = d.height; imageOff = createImage( wOff, hOff); gOff = imageOff.getGraphics(); FM = gOff.getFontMetrics(); imcompleteImageCount = 1 + 10; imageMecha = getImage( getCodeBase(), "Mecha.gif"); if( prepareImage( imageMecha, this)) imcompleteImageCount--; } public void start(){ theThread = new Thread( this); theThread.start();} public void stop(){ theThread.stop(); theThread = null;} public void paint( Graphics g){ g.drawImage( imageOff, 0, 0, this);} public void update( Graphics g){ paint( g);} public boolean imageUpdate( Image img, int infoflags, int x, int y, int width, int height){ if(( infoflags & ImageObserver.ALLBITS) != 0){ imcompleteImageCount--; return false; } return true; } //--------------------------------------------------- public void run(){ int a, i, j, k, MessagePtr; int Map[][] = new int[30][8]; WaitWhileLoading(); if( Kaerugo == null || Kaerugo.length() == 0) Kaerugo = "***) ) ) "; for( i = 0; i < 30; i++) for( j = 0; j < 8; j++) Map[i][j] = 0; eraser( 0, 0, wOff, hOff); gOff.drawImage( imagePart[0], 416, 12, this); repaint(); sleeper(1000); MessagePtr = 0; while(true){ a = Kaerugo.charAt( MessagePtr++); if( MessagePtr == Kaerugo.length()) MessagePtr = 0; switch(a){ case ')': gOff.drawImage( imagePart[1], 416, 12, this); repaint(); sleeper(200); gOff.drawImage( imagePart[2], 416, 12, this); repaint(); sleeper(200); break; case '*': gOff.drawImage( imagePart[4], 416, 12, this); repaint(); sleeper(200); gOff.drawImage( imagePart[5], 416, 12, this); repaint(); sleeper(200); break; case '%': gOff.drawImage( imagePart[ 0], 416, 12, this); for( i = 0; i < 2; i++){ eraser( 0, 0, 360, hOff); for( j = 0; j < 30; j++){ for( k = 0; k < 7; k++){ if( Map[j][k] != 0) gOff.drawImage( imagePart[ 8 + i], j * 12, 6 + k * 12, this); } } repaint(); sleeper(100); } break; default: if( a == '!') a = 26; else if( a == '?') a = 27; else if( a == ' '){ a = 28; eraser( 348, 0, 152, hOff); gOff.drawImage( imagePart[0], 416, 12, this); repaint( 348, 0, 152, hOff); } else a -= 'A'; if( a < 0 || 28 < a) break; for( i = 0; i <= FONTDATA[ a * 8]; i++){ eraser( 0, 0, 348, hOff); for( j = 0; j < 29; j++){ for( k = 0; k < 7; k++){ Map[j][k] = Map[ j + 1][k]; if( Map[j][k] != 0) gOff.drawImage( imagePart[7], j * 12, 6 + k * 12, this); } } repaint( 0, 0, 348, hOff); if( a == 28 || i == FONTDATA[ a * 8]){ for( j = 0; j < 7; j++) Map[29][j] = 0; sleeper(20); } else{ for( j = 0; j < 7; j++) Map[29][j] = FONTDATA[ a * 8 + 1 + i] >> j & 1; for( j = 0; j < 6; j++){ eraser( 348, 0, 68, hOff); gOff.drawImage( imagePart[3], 416, 12, this); for( k = 0; k < 7; k++){ if( Map[29][k] != 0) gOff.drawImage( imagePart[6], 416 - 68 * j / 5, 6 + 30 * ( 5 - j) / 5 + k * 12 * j / 5, this); } repaint( 348, 0, 12+40+16+32, hOff); sleeper(17); if( j == 1 || j == 5) sleeper(50); } } } } } } private void WaitWhileLoading(){ int i, x, y, w = 244, h = 84, pix[]; boolean blink; String s; if( imcompleteImageCount == 1 + 10){ blink = true; while( imcompleteImageCount == 1 + 10){ eraser( 0, 0, wOff, hOff); s = "Maeda Mameo http://www.alles.or.jp/~mameo/"; x = ( wOff - FM.stringWidth(s)) / 2; y = hOff / 2 + FM.getHeight() + 4; gOff.setColor( Color.gray); gOff.drawString( s, x, y); if(blink){ s = "Wait a moment."; x = ( wOff - FM.stringWidth(s)) / 2; y = hOff / 2 - 4; gOff.setColor( Color.gray); gOff.drawString( s, x, y); } repaint(); sleeper(250); blink = !blink; } } if( imcompleteImageCount > 0){ pix = new int[ w * h]; try{ new PixelGrabber( imageMecha, 0, 0, w, h, pix, 0, w).grabPixels();} catch( InterruptedException e); for( i = 0; i < w * h; i++) if( pix[i] == 0xff000000) pix[i] = 0; imcompleteImageCount = 10; for( i = 0; i < 10; i++){ imagePart[i] = createImage( new MemoryImageSource( W[i], H[i], pix, X[i] + Y[i] * w, w)); if( prepareImage( imagePart[i], this)) imcompleteImageCount--; } while( imcompleteImageCount > 0) sleeper(1); } } private void sleeper( int t){ try Thread.sleep(t); catch( InterruptedException e);} private void eraser( int x, int y, int w, int h){ gOff.setColor( Color.white); gOff.fillRect( x, y, w, h);} }