//******************************************************************************** // MashimaroSolitaire.java // // "MashimaroSolitaire" // // (c) 2001 Maeda Mameo http://hw001.gate01.com/frog/ //******************************************************************************** public class MashimaroSolitaire extends java.applet.Applet implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, Runnable{ private java.awt.Image imageOff, imageBackground; private java.awt.Graphics gOff, gBackground; private boolean paintRequest, refreshRequest; private java.awt.FontMetrics theFontMetrics; private int theWidth, theHeight; private Thread theThread; private java.applet.AudioClip acFlush, acSmash; static final double PI = Math.PI; static final java.awt.Color COLORBACKGROUND = java.awt.Color.white; static final java.awt.Color COLORBACKGROUNDLINES = java.awt.Color.lightGray; static final java.awt.Color COLORBASE = new java.awt.Color( 255, 204, 204); static final java.awt.Color COLORBLACK = java.awt.Color.black; static final java.awt.Color COLORCURSOR = java.awt.Color.orange; static final java.awt.Color COLORLETTER = java.awt.Color.gray; static final int COLORMASHIMARO[] = { 255, 64, 64, 255, 200, 64, 255, 255, 64, 64, 255, 64, 64, 200, 255, 64, 64, 255, 255, 64, 200 }; private java.awt.Image imageMashimaro[] = new java.awt.Image[ 8 * 12], imageSullae; static final int MAXMASHIMARONUM = 100; private double mashimaroX[] = new double[ MAXMASHIMARONUM]; private double mashimaroY[] = new double[ MAXMASHIMARONUM]; private double mashimaroZ[] = new double[ MAXMASHIMARONUM]; private double mashimaroS[] = new double[ MAXMASHIMARONUM]; private double mashimaroA[] = new double[ MAXMASHIMARONUM]; private int mashimaroOff[] = new int[ MAXMASHIMARONUM]; private int mashimaroNum, mashimaroIt, mashimaroTarget; static final double MINSPEED = 3, MAXSPEED = 12; private int preparingImageNum; private int gameState; private int handsNum, hands[] = new int[ 79]; private int mashimaroRoller; private int mouseX, mouseY, nowX, nowY, pointedX, pointedY, forcusedX, forcusedY; private boolean havePressed, haveReleased; private boolean isRotating, canRotate; private boolean isJumping, canJump; private int jumpCount, jumpFromX, jumpFromY, jumpToX, jumpToY; private double boardAngle, vxx, vxy, vyx, vyy; static final int BOARDX = 10, BOARDY = 15; static final int WIDTH = 40, EDGEWIDTH = 10; static final int CX = BOARDX + EDGEWIDTH + (int)( 4.5 * WIDTH); static final int CY = BOARDY + EDGEWIDTH + (int)( 4.5 * WIDTH); static final int VX[] = { 0, 1, 0, -1}; static final int VY[] = { -1, 0, 1, 0}; private boolean fpsRequest; private String fpsString; static final long MINIMUMDELAY = 20; static final int MAXFPS = 20; //******************************************************************************** //******************************************************************************** public void init(){ java.awt.Dimension d; fpsRequest = false; fpsString = ""; paintRequest = false; setBackground( COLORBACKGROUND); d = getSize(); theWidth = d.width; theHeight = d.height; imageOff = createImage( theWidth, theHeight); gOff = imageOff.getGraphics(); imageBackground = createImage( theWidth, theHeight); gBackground = imageBackground.getGraphics(); addMouseListener( this); addMouseMotionListener( this); } public void start(){ theThread = new Thread( this); theThread.start();} public void stop(){ theThread = null;} public void update( java.awt.Graphics g){ paint( g);} public void paint( java.awt.Graphics g){ if( paintRequest){ if( fpsRequest) showStatus( fpsString); g.drawImage( imageOff, 0, 0, this); paintRequest = false; } } public void mouseClicked( java.awt.event.MouseEvent e){} public void mouseDragged( java.awt.event.MouseEvent e){ mouseX = e.getX(); mouseY = e.getY();} public void mouseEntered( java.awt.event.MouseEvent e){ fpsRequest = true;} public void mouseExited( java.awt.event.MouseEvent e){ fpsRequest = false; showStatus( null);} public void mouseMoved( java.awt.event.MouseEvent e){ mouseX = e.getX(); mouseY = e.getY();} public void mousePressed( java.awt.event.MouseEvent e){ havePressed = true;} public void mouseReleased( java.awt.event.MouseEvent e){ haveReleased = true;} public boolean imageUpdate( java.awt.Image img, int infoFlags, int x, int y, int width, int height){ if(( infoFlags & java.awt.image.ImageObserver.ALLBITS) != 0){ preparingImageNum--; return false; } return true; } //******************************************************************************** //******************************************************************************** public void run(){ int a, i; double d, nowAngle, lastAngle; String s; int fpsRefreshCount; long delay, averageTime, latestTimeMillis, t; loadMashimaroImage(); acFlush = getAudioClip( getDocumentBase(), "MashimaroSolitaireFlush.au"); acFlush.play(); acSmash = getAudioClip( getDocumentBase(), "MashimaroSolitaireSmash.au"); acSmash.play(); fpsRefreshCount = 0; delay = MINIMUMDELAY; latestTimeMillis = System.currentTimeMillis(); mashimaroRoller = 0; gameState = 0; refreshRequest = true; boardAngle = lastAngle = 0; while( theThread != null){ if( refreshRequest){ gBackground.setColor( COLORBACKGROUND); gBackground.fillRect( 0, 0, theWidth, theHeight); switch( gameState){ case 0: buttonNum = 0; pressedButton = -1; addButton( 15, 310); mashimaroNum = 0; for( i = 0; i < 7; i++){ mashimaroX[ mashimaroNum] = 100 + i * 50; mashimaroY[ mashimaroNum] = 0; mashimaroZ[ mashimaroNum] = 0; mashimaroS[ mashimaroNum] = MAXSPEED / 2; mashimaroA[ mashimaroNum] = PI / 2 + .3 - i * .1; mashimaroOff[ mashimaroNum] = 12 + i * 12; mashimaroNum++; } mashimaroIt = 3; mashimaroTarget = -1; gBackground.setColor( COLORBACKGROUNDLINES); for( i = 5; i < theHeight; i += 10) gBackground.drawLine( 0, i, 499, i); for( i = 5; i < theWidth; i += 10) gBackground.drawLine( i, 0, i, 399); gBackground.setColor( COLORLETTER); //***** old (new) / TimesRoman (Serif) / Helvetica (SansSerif) / Courier (Monospaced) gBackground.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 38)); theFontMetrics = gBackground.getFontMetrics(); s = "MashimaroSolitaire"; gBackground.drawString( s, 490 - theFontMetrics.stringWidth( s), 300); gBackground.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 18)); theFontMetrics = gBackground.getFontMetrics(); s = "(c) 2001 Maeda Mameo"; gBackground.drawString( s, 490 - theFontMetrics.stringWidth( s), 360); s = "http://www.alles.or.jp/~mameo/"; gBackground.drawString( s, 490 - theFontMetrics.stringWidth( s), 380); break; case 1: case 2: resetBoard(); handsNum = 0; gBackground.setColor( COLORBACKGROUNDLINES); for( i = 0; i < theHeight; i += 3) gBackground.drawLine( 0, i, 399, i); buttonNum = 0; pressedButton = -1; addButton( 415, 220); addButton( 415, 310); boardAngle = lastAngle = 0; forcusedX = -1; isJumping = false; } refreshRequest = false; } sleeper( delay); while( paintRequest) sleeper( 1); gOff.drawImage( imageBackground, 0, 0, this); nowX = mouseX; nowY = mouseY; pointedButton = getButton( nowX, nowY); switch( gameState){ case 0: if( havePressed){ if( pointedButton == 0) pressedButton = pointedButton; havePressed = false; } if( haveReleased){ if( pressedButton == 0 && pointedButton == 0){ acFlush.play(); gameState = 1; refreshRequest = true; } pressedButton = -1; haveReleased = false; } playTag(); drawMashimaro(); gOff.setColor( COLORBLACK); gOff.fillRoundRect( 8, 358, 94, 34, 12, 12); gOff.setColor( COLORCURSOR); gOff.fillRoundRect( 10, 360, 90, 30, 10, 10); gOff.setColor( COLORBLACK); gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 12)); gOff.drawString( "start", 60, 380); drawButton(); break; case 1: case 2: nowAngle = getAngle( nowX - CX, nowY - CY); d = Math.sqrt( Math.pow( nowX - CX, 2) + Math.pow( nowY - CY, 2)); pointedX = -1; canRotate = false; canJump = false; if( pointedButton < 0){ pointedX = (int)( 5.5 + d * Math.cos( nowAngle - boardAngle) / WIDTH) - 1; pointedY = (int)( 5.5 + d * Math.sin( nowAngle - boardAngle) / WIDTH) - 1; a = getBoard( pointedX, pointedY); if( a < 0) pointedX = -1; if( pointedX >= 0){ if( a == 0){ if( forcusedX >= 0){ for( i = 0; i < 4; i++){ if( pointedX == forcusedX + 2 * VX[ i] && pointedY == forcusedY + 2 * VY[ i]){ if( getBoard( forcusedX + VX[ i], forcusedY + VY[ i]) == 1) canJump = true; } } } } else{ for( i = 0; i < 4; i++){ if( getBoard( pointedX + VX[ i], pointedY + VY[ i]) == 1){ if( getBoard( pointedX + 2 * VX[ i], pointedY + 2 * VY[ i]) == 0) canJump = true; } } } } else{ if( pointedX < 0 && 4.5 * WIDTH <= d && d <= 4.5 * WIDTH + EDGEWIDTH) canRotate = true; } } if( havePressed){ if( pointedButton >= 0) pressedButton = pointedButton; else if( canJump){ if( getBoard( pointedX, pointedY) == 0){ if( isJumping == false){ //***** jump acFlush.play(); hands[ handsNum++] = pointedX * 1000000 + pointedY * 10000 + forcusedX * 100 + forcusedY; setBoard( forcusedX, forcusedY, 0); setBoard( ( forcusedX + pointedX) / 2, ( forcusedY + pointedY) / 2, 0); canJump = false; jumpFromX = forcusedX; jumpFromY = forcusedY; jumpToX = pointedX; jumpToY = pointedY; jumpCount = 0; isJumping = true; } else{ //***** another jump during jumping } } else{ //***** change place to jump from acSmash.play(); forcusedX = pointedX; forcusedY = pointedY; } } else{ forcusedX = -1; if( canRotate){ isRotating = true; lastAngle = nowAngle; } } havePressed = false; } if( haveReleased){ if( pressedButton >= 0 && pointedButton == pressedButton){ switch( pressedButton){ case 0: //***** back button if( handsNum > 0){ acSmash.play(); handsNum--; i = hands[ handsNum]; pointedX = i / 1000000; pointedY = i / 10000 % 100; forcusedX = i / 100 % 100; forcusedY = i % 100; setBoard( pointedX, pointedY, 0); setBoard( ( forcusedX + pointedX) / 2, ( forcusedY + pointedY) / 2, 1); setBoard( forcusedX, forcusedY, 1); gameState = 1; mashimaroRoller = 0; } break; case 1: //***** quit button acFlush.play(); gameState = 0; refreshRequest = true; } } pressedButton = -1; isRotating = false; haveReleased = false; } if( isRotating){ if( nowAngle != lastAngle){ boardAngle += angleDifference( nowAngle, lastAngle); if( boardAngle < 0) boardAngle += 2 * PI; if( 2 * PI <= boardAngle) boardAngle -= 2 * PI; } } vxx = Math.cos( boardAngle); vxy = -Math.sin( boardAngle); vyx = Math.sin( boardAngle); vyy = Math.cos( boardAngle); mashimaroNum = 0; if( isJumping){ mashimaroX[ mashimaroNum] = CX + ( jumpFromX + (double)( jumpToX - jumpFromX) * jumpCount / 10 - 4) * WIDTH * vxx + ( jumpFromY + (double)( jumpToY - jumpFromY) * jumpCount / 10 - 4) * WIDTH * vxy; mashimaroY[ mashimaroNum] = CY + ( jumpFromX + (double)( jumpToX - jumpFromX) * jumpCount / 10 - 4) * WIDTH * vyx + ( jumpFromY + (double)( jumpToY - jumpFromY) * jumpCount / 10 - 4) * WIDTH * vyy; mashimaroZ[ mashimaroNum] = 50 - 2 * Math.pow( jumpCount - 4, 2); mashimaroA[ mashimaroNum] = getAngle( nowX - mashimaroX[ mashimaroNum], nowY - mashimaroY[ mashimaroNum]); mashimaroOff[ mashimaroNum] = 24; mashimaroNum++; mashimaroX[ mashimaroNum] = CX + ( ( jumpFromX + jumpToX) / 2 - 4) * WIDTH * vxx + ( ( jumpFromY + jumpToY) / 2 - 4) * WIDTH * vxy; mashimaroY[ mashimaroNum] = CY + ( ( jumpFromX + jumpToX) / 2 - 4) * WIDTH * vyx + ( ( jumpFromY + jumpToY) / 2 - 4) * WIDTH * vyy; mashimaroZ[ mashimaroNum] = 0; mashimaroA[ mashimaroNum] = PI / 2; mashimaroOff[ mashimaroNum] = 2 + jumpCount; mashimaroNum++; jumpCount++; if( jumpCount == 10){ setBoard( jumpToX, jumpToY, 1); for( i = 0; i < 4; i++){ if( getBoard( jumpToX + VX[ i], jumpToY + VY[ i]) == 1){ if( getBoard( jumpToX + 2 * VX[ i], jumpToY + 2 * VY[ i]) == 0) canJump = true; } } if( canJump){ forcusedX = jumpToX; forcusedY = jumpToY; } else forcusedX = -1; if( isEnd()){ mashimaroRoller = 0; gameState = 2; forcusedX = -1; } isJumping = false; } } setMashimaro(); drawBoard(); drawMashimaro(); gOff.setColor( COLORBLACK); gOff.fillRoundRect( 408, 268, 84, 34, 12, 12); gOff.fillRoundRect( 408, 358, 84, 34, 12, 12); gOff.setColor( COLORCURSOR); gOff.fillRoundRect( 410, 270, 80, 30, 10, 10); gOff.fillRoundRect( 410, 360, 80, 30, 10, 10); gOff.setColor( COLORBLACK); gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 12)); gOff.drawString( "back", 460, 290); gOff.drawString( "quit", 460, 380); drawButton(); gOff.setColor( COLORLETTER); gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 50)); gOff.drawString( 44 - handsNum + "", 410, 184); gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 12)); gOff.drawString( "mashimaros", 410, 200); if( mashimaroRoller < 9){ if( handsNum == 43){ gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 38)); theFontMetrics = gOff.getFontMetrics(); s = "Congratulations !"; gOff.drawString( s, ( 400 - theFontMetrics.stringWidth( s)) / 2, 60); } else if( gameState == 2){ gOff.setFont( new java.awt.Font( "SansSerif", java.awt.Font.BOLD, 38)); theFontMetrics = gOff.getFontMetrics(); s = "Game Over !"; gOff.drawString( s, ( 400 - theFontMetrics.stringWidth( s)) / 2, 60); } } mashimaroRoller = ++mashimaroRoller % 12; lastAngle = nowAngle; } paintRequest = true; repaint(); if( ++fpsRefreshCount == MAXFPS){ t = System.currentTimeMillis(); averageTime = ( t - latestTimeMillis) / MAXFPS; fpsString = "" + 1000 / averageTime + "." + 10000 / averageTime % 10 + " frames / second"; delay = Math.max( MINIMUMDELAY, 1000 / MAXFPS - averageTime + delay); latestTimeMillis = t; fpsRefreshCount = 0; } } } private void playTag(){ int i, j, n; double d, x, y, s, a, vx, vy; for( i = 0; i < mashimaroNum; i++){ x = mashimaroX[ i]; y = mashimaroY[ i]; s = mashimaroS[ i]; a = mashimaroA[ i]; vx = s * Math.cos( a); x += vx; if( x < 0){ x = 0; vx *= -1;} else if( x >= 500){ x = 499; vx *= -1;} vy = s * Math.sin( a); y += vy; if( y < 0){ y = 0; vy *= -1;} else if( y >= 400){ y = 399; vy *= -1;} a = getAngle( vx, vy); for( j = 0; j < mashimaroNum; j++){ if( i != j && Math.pow( mashimaroX[ j] - x, 2) + Math.pow( mashimaroY[ j] - y, 2) < 900){ //***** touched x = mashimaroX[ i]; y = mashimaroY[ i]; a = getAngle( x - mashimaroX[ j], y - mashimaroY[ j]); s = ( s + mashimaroS[ j]) / 2; mashimaroS[ j] = s; if( a < PI) mashimaroA[ j] = a + PI; else mashimaroA[ j] = a - PI; if( i == mashimaroIt){ mashimaroS[ j] = MINSPEED; mashimaroIt = j; mashimaroTarget = -1; } } } if( i == mashimaroIt){ if( mashimaroTarget < 0){ //***** seek the target n = -1; for( j = 0; j < mashimaroNum; j++){ if( j != i){ d = angleDifference( getAngle( mashimaroX[ j] - x, mashimaroY[ j] - y), a); if( -.5 < d && d < .5) n = j; } } if( n >= 0) mashimaroTarget = n; } else{ //***** chase the target a += angleDifference( getAngle( mashimaroX[ mashimaroTarget] - x, mashimaroY[ mashimaroTarget] - y), a) * .8; s += .2; } if( s < MINSPEED) s = MINSPEED; else if( s > MAXSPEED) s = MAXSPEED; } else{ if( Math.pow( x - mashimaroX[ mashimaroIt], 2) + Math.pow( y - mashimaroY[ mashimaroIt], 2) < 40000){ a += angleDifference( getAngle( x - mashimaroX[ mashimaroIt], y - mashimaroY[ mashimaroIt]), a) * .2; } a += angleDifference( getAngle( 250 - x, 200 - y), a) * .1; s += .2; if( s < MINSPEED) s = MINSPEED; else if( s > MAXSPEED) s = MAXSPEED; } mashimaroX[ i] = x; mashimaroY[ i] = y; mashimaroS[ i] = s; mashimaroA[ i] = a; } } private boolean isEnd(){ int i, x, y; if( handsNum == 43) return true; for( y = 0; y < 9; y++){ for( x = 0; x < 9; x++){ if( getBoard( x, y) == 1){ for( i = 0; i < 4; i++){ if( getBoard( x + VX[ i], y + VY[ i]) == 1){ if( getBoard( x + 2 * VX[ i], y + 2 * VY[ i]) == 0) return false; } } } } } return true; } private void drawBoard(){ int i, j, px[] = new int[ 5], py[] = new int[ 5]; double hx, hy, x, y, vx, vy; if( isRotating || canRotate){ gOff.setColor( COLORCURSOR); } else{ gOff.setColor( COLORBACKGROUND); } gOff.fillOval( BOARDX, BOARDY, 9 * WIDTH + 2 * EDGEWIDTH, 9 * WIDTH + 2 * EDGEWIDTH); gOff.setColor( COLORLETTER); gOff.drawOval( BOARDX, BOARDY, 9 * WIDTH + 2 * EDGEWIDTH, 9 * WIDTH + 2 * EDGEWIDTH); gOff.setColor( COLORBASE); gOff.fillOval( BOARDX + EDGEWIDTH, BOARDY + EDGEWIDTH, 9 * WIDTH, 9 * WIDTH); gOff.setColor( COLORLETTER); gOff.drawOval( BOARDX + EDGEWIDTH, BOARDY + EDGEWIDTH, 9 * WIDTH, 9 * WIDTH); hx = CX - 4.5 * WIDTH * vxx - 4.5 * WIDTH * vxy; hy = CY - 4.5 * WIDTH * vyx - 4.5 * WIDTH * vyy; for( i = 0; i < 9; i++){ x = hx; y = hy; for( j = 0; j < 9; j++){ if( getBoard( j, i) >= 0){ px[ 0] = px[ 4] = (int)( x); px[ 1] = (int)( x + WIDTH * vxx); px[ 2] = (int)( x + WIDTH * vxx + WIDTH * vxy); px[ 3] = (int)( x + WIDTH * vxy); py[ 0] = py[ 4] = (int)y; py[ 1] = (int)( y + WIDTH * vyx); py[ 2] = (int)( y + WIDTH * vyx + WIDTH * vyy); py[ 3] = (int)( y + WIDTH * vyy); if( pointedX == j && pointedY == i && canJump && getBoard( pointedX, pointedY) == 0){ gOff.setColor( COLORCURSOR); } else{ gOff.setColor( COLORBACKGROUND); } gOff.fillPolygon( px, py, 5); gOff.setColor( COLORLETTER); gOff.drawPolyline( px, py, 5); } x += WIDTH * vxx; y += WIDTH * vyx; } hx += WIDTH * vxy; hy += WIDTH * vyy; } } private void setMashimaro(){ int i, j; double hx, hy, x, y, vx, vy; mashimaroIt = -1; hx = CX - 4 * WIDTH * vxx - 4 * WIDTH * vxy; hy = CY - 4 * WIDTH * vyx - 4 * WIDTH * vyy; for( i = 0; i < 9; i++){ x = hx; y = hy; for( j = 0; j < 9; j++){ mashimaroX[ mashimaroNum] = x; mashimaroY[ mashimaroNum] = y; mashimaroZ[ mashimaroNum] = 0; if( getBoard( j, i) == 1){ if( forcusedX == j && forcusedY == i){ mashimaroA[ mashimaroNum] = getAngle( nowX - x, nowY - y); mashimaroOff[ mashimaroNum] = 24; mashimaroNum++; } else if( pointedX == j && pointedY == i && canJump){ mashimaroA[ mashimaroNum] = PI / 2; mashimaroOff[ mashimaroNum] = 0; mashimaroIt = mashimaroNum; mashimaroNum++; } else{ if( handsNum == 43 && isJumping == false){ mashimaroZ[ mashimaroNum] = 36 - Math.pow( mashimaroRoller - 6, 2); mashimaroA[ mashimaroNum] = PI / 2; mashimaroOff[ mashimaroNum] = 0; } else if( gameState == 2){ mashimaroA[ mashimaroNum] = 2 * PI * (( mashimaroRoller + 3) % 12) / 12; mashimaroOff[ mashimaroNum] = 48; } else{ mashimaroA[ mashimaroNum] = PI / 2; mashimaroOff[ mashimaroNum] = 0; } mashimaroNum++; } } x += WIDTH * vxx; y += WIDTH * vyx; } hx += WIDTH * vxy; hy += WIDTH * vyy; } } private void drawMashimaro(){ int i, j, n, zOrder[] = new int[ mashimaroNum]; for( i = 0; i < mashimaroNum; i++) zOrder[ i] = i; for( i = 0; i < mashimaroNum - 1; i++){ for( j = mashimaroNum - 2; j >= i; j--){ if( mashimaroY[ zOrder[ j]] < mashimaroY[ zOrder[ j + 1]]){ n = zOrder[ j]; zOrder[ j] = zOrder[ j + 1]; zOrder[ j + 1] = n; } } } /* if( mashimaroIt >= 0){ if( gameState == 0){ gOff.draw gOff.setColor( COLORLETTER); gOff.fillOval( (int)( mashimaroX[ mashimaroIt] - 30), (int)( mashimaroY[ mashimaroIt] - 16), 60, 48); gOff.setColor( COLORBACKGROUND); gOff.fillOval( (int)( mashimaroX[ mashimaroIt] - 20), (int)( mashimaroY[ mashimaroIt] - 8), 40, 32); } else gOff.drawImage( imageMashimaro[ 1], (int)( mashimaroX[ mashimaroIt] - 21), (int)( mashimaroY[ mashimaroIt] - 79 + 20), null); } */ for( i = mashimaroNum - 1; i >=0; i--){ n = zOrder[ i]; if( n == mashimaroIt){ if( gameState == 0) gOff.drawImage( imageSullae, (int)( mashimaroX[ n] - 21), (int)( mashimaroY[ n] - 79 + 20 - 36), null); else gOff.drawImage( imageMashimaro[ 1], (int)( mashimaroX[ n] - 21), (int)( mashimaroY[ n] - 79 + 20), null); } gOff.drawImage( imageMashimaro[ mashimaroOff[ n] + ((int)( 12 * ( mashimaroA[ n] + 2 * PI / 24) / 2 / PI) + 9) % 12], (int)( mashimaroX[ n] - 21), (int)( mashimaroY[ n] - mashimaroZ[ n] - 79 + 20), null); } } //******************************************************************************** //******************************************************************************** static final int MAXBUTTONNUM = 10; private int buttonX[] = new int[ MAXBUTTONNUM]; private int buttonY[] = new int[ MAXBUTTONNUM]; private int buttonNum, pointedButton, pressedButton; void addButton( int x, int y){ buttonX[ buttonNum] = x; buttonY[ buttonNum] = y; buttonNum++; } int getButton( int x, int y){ int i; for( i = 0; i < buttonNum; i++){ if( buttonX[ i] <= x && x < buttonX[ i] + 42 && buttonY[ i] <= y && y < buttonY[ i] + 79) return i; } return -1; } void drawButton(){ int i; for( i = 0; i < buttonNum; i++){ if( i == pressedButton){ gOff.drawImage( imageMashimaro[ 24], buttonX[ i], buttonY[ i], null); } else if( i == pointedButton){ gOff.drawImage( imageMashimaro[ 1], buttonX[ i], buttonY[ i], null); gOff.drawImage( imageMashimaro[ 0], buttonX[ i], buttonY[ i], null); } else{ gOff.drawImage( imageMashimaro[ 0], buttonX[ i], buttonY[ i], null); } } } //******************************************************************************** //******************************************************************************** private int board[] = new int[ 81]; void resetBoard(){ int i; for( i = 0; i < 81; i++) board[ i] = -1; for( i = 0; i < 9; i++){ board[ 3 + i * 9] = 1; board[ 4 + i * 9] = 1; board[ 5 + i * 9] = 1; board[ 27 + i] = 1; board[ 36 + i] = 1; board[ 45 + i] = 1; } board[ 40] = 0; } int getBoard( int x, int y){ if( x < 0 || 8 < x || y < 0 || 8 < y) return -1; return board[ x + y * 9]; } void setBoard( int x, int y, int n){ board[ x + y * 9] = n; } //******************************************************************************** //******************************************************************************** private double getAngle( double vx, double vy){ double a; if( vy == 0) if( vx < 0) return PI; else return 0; a = Math.acos( vx / Math.sqrt( vx * vx + vy * vy)); if( vy > 0) return a; else return ( 2 * PI - a); } private double angleDifference( double t, double s){ double a; a = t - s; if( a > PI) return( a - 2 * PI); if( a < -PI) return( a + 2 * PI); return a; } private void sleeper( long t){ try{ theThread.sleep( t);} catch( InterruptedException e){}} private void loadMashimaroImage(){ int a, i, j, r, g, b, x, y, w, h, pix[], pix1[], pix2[]; java.awt.Image imageMashimaroSource; int fallOffset[] = { 0, 1, 4, 8, 24, 48, 70, 70, 70, 70}; int fallSize[] = { 18, 22, 22, 22, 22, 22, 12, 6, 2, 1}; preparingImageNum = 2; imageMashimaroSource = getImage( getDocumentBase(), "Mashimaro12.gif"); if( prepareImage( imageMashimaroSource, this)) preparingImageNum--; imageSullae = getImage( getDocumentBase(), "Sullae.gif"); if( prepareImage( imageSullae, this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); w = imageMashimaroSource.getWidth( this); h = imageMashimaroSource.getHeight( this); pix = new int[ w * h]; try{ new java.awt.image.PixelGrabber( imageMashimaroSource, 0, 0, w, h, pix, 0, w).grabPixels();} catch( InterruptedException e){} a = pix[ 1]; for( i = 0; i < w * h; i++) if( pix[ i] == a) pix[ i] = 0; pix1 = new int[ 44 * 36]; try{ new java.awt.image.PixelGrabber( imageSullae, 0, 0, 44, 36, pix1, 0, 44).grabPixels();} catch( InterruptedException e){} a = pix1[ 0]; for( i = 0; i < 44 * 36; i++) if( pix1[ i] == a) pix1[ i] = 0; preparingImageNum = 1; imageSullae = createImage( new java.awt.image.MemoryImageSource( 44, 36, pix1, 0, 44)); if( prepareImage( imageSullae, this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); preparingImageNum = 1; imageMashimaro[ 0] = createImage( new java.awt.image.MemoryImageSource( 42, 79, pix, 1, w)); if( prepareImage( imageMashimaro[ 0], this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); pix2 = new int[ 42 * 79]; for( i = 0; i < 42 * 79; i++) pix2[ i] = 0; for( i = 0; i < 7; i++){ for( j = 0; j < 7; j++){ for( y = 0; y < 73; y++){ for( x = 0; x < 36; x++){ pix2[ j + x + ( i + y) * 42] |= pix[ 1 + 3 + x + ( 3 + y) * w]; } } } } for( i = 0; i < 42 * 79; i++) if( pix2[ i] != 0) pix2[ i] = 0xffffcc00; preparingImageNum = 1; imageMashimaro[ 1] = createImage( new java.awt.image.MemoryImageSource( 42, 79, pix2, 0, 42)); if( prepareImage( imageMashimaro[ 1], this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); for( i = 0; i < 10; i++){ for( j = 0; j < 42 * 79; j++) pix2[ j] = 0; for( y = 0; y < 21; y++){ for( x = 0; x < 42; x++){ if( Math.pow( x - 20.5, 2) + Math.pow( 2 * ( y - 10), 2) < Math.pow( fallSize[ i], 2)) pix2[ x + ( 58 + y) * 42] = 0xff000000; } } for( y = 0; y < 70 - fallOffset[ i]; y++){ for( x = 0; x < 42; x++){ a = pix[ 1 + x + ( 3 + y) * w]; if( a != 0 && ( fallOffset[ i] + y < 67 || ( fallOffset[ i] + y >= 67 && ( fallOffset[ i] + y - 66) * 3 < x && x < 42 - ( fallOffset[ i] + y - 66) * 3))) pix2[ x + ( 3 + fallOffset[ i] + y) * 42] = a; } } preparingImageNum = 1; imageMashimaro[ 2 + i] = createImage( new java.awt.image.MemoryImageSource( 42, 79, pix2, 0, 42)); if( prepareImage( imageMashimaro[ 2 + i], this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); } for( i = 0; i < 7; i++){ r = COLORMASHIMARO[ i * 3]; g = COLORMASHIMARO[ i * 3 + 1]; b = COLORMASHIMARO[ i * 3 + 2]; for( j = 0; j < 12; j++){ for( y = 0; y < 79; y++){ for( x = 0; x < 42; x++){ a = pix[ 1 + ( j % 6) * 43 + x + ( j / 6 * 79 + y) * w]; if( a != 0){ pix2[ y * 42 + x] = 0xff000000 | ( a & 0xff0000 * r >> 8) & 0xff0000 | ( a & 0x00ff00 * g >> 8) & 0x00ff00 | a & 0x0000ff * b >> 8; } else{ pix2[ y * 42 + x] = 0; } } } preparingImageNum = 1; imageMashimaro[ 12 + i * 12 + j] = createImage( new java.awt.image.MemoryImageSource( 42, 79, pix2, 0, 42)); if( prepareImage( imageMashimaro[ 12 + i * 12 + j], this)) preparingImageNum--; while( preparingImageNum > 0) sleeper( 10); } } } }