📄 fish.java
字号:
/* * Fish.java * * Copyright 2000 JJKING Software, Junichi Ito <jun1@mailhost.net> * Permission to use, copy, modify, and distribute this software and its * documentation without fee for NON-COMMERCIAL is free. */ import com.sun.kjava.Bitmap;import com.sun.kjava.Graphics;/** * This class represents a animation character "Fish". */public class Fish extends AnimChar{ /** * The bitmap patterns. */ static final short[][] pattern = { { // fish 1 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x0000, (short)0x01c0, (short)0x3e20, (short)0x43d3 , (short)0xb43c, (short)0xa403, (short)0x8404, (short)0x4b07 , (short)0x3288, (short)0x1934, (short)0x07d4, (short)0x0008 } ,{ // fish 2 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x03c0, (short)0x0420, (short)0x0fd0, (short)0x1030 , (short)0x3008, (short)0x4807, (short)0xa584, (short)0xb683 , (short)0x853c, (short)0x4fd7, (short)0x3018, (short)0x0000 } ,{ // fish disappear 1 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x0100, (short)0x0820, (short)0x1110, (short)0x0540 , (short)0x0000, (short)0x2d68, (short)0x0000, (short)0x0540 , (short)0x1110, (short)0x0820, (short)0x0100, (short)0x0000 } ,{ // fish disappear 2 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x0000, (short)0x0000, (short)0x0540, (short)0x0820 , (short)0x0100, (short)0x0aa0, (short)0x0100, (short)0x0820 , (short)0x0540, (short)0x0000, (short)0x0000, (short)0x0000 } }; /** * Fish bitmaps. */ static Bitmap[] fishBitmap = { new Bitmap(pattern[0]) , new Bitmap(pattern[1]) , new Bitmap(pattern[2]) , new Bitmap(pattern[3]) }; /** * The bitmap information. */ static final int BITMAP_WIDTH = 16; static final int BITMAP_HEIGHT = 12; /** * The active state of Fish. */ static final int STATE_MOVE = 1; static final int STATE_GOAWAY = 2; /** * The old y coordinate of top-left corner of a character. */ int oy; /** * The y step to move fish. */ static final int VY = 2; /** * This method is invoked when manager starts to manage this character. * @param mgr the animation manager. */ public void start(AnimManager mgr) { super.start(mgr); Rectangle bounds = mgr.getFieldBounds(); x = bounds.x + AnimManager.random((bounds.width - BITMAP_WIDTH) / 2) * 2; y = bounds.y; setState(STATE_MOVE); appear = true; } /** * Sets the state. * @param the state of character. */ public void setState(int state) { this.state = state; switch(state) { case STATE_GOAWAY: duration = 4; break; case STATE_MOVE: duration = 100; break; } } /** * Move the character. */ public void move() { // move until fish reaches to field edge. oy = y; if (state == STATE_MOVE) { Rectangle bounds = mgr.getFieldBounds(); if (y >= bounds.y + bounds.height - BITMAP_HEIGHT) { setState(STATE_GOAWAY); } else { y += VY; } } // decrease counter duration --; if (duration > 0) { return; } // change state setState(STATE_HIDE); } /** * Draw the character on the given graphics. * @param g the graphics. */ public void paint(Graphics g) { // clear bitmap if (state == STATE_HIDE && appear) { appear = false; g.drawRectangle(x, oy, BITMAP_WIDTH, BITMAP_HEIGHT , Graphics.ERASE, 0); } else if (y != oy) { g.drawRectangle(x, oy, BITMAP_WIDTH, BITMAP_HEIGHT , Graphics.ERASE, 0); } // draw bitmap int bmid; switch(state) { case STATE_MOVE: bmid = duration & 0x01; break; case STATE_GOAWAY: bmid = 2 + (duration & 0x01); break; default: return; } g.drawBitmap(x, y, fishBitmap[bmid]); } /** * Check if fish is eatable. */ public boolean isEatable() { return state == STATE_MOVE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -