📄 fire.java
字号:
/* * Fire.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 "Fire". */public class Fire extends AnimChar{ /** * The bitmap patterns. */ static final short[][] pattern = { { // fire 1 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x0340, (short)0x4ca4, (short)0x9212, (short)0xa9c8 , (short)0x2210, (short)0x2028, (short)0x180a, (short)0xa24a , (short)0x9190, (short)0x5a24, (short)0x05c0, (short)0x0000 } ,{ // fire 2 (short)0x0010, (short)0x000c, (short)0x0002, (short)0x0000 , (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000 , (short)0x0000, (short)0x0000, (short)0x06c0, (short)0x0920 , (short)0x2840, (short)0x2a28, (short)0x04a8, (short)0x0920 , (short)0x06c0, (short)0x0000, (short)0x0000, (short)0x0000 } }; /** * Fire bitmaps. */ static Bitmap[] fireBitmap = { new Bitmap(pattern[0]) , new Bitmap(pattern[1]) }; /** * The bitmap information. */ static final int BITMAP_WIDTH = 16; static final int BITMAP_HEIGHT = 12; /** * The active state of Fire. */ static final int STATE_MOVE = 1; /** * The old x coordinate of top-left corner of a character. */ int ox; /** * The old y coordinate of top-left corner of a character. */ int oy; /** * The x step to move fire. */ int vx; /** * The y step to move fire. */ int vy; /** * The X step to move fire. */ public static final int VX = 4; /** * The Y step to move fire. */ public static final int VY = 4; /** * Create new fire with the specified information. */ public Fire(int x, int y, int vx, int vy) { this.x = x; this.y = y; this.vx = vx; this.vy = vy; ox = x; oy = y; } /** * This method is invoked when manager starts to manage this character. * @param mgr the animation manager. */ public void start(AnimManager mgr) { super.start(mgr); 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_MOVE: duration = 4; break; } } /** * Move the character. */ public void move() { ox = x; oy = y; if (state == STATE_MOVE) { Rectangle bounds = mgr.getFieldBounds(); if (x <= bounds.x || x >= bounds.x + bounds.width - BITMAP_WIDTH) { setState(STATE_HIDE); } else { x += vx; 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) { g.drawRectangle(ox, oy, BITMAP_WIDTH, BITMAP_HEIGHT , Graphics.ERASE, 0); appear = false; return; } if (ox != x || oy != y) { g.drawRectangle(ox, oy, BITMAP_WIDTH, BITMAP_HEIGHT , Graphics.ERASE, 0); } // draw bitmap g.drawBitmap(x, y, fireBitmap[duration > 1 ? 0 : 1]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -