⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kuma.java

📁 随着手机的日益普及、Java功能在移动设备上的实现
💻 JAVA
字号:
/* * Kuma.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 "Kuma".  */public class Kuma extends AnimChar{	/**	 * The bitmap patterns.	 */	static final short[][] pattern = {		{	// kuma_f1			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c1c, (short)0x2222, (short)0x47e2			, (short)0x4c1a, (short)0x5004, (short)0x2002, (short)0x4662			, (short)0x4662, (short)0x4002, (short)0x4182, (short)0x2392			, (short)0x16e4, (short)0x1008, (short)0x0c1c, (short)0x33e2			, (short)0x4001, (short)0x980d, (short)0xe80b, (short)0x0808			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e		}		,{	// kuma_walk_l1			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x0038, (short)0x1844, (short)0x27c4			, (short)0x2c34, (short)0x300c, (short)0x2002, (short)0x4cc2			, (short)0x4cc2, (short)0x4002, (short)0x4302, (short)0x2722			, (short)0x1dc4, (short)0x1008, (short)0x0c1c, (short)0x33e2			, (short)0x4001, (short)0x980d, (short)0xe80b, (short)0x0808			, (short)0x0b08, (short)0x1e38, (short)0x20c4, (short)0x3f3c		}		,{	// kuma_walk_l2			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x0038, (short)0x1844, (short)0x27c4			, (short)0x2c34, (short)0x300c, (short)0x2002, (short)0x4cc2			, (short)0x4cc2, (short)0x4002, (short)0x4302, (short)0x2722			, (short)0x1dc4, (short)0x1008, (short)0x0c18, (short)0x13e4			, (short)0x1004, (short)0x18e4, (short)0x0908, (short)0x09fc			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e		}		,{	// kuma_walk_r1			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c00, (short)0x2218, (short)0x23e4			, (short)0x2c34, (short)0x300c, (short)0x4004, (short)0x4332			, (short)0x4332, (short)0x4002, (short)0x4062, (short)0x44e4			, (short)0x23b8, (short)0x1008, (short)0x3830, (short)0x47cc			, (short)0x8002, (short)0xb019, (short)0xd017, (short)0x1010			, (short)0x10d0, (short)0x1c78, (short)0x2304, (short)0x3cfc		}		,{	// kuma_walk_r2			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c00, (short)0x2218, (short)0x23e4			, (short)0x2c34, (short)0x300c, (short)0x4004, (short)0x4332			, (short)0x4332, (short)0x4002, (short)0x4062, (short)0x44e4			, (short)0x23b8, (short)0x1008, (short)0x1830, (short)0x27c8			, (short)0x2008, (short)0x2718, (short)0x1090, (short)0x3f90			, (short)0x2008, (short)0x67cc, (short)0x4824, (short)0x701c		}		,{	// kuma eat 1			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c1c, (short)0x2222, (short)0x47e2			, (short)0x4c1a, (short)0x5004, (short)0x2002, (short)0x4662			, (short)0x4662, (short)0x4002, (short)0x4182, (short)0x2392			, (short)0x16e4, (short)0x1bf8, (short)0x310e, (short)0x5ad9			, (short)0x4491, (short)0x3bee, (short)0x0808, (short)0x0808			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e		}		,{	// kuma eat 2			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c1c, (short)0x2222, (short)0x47e2			, (short)0x4c1a, (short)0x5004, (short)0x2002, (short)0x4662			, (short)0x4662, (short)0x4002, (short)0x4392, (short)0x26e2			, (short)0x1bfc, (short)0x310e, (short)0x5ad9, (short)0x4491			, (short)0x3bee, (short)0x0808, (short)0x0808, (short)0x0808			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e 		}		,{	// kuma eat 3			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c1c, (short)0x2222, (short)0x47e2			, (short)0x4c1a, (short)0x5004, (short)0x2002, (short)0x4662			, (short)0x4662, (short)0x4002, (short)0x4182, (short)0x3b92			, (short)0x46e7, (short)0xb5fc, (short)0xa403, (short)0x8404			, (short)0x7b0f, (short)0x5292, (short)0x393c, (short)0x0fd4			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e		}		,{	// kuma eat 4			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x1c1c, (short)0x2222, (short)0x47e2			, (short)0x4c1a, (short)0x5004, (short)0x2002, (short)0x4662			, (short)0x4662, (short)0x4002, (short)0x3b92, (short)0x46e7			, (short)0xb5fc, (short)0xa403, (short)0x8404, (short)0x7b0f			, (short)0x5292, (short)0x393c, (short)0x0fd4, (short)0x0808			, (short)0x1004, (short)0x33e6, (short)0x2412, (short)0x380e		}		,{	// kuma groggy 1			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x3838, (short)0x4444, (short)0x8fc4			, (short)0x9834, (short)0xa008, (short)0x5c74, (short)0xa28c			, (short)0xaaac, (short)0x9864, (short)0x8304, (short)0x4724			, (short)0x2dc8, (short)0x2010, (short)0x1838, (short)0x27c6			, (short)0x4001, (short)0x901e, (short)0xb010, (short)0xd018			, (short)0x1004, (short)0x23f2, (short)0x240e, (short)0x3800 		}		,{	// kuma groggy 2 			  (short)0x0010, (short)0x0018, (short)0x0002, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x0e0e, (short)0x1111, (short)0x23f1			, (short)0x260d, (short)0x2802, (short)0x130d, (short)0x2aab			, (short)0x28a3, (short)0x271d, (short)0x20c1, (short)0x11c9			, (short)0x0b72, (short)0x0804, (short)0x1e0c, (short)0x61f2			, (short)0x8002, (short)0x7809, (short)0x080d, (short)0x180b			, (short)0x2008, (short)0x4fc4, (short)0x7024, (short)0x001c		}		,{	// kuma groggy 3			  (short)0x0018, (short)0x0010, (short)0x0004, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x0000, (short)0x0e00, (short)0x0000			, (short)0x1100, (short)0x0000, (short)0x17e0, (short)0x0000			, (short)0x1819, (short)0x8000, (short)0x11c6, (short)0x7e00			, (short)0x6222, (short)0x2300, (short)0xa2a2, (short)0xa100			, (short)0xa18a, (short)0xa500, (short)0xa6ca, (short)0x4500			, (short)0x68f2, (short)0x0200, (short)0x2a44, (short)0xc300			, (short)0x36c5, (short)0x4500, (short)0x1804, (short)0x4500			, (short)0x061c, (short)0xf100, (short)0x01f7, (short)0x9e00 		}		,{	// kuma groggy 4 			  (short)0x0018, (short)0x0010, (short)0x0004, (short)0x0000			, (short)0x0101, (short)0x0000, (short)0x0000, (short)0x0000			, (short)0x0000, (short)0x0000, (short)0x0e00, (short)0x0000			, (short)0x1100, (short)0x0000, (short)0x17e0, (short)0x0000			, (short)0x18d9, (short)0x8000, (short)0x12a6, (short)0x7e00			, (short)0x6222, (short)0x2300, (short)0xa1c2, (short)0xa100			, (short)0xa30a, (short)0xa500, (short)0xaaca, (short)0x4500			, (short)0x68f2, (short)0x0200, (short)0x2744, (short)0xc300			, (short)0x20c5, (short)0x4500, (short)0x1804, (short)0x4500			, (short)0x061c, (short)0xf100, (short)0x01f7, (short)0x9e00		}	};	/**	 * Kuma bitmaps.	 */	static Bitmap[] kumaBitmap = {		  new Bitmap(pattern[0])		// walk		, new Bitmap(pattern[1])		, new Bitmap(pattern[2])		, new Bitmap(pattern[3])		, new Bitmap(pattern[4])		// eat		, new Bitmap(pattern[5])		, new Bitmap(pattern[6])		, new Bitmap(pattern[7])		, new Bitmap(pattern[8])		// groggy		, new Bitmap(pattern[9])		, new Bitmap(pattern[10])		, new Bitmap(pattern[11])		, new Bitmap(pattern[12])	};	/**	 * The bitmap information.	 */	static final int BITMAP_WIDTH = 16;	static final int BITMAP_HEIGHT = 24;	/**	 * The active state of Kuma.	 */	static final int STATE_WAIT = 1;	static final int STATE_WALK_L = 2;	static final int STATE_WALK_R = 3;	static final int STATE_EAT = 4;	static final int STATE_GROGGY = 5;	/**	 * The x step for kuma movement.	 */	static final int VX = 4;	/**	 * The old x coordinate of top-left corner of a character.	 */	int ox;	/**	 * 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 + (bounds.width - BITMAP_WIDTH) / 2;		y = bounds.y + bounds.height - BITMAP_HEIGHT;		ox = x;		setState(STATE_WAIT);		appear = true;	}	/**	 * Sets the state.	 * @param the state of character.	 */	public void setState(int state)	{		this.state = state;				switch(state) {		case STATE_WALK_L:		case STATE_WALK_R:			duration = (duration & 1) + 2;			break;		case STATE_EAT:			duration = 8;			break;		case STATE_GROGGY:			duration = 20;			break;		}	}	/**	 * Move right.	 */	public void moveRight()	{		Rectangle bounds = mgr.getFieldBounds();		ox = x;		x += VX;		if (x > bounds.x + bounds.width - BITMAP_WIDTH) x = ox;		setState(STATE_WALK_R);	}	/**	 * Move left.	 */	public void moveLeft()	{		Rectangle bounds = mgr.getFieldBounds();		ox = x;		x -= VX;		if (x < bounds.x) x = ox;		setState(STATE_WALK_L);	}	/**	 * Check if kuma is busy now.	 */	public boolean isBusy()	{		return state == STATE_EAT || !isLive();	}	/**	 * Check if kuma is groggy now.	 */	public boolean isLive()	{		return state == STATE_WAIT			|| state == STATE_WALK_R			|| state == STATE_WALK_L			|| state == STATE_EAT;	}		/**	 * Check if kuma hit the specified character.	 */	public boolean isHit(AnimChar c)	{		if (c == null || c == this) return false;		int dx = c.getX() - x;		int dy = c.getY() - y;		return dx >= -8 && dx <= 8 && dy >= -4;	}		/**	 * Move the character.	 */	public void move()	{		// decrease counter		if (duration > 0) {			duration --;			return;		}		// change state		switch(state) {		case STATE_WALK_L:		case STATE_WALK_R:		case STATE_EAT:			setState(STATE_WAIT);			break;		case STATE_GROGGY:			setState(STATE_HIDE);			break;		}	}		/**	 * 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(ox, y, BITMAP_WIDTH, BITMAP_HEIGHT				, Graphics.ERASE, 0);		}		else if (x != ox) {			g.drawRectangle(ox, y, BITMAP_WIDTH, BITMAP_HEIGHT				, Graphics.ERASE, 0);		}				// draw bitmap		int bmid;		switch(state)		{		case STATE_EAT:			bmid = 5 + (duration & 0x01) + (duration < 4 ? 0 : 2);			break;		case STATE_WALK_L:			bmid = 1 + (duration & 0x01);			break;		case STATE_WALK_R:			bmid = 3 + (duration & 0x01);			break;		case STATE_WAIT:			bmid = 0;			break;		case STATE_GROGGY:			bmid = 9 + (duration & 0x01) + (duration < 12 ? 2 : 0);			break;		default:			return;		}		if (bmid < 11) {			g.drawBitmap(x, y, kumaBitmap[bmid]);		}		else {			g.drawRectangle(x, y, BITMAP_WIDTH, 8, Graphics.ERASE, 0);			g.drawBitmap(x-4, y+8, kumaBitmap[bmid]);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -