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

📄 npcgw.java

📁 自己写的一个手机游戏
💻 JAVA
字号:
import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;


public class NPCGW {

	Image GW1,GW1L;
	int x=100,y=195,index=0,speed=5;
	final byte Stand=0;
	final byte Run=1;
	final byte GongjiQ=2;
	final byte GongjiJ=3;
	final byte StandL=4;
	final byte RunL=5;
	final byte GongjiQL=6;
	final byte GongjiJL=7;
	
	byte GWZT=RunL;//怪物状态
	int GWdate[][]={
			{0,0,31,60},//run
			{31,0,33,60},
			{64,0,40,60},
			{104,0,65,60},//gongji 拳
			{169,0,30,60},//gongji 脚
			{199,0,79,60},
			{278,0,44,60},//挨打
			{322,0,78,60}};//死亡
	public NPCGW(){
		try {
			GW1=Image.createImage("/boss.png");
			GW1L=Image.createImage(GW1, 0, 0, GW1.getWidth(), GW1.getHeight(), Sprite.TRANS_MIRROR);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void Hua(Graphics g){
		switch (GWZT) {
		case Stand:
		case Run:
		case GongjiQ:
		case GongjiJ:
			g.setClip(x,y,GWdate[index][2],GWdate[index][3]);
			g.drawImage(GW1,x-GWdate[index][0],y-GWdate[index][1],0);
			break;
		case StandL:
		case RunL:
		case GongjiQL:
		case GongjiJL:
			g.setClip(x,y,GWdate[index][2],GWdate[index][3]);
			g.drawImage(GW1L,
					x-GW1L.getWidth()+GWdate[index][0]+GWdate[index][2],
					y-GWdate[index][1],0);
		}
		move();
	}
	public void move(){
		switch(GWZT)
		{
		case RunL:
			zhen(0,3);
			x-=speed;
			if(x<50)
			{
				GWZT=Run;
			}
			break;
		case Run:
			zhen(0,3);
			x+=speed;
			if(x>200)
			{
				GWZT=RunL;
			}
			break;
		case GongjiQ:
			zhen(4,5);
			break;
		case GongjiQL:
			zhen(4,5);
			break;
		}
		
	}
	public void zhen(int a,int b)
	{
		index++;
		if(index>b)
		{
			index=a;
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

⌨️ 快捷键说明

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