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

📄 wj.java

📁 坦克大战类游戏实现坦克的基本功能控制坦克地图行走
💻 JAVA
字号:
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class WJ extends Sprite 
{int m;
	public WJ(Image im,int w,int h,int x,int y,int[]a)
	{
		super(im,w,h);
		this.setFrameSequence(a);
		this.setPosition(x,y);
	}
	public void move(boolean u,boolean d,boolean l,boolean r,BJ bj,BJ bj2,MC mc)
	{
	
		this.nextFrame();
		if(u==true)
		{  
			this.move(0,-5);
			if(this.collidesWith(bj,true)==true||this.collidesWith(bj2,true)==true)
			{
				this.move(0,5);
			}
			if(this.getY()-mc.cy<100)
			{
				mc.cy-=5;
				if(mc.cy<0)
				{
					mc.cy=0;
				}
			}
		}
		
		if(d==true)
		{
		
			this.move(0,5);
			if(this.collidesWith(bj,true)==true||this.collidesWith(bj2,true)==true)
			{
				this.move(0,-5);
			}
			if(this.getY()-mc.cy>220)
			{
				mc.cy+=5;
				if(mc.cy>250)
				{
					mc.cy=250;
				}
			}
		}
		
		if(l==true)
		{
			
			this.move(-5,0);
			if(this.collidesWith(bj,true)==true||this.collidesWith(bj2,true)==true)
			{
				this.move(5,0);
			}
			if(this.getX()-mc.cx<40)
			{
				mc.cx-=5;
				if(mc.cx<0)
				{
					mc.cx=0;
				}
			}
		}
		
		if(r==true)
		{
			
			this.move(5,0);
			if(this.collidesWith(bj,true)==true||this.collidesWith(bj2,true)==true)
			{
				this.move(-5,0);
			}
			if(this.getX()-mc.cx>100)
			{
				mc.cx+=5;
				if(mc.cx>340)
				{
					mc.cx=340;
				}
			}
		}
		
//		System.out.println("cx="+mc.cx+"cy="+mc.cy);
		
	}

}

⌨️ 快捷键说明

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