bomb.java
来自「基于J2ME的手机游戏软件。可以控制游戏人物在地图上上下左右行走;可以在地图上放」· Java 代码 · 共 142 行
JAVA
142 行
import javax.microedition.lcdui.Graphics;
public class Bomb
{
private static final int PER_S_CYC = 20;
private int posX;
private int posY;
private int mode;
private int remainCyc;
private World world;
private Sprite sprite;
private boolean blast;
private boolean isShow;
private int width;
private int height;
private boolean across;
private int power;
public Bomb(World world, int x, int y, int power)
{
posX = x;
posY = y;
this.mode = mode;
remainCyc = PER_S_CYC * 2;
this.world = world;
sprite = new Sprite(world.getImageSet(), world.BOMB_STATIC, 0);
blast = false;
isShow = true;
width = 32;
height = 32;
across = true;
this.power = power;
// System.out.println(x + " " + y);
}
public void cycle()
{
remainCyc--;
if (remainCyc <= 0)
{
blast = true;
world.addBlast(posX, posY, power);
}
else
{
blast = false;
}
if (across)
{
int actorWidth = world.getActor().getWidth();
int actorHeight = world.getActor().getHeight();
int ax_1 = world.getActor().getX();
int ay_1 = world.getActor().getY();
int ax_2 = ax_1 + actorWidth - 1;
int ay_2 = ay_1;
int ax_3 = ax_1 + actorWidth - 1;
int ay_3 = ay_1 + actorHeight - 1;
int ax_4 = ax_1;
int ay_4 = ay_1 + actorHeight - 1;
boolean buf_1 = (world.getTileX(ax_1, ay_1) != world.getTileX(posX, posY)
||
world.getTileY(ax_1, ay_1) != world.getTileY(posX, posY));
boolean buf_2 = (world.getTileX(ax_2, ay_2) != world.getTileX(posX, posY)
||
world.getTileY(ax_2, ay_2) != world.getTileY(posX, posY));
boolean buf_3 = (world.getTileX(ax_3, ay_3) != world.getTileX(posX, posY)
||
world.getTileY(ax_3, ay_3) != world.getTileY(posX, posY));
boolean buf_4 = (world.getTileX(ax_4, ay_4) != world.getTileX(posX, posY)
||
world.getTileY(ax_4, ay_4) != world.getTileY(posX, posY));
if (buf_1 && buf_2 && buf_3 && buf_4)
{
across = false;
// System.out.println("false");
}
}
int viewX = world.getViewX();
int viewY = world.getViewY();
if (posX - viewX > world.getViewWidth() + 30
|| posY - viewY > world.getViewHeight() + 30
|| posX < viewX - 30 || posY < viewY - 30)
{
isShow = false;
}
else
{
isShow = true;
}
sprite.cycle();
}
public void render(Graphics gra)
{
if (isShow)
{
sprite.draw(gra, posX - world.getViewX()
, posY - world.getViewY()
, Graphics.TOP | Graphics.LEFT);
gra.setColor(0xff0000);
gra.drawString(remainCyc / PER_S_CYC + "s"
, posX - world.getViewX() + width / 2
, posY - world.getViewY() + height / 2
, Graphics.TOP | Graphics.LEFT);
gra.setColor(0x000000);
gra.drawRect(posX - world.getViewX(), posY - world.getViewY()
, width - 1, height - 1);
}
}
public boolean isBlast()
{
return blast;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getX()
{
return posX;
}
public int getY()
{
return posY;
}
public boolean getAcross()
{
return across;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?