private MicroTankSprite createTank() throws IOException
{
Image image = Image.createImage("/tank.png");
return new MicroTankSprite(image, 32, 32);
}
private TiledLayer createBoard() throws IOException
{
Image image = Image.createImage("/board.png");
TiledLayer tiledLayer = new TiledLayer(10, 10, image, 16, 16);
int[] map = { 1, 1, 1, 1, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 0, 1,
1, 1, 1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 11, 0, 0, 0,
0, 0, 0, 0, 7, 6, 0, 0, 0, 0, 0, 0, 0, 7, 6, 0, 0, 0 };
for (int i = 0; i < map.length; i++)
{
int column = i % 10;
int row = (i - column) / 10;
tiledLayer.setCell(column, row, map[i]);
}
return tiledLayer;
}
public void start()
{
mTrucking = true;
Thread t = new Thread(this);
t.start();
}
public void run()
{
Graphics g = getGraphics();
int timeStep = 80;
while (mTrucking)
{
long start = System.currentTimeMillis();
tick();
input();
render(g);
long end = System.currentTimeMillis();
int duration = (int) (end - start);
if (duration < timeStep)
{
try
{
Thread.sleep(timeStep - duration);
} catch (InterruptedException ie)
{
stop();
}
}
}
}
private void tick()
{
if (mTank.collidesWith(mBoard, true))
mTank.undo();
}