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

📄 mc.java

📁 自己用java写的rpg小游戏....用到了小图拼大地图技术.
💻 JAVA
字号:
import java.io.IOException;

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

public class MC extends Canvas implements Runnable 
{
	Image im;
     PL pl;
	MAP map;
	int[][] pd;
	int cx,cy;
	int []fs;
	boolean u,d,l,r;
	public MC()
	{
		
		try {
			im=Image.createImage( "/player01.png");
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		map=new MAP();
		cx=cy=10;
	
		pd=new int [][]{
				{0 , 0 , 17 , 20 , 9 , 20},
				{17 , 0 , 17 , 20 , 9 , 20},
				{34 , 0 , 17 , 20 , 9 , 20},
				{51 , 0 , 17 , 20 , 9 , 20},
				{0 , 20 , 17 , 20 , 9 , 20},
				{17 , 20 , 17 , 20 , 9 , 20},
				{34 , 20 , 17 , 20 , 9 , 20},
				{0 , 40 , 15 , 19 , 8 , 20},
				{15 , 40 , 15 , 19 , 8 , 20},
				{30 , 40 , 15 , 19 , 8 , 20},
				{45 , 40 , 15 , 19 , 8 , 20},
				{0 , 59 , 16 , 19 , 8 , 20},
				{16 , 59 , 16 , 19 , 8 , 20},
				{32 , 59 , 16 , 19 , 8 , 20},
				{48 , 59 , 16 , 19 , 8 , 20},
				{0 , 78 , 16 , 19 , 8 , 20},
				{16 , 78 , 16 , 19 , 8 , 20},
				{32 , 78 , 16 , 19 , 8 , 20},
		};
		fs=new int[]{1,1,1,1,};
		pl=new PL(im, pd, fs);
		Thread t = new Thread(this) ;
		t.start() ;
		
	}
	protected void paint(Graphics g) 
	{
		g.setColor( 0x000000);
		g.fillRect( 0,0,500,500);
		map.renderDown( g,cx,cy);
		pl.render( g,cx,cy);
		map.renderUp (g,cx,cy);
	
	}
	public void run() 
	{
		while(true)
		{
		   pl.upData( u,d,l,r,this);
		   map.isHitcs( this);
		   
		   
			System.out.println("*"+pl.x+"/"+pl.y+"//"+cx +"//"+cy );
			repaint();
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}

	}
	public void keyPressed(int k)
	{
		if(k==-1)
		{
			u=true;
			
		}
		if(k==-2)
		{
			d=true;
		}
		if(k==-3)
		{
			l=true;
		}
		if(k==-4)
		{
			r=true;
		}
	}
	public void keyReleased(int k)
	{
		if(k==-1)
		{
			u=false;
		}
		if(k==-2)
		{
			d=false;
		}
		if(k==-3)
		{
			l=false;
		}
		if(k==-4)
		{
			r=false;
		}
	}
}

⌨️ 快捷键说明

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