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

📄 resourse.java

📁 一个RPG游戏的DEMO.用到了脚本技术。图片也有封装过。
💻 JAVA
字号:
import java.io.InputStream;

import javax.microedition.lcdui.Image;

class Resourse
{
	public static final int ROOM=15602;
	public static final int GROUND=21046;
	public static final int MAINCHAR=13944;
	public static final int ITEMS=10213;
	public static final int ITEM=8556;
	public static final int ATTENTION=13680;
	public static final int ENEMY=2600;
	public static final int ENEMY2=0;
	public static final int HEAL=4712;
	public static final int FACE=7913;
	public static final int ATTACK=5436;
	public static final int BATTLE=11032;
	public static final int TARGET=13185;
	private static final Resourse self=new Resourse();
	
	private Resourse(){}
	
	 public static Image readImage(int pos)
	 {
	  byte buffer[];
	  int len;
	  try {
	   InputStream is = self.getClass().getResourceAsStream("/image.bin");
	   
	   is.skip(pos);
	   
	   len  = (is.read() & 0xFF) << 24;
	   len  |= (is.read() & 0xFF) << 16;
	   len  |= (is.read() & 0xFF) << 8;
	   len  |= (is.read() & 0xFF);

	   buffer = new byte[len];
	  
	   is.read(buffer, 0, buffer.length);

	   is.close();
	   is = null;
	  
	   System.gc();
	  } catch (Exception e) {
	   buffer = null;
	   e.printStackTrace();
	   System.gc();
	   return null;
	  }
	  return Image.createImage(buffer, 0, buffer.length);
	 }
	 
	 public static int[][] readMap(int mapId)
	 {
	 	byte buffer[]=null;
	 	int map[][]=new int[10][10];
	 	try {
	 	   InputStream is = self.getClass().getResourceAsStream("/map");
	 	   is.skip(mapId*300);
	 	   buffer = new byte[300];
	 	   is.read(buffer, 0 , buffer.length);
	 	   is.close();
	 	   is = null;
	 	   System.gc();
	 	  } catch (Exception e) {
	 	   buffer = null;
		   e.printStackTrace();
		   System.gc();
		   return null;
		   }
	 	int count=0;
	 	for(int i=0;i<10;i++)
	 	{
	 		for(int j=0;j<10;j++)
	 		{
	 			map[j][i]=(int)(buffer[count]-48)*100+(int)(buffer[count+1]-48)*10+(int)(buffer[count+2]-48);
	 			count+=3;
	 		}
	 	}
	 	return map;
	 }
	 
	 public static int[] getEnemy(int kind)
	 {
	 	int s[]=new int[7];
	 	byte buffer[]=null;
	 	try {
		 	   InputStream is = self.getClass().getResourceAsStream("/enemy");
		 	   is.skip(kind*21);
		 	   buffer = new byte[23];
		 	   is.read(buffer, 0 , buffer.length);
		 	   is.close();
		 	   is = null;
		 	   System.gc();
		 	  } catch (Exception e) {
		 	   buffer = null;
			   e.printStackTrace();
			   System.gc();
			   return null;
			   }
		for(int i=0;i<7;i++)
			s[i]=(int)(buffer[3*i]-48)*100+(int)(buffer[3*i+1]-48)*10+(int)(buffer[3*i+2]-48);
	 	return s;
	 }
	 
	 public static int[] levelUp(int level)
	 {
	 	int s[]=new int[8];
	 	byte buffer[]=null;
	 	try {
		 	   InputStream is = self.getClass().getResourceAsStream("/level");
		 	   is.skip(level*23);
		 	   buffer = new byte[23];
		 	   is.read(buffer, 0 , buffer.length);
		 	   is.close();
		 	   is = null;
		 	   System.gc();
		 	  } catch (Exception e) {
		 	   buffer = null;
			   e.printStackTrace();
			   System.gc();
			   return null;
			   }
		s[0]=(int)(buffer[0]-48)*100+(int)(buffer[1]-48)*10+(int)(buffer[2]-48);//maxhp
		s[1]=(int)(buffer[3]-48)*100+(int)(buffer[4]-48)*10+(int)(buffer[5]-48);//maxmp
		s[2]=(int)(buffer[6]-48)*100+(int)(buffer[7]-48)*10+(int)(buffer[8]-48);//str
		s[3]=(int)(buffer[9]-48)*100+(int)(buffer[10]-48)*10+(int)(buffer[11]-48);//dex
		s[4]=(int)(buffer[12]-48)*100+(int)(buffer[13]-48)*10+(int)(buffer[14]-48);//spd
		s[5]=(int)(buffer[15]-48)*100+(int)(buffer[16]-48)*10+(int)(buffer[17]-48);//mag
		s[6]=(int)(buffer[18]-48)*1000+(int)(buffer[19]-48)*100+(int)(buffer[20]-48)*10+(int)(buffer[21]-48);//nextexp
		s[7]=(int)(buffer[22]-48);//sp
	 	return s;
	 }
}

⌨️ 快捷键说明

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