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

📄 npcmanger.java

📁 用j2me做的空战游戏.多npc,碰撞,特效,道具都有!推荐下载
💻 JAVA
字号:
import java.io.IOException;

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

public class NPCManger 
{
	NPC[] npc;
	Image[] im = new Image[10]; 
	int time;
	public NPCManger(int max)
	{
		npc = new NPC[max];
		
		
		
		
		try {
			im[0] = Image.createImage( "/npc1.png");
			im[1] = Image.createImage( "/npc2.png");
			im[2] = Image.createImage( "/npc3.png");
			im[3] = Image.createImage( "/npc4.png");
			im[4] = Image.createImage( "/npc6.png");
			im[5] = Image.createImage( "/tan.png");
			
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
	
	public void render (Graphics g)
	{
		for (int i=0;i<npc.length ;i++)
		{
			if ( npc[i] != null)
			{
				npc[i].render( g);
			}
		}
	}
	public void upData(ZDManger zm,PL pl,TXManger tm)
	{
		zl();
		for (int i=0;i<npc.length ;i++)
		{
			if ( npc[i] != null)
			{
				npc[i].upData( zm);
				if (Math.abs( npc[i].x -pl.x )<13&&Math.abs( npc[i].y-pl.y)<14)
				{
					npc[i] = null;
					tm.create( 3,pl.x,pl.y);
					pl.m = 20;
					pl.x = 80;
					pl.y = 280;
					break;
				}
				
				if (npc[i].last ==true)
				{
					if (npc[i].x < -50||npc[i].x >250||npc[i].y < -50||npc[i].y >300)
					{
						npc[i] = null;
					}
				}
			}
		}
		
	}
	public void create (int m,int x,int y)
	{
		for (int i=0;i<npc.length ;i++)
		{
			if (npc[i] == null)
			{
				switch (m)
				{
				case 1:
					npc[i] = new NPC1(x,y,im[0]);
					break;
				case 2:
					npc[i] = new NPC2(x,y,im[1]);
					break;
				case 3:
					npc[i] = new NPC3(x,y,im[2]);
					break;
				case 4:
					npc[i] = new NPC4(x,y,im[3]);
					break;
				case 5:
					npc[i] = new NPC5(x,y,im[3]);
					break;
				case 6:
					npc[i] = new NPC6(x,y,im[3]);
					break;
				case 7:
					npc[i] = new NPC7(x,y,im[4]);
					break;
				case 8:
					npc[i] = new NPC8(x,y,im[5]);
					break;
				}
				break;
			}
		}
	}
	public void zl()
	{
		time ++;
		switch (time)
		{
		case 20:
			
			create(5,0,0);
			create(6,176,0);
			create(8,20,60);
			break;
		case 150:
			create(7,-30,60);
			create(7,-100,60);
			create(7,-170,60);
			
			break;
		case 250:
			create(1,50,-300);
			
			create(3,80,-50);
			create(3,140,-50);
		
			
			break;
		case 350:
			create(1,50,-50);
			create(2,100,-100);
			create(7,80,-200);
			break;
			
		case 450:
			create(8,20,60);
			create(1,150,-50);
			create(2,90,-100);
			create(3,70,-180);
			break;
			
		case 550:
			create(1,100,-50);
			create(2,40,-100);
			
			break;
		case 700:
			create(2,80,-130);
			create(4,70,-200);
			create(6,30,-180);
			time = -50;
			break;
			
	
			
		}
	}
	
	
}

⌨️ 快捷键说明

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