prop.java~1~

来自「基于J2ME的手机游戏软件。可以控制游戏人物在地图上上下左右行走;可以在地图上放」· JAVA~1~ 代码 · 共 141 行

JAVA~1~
141
字号
import javax.microedition.lcdui.Graphics;
public class Prop 
{
	public static final int REMAIN_CYC = 100;
	public static final int FLASH_CYC = 30;
	
	private int posX;
	private int posY;
	private int remainCyc;
	private int model;
	private ImageSet imageSet;
	private World world;
	private boolean isShow;
	private boolean isExist;
	private boolean flash;
	private int clock;
	
	public Prop(World world,int x,int y,int model)
	{
		this.world = world;
		imageSet = world.getImageSet();
		init(x,y,model);
	}
	
	public void init(int x,int y,int model)
	{
		posX = x;
		posY = y;
		this.model = model;
		remainCyc = REMAIN_CYC;
		isShow = true;
		isExist = true;
		flash = false;
		clock = 0;
	}
	
	public void render(Graphics gra)
	{
		if(isShow && isExist)
		{
			if(remainCyc < FLASH_CYC)
			{
				clock++;
				if(clock > 3)
				{
					flash = !flash;
					clock = 0;
				}
			}
			if(remainCyc >= FLASH_CYC || flash)
			{
				switch(model)
				{
					case World.PROP_TYPE_STAR:
						imageSet.draw(gra,World.PROP_STAR,0,posX - world.getViewX()
													,posY - world.getViewY()
													,Graphics.TOP|Graphics.LEFT);
						break;
					case World.PROP_TYPE_MONEY:
						imageSet.draw(gra,World.PROP_MONEY,0,posX - world.getViewX()
													,posY - world.getViewY()
													,Graphics.TOP|Graphics.LEFT);
						break;
					case World.PROP_TYPE_LIGHTING:
						imageSet.draw(gra,World.PROP_LIGHTING,0,posX - world.getViewX()
													,posY - world.getViewY()
													,Graphics.TOP|Graphics.LEFT);
						break;
					case World.PROP_TYPE_LIFE:
						imageSet.draw(gra,World.PROP_LIFE,0,posX - world.getViewX()
													,posY - world.getViewY()
													,Graphics.TOP|Graphics.LEFT);
						break;
				}
			}
		}
	}
	
	public void cycle()
	{
		remainCyc--;
		if(remainCyc < 0)
		{
			isExist = false;
		}
		if(posX - world.getViewX() > world.getViewWidth() +30
			|| posX < world.getViewX() - 30
			|| posY - world.getViewY() > world.getViewHeight() + 30
			|| posY < world.getViewY() - 30)
		{
			isShow = false;
		}
		else 
		{
			isShow = true;
		}
	}
	
	public void action()
	{
		if(isExist == true)
		{
			isExist = false;
			switch(model)
			{
				case World.PROP_TYPE_STAR:
					world.getActor().addBombNum();
					break;
				case World.PROP_TYPE_MONEY:
					world.addScore(1000);
					break;
				case World.PROP_TYPE_LIGHTING:
					world.getActor().addPower();
					break;
				case World.PROP_TYPE_LIFE:
					world.addPlayerLife();
					break;
			}
		}
	}
	
	public boolean isExist()
	{
		return isExist;
	}
	
	public boolean isShow()
	{
		return isShow;
	}
	
	public int getX()
	{
		return posX;
	}
	
	public int getY()
	{
		return posY;
	}
}

⌨️ 快捷键说明

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