基于J2ME的手机游戏软件。可以控制游戏人物在地图上上下左右行走;可以在地图上放置一颗炸弹

源代码在线查看: prop.java

软件大小: 684 K
上传用户: a1a1J0
关键词: J2ME 地图 手机游戏 软件
下载地址: 免注册下载 普通下载 VIP

相关代码

				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;
				  }
				}
							

相关资源