📄 barrier.java
字号:
/**
* <p>Title: DemoVader</p>
* <p>Description: .</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Symbian Ltd</p>
* @author Alan Newman - alan@sensibledevelopment.net
* @version 1.0
*/
import javax.microedition.lcdui.*;
public class Barrier{
protected static int cols=2;
int[][] imageMap;
Image[] imageFrames;
Image image;
int imageWidth;
int imageHeight;
int tileWidth;
int tileHeight;
int canvasWidth;
int canvasHeight;
protected static final int RAW_FRAMES=1;
protected static final String IMAGE_NAME="barrier";
protected int xPos;
protected int yPos;
public Barrier(int canvasWidth, int canvasHeight)
{
imageFrames=VaderManager.getFrames(IMAGE_NAME, RAW_FRAMES);
this.canvasHeight=canvasHeight;
this.canvasWidth=canvasWidth;
setImage(createImage());
}
public static int getCols() {return cols;}
public int getHeight() {return imageHeight;}
public int getWidth() {return imageWidth;}
public int getTileHeight() {return tileHeight;}
public int getTileWidth() {return tileWidth;}
public int getCanvasHeight() {return canvasHeight;}
public int getCanvasWidth() {return canvasWidth;}
public Image getImage() {return image;}
private void setX(int x) {xPos=x;}
private void setY(int y) {yPos=y;}
public int getX() {return xPos;}
public int getY() {return yPos;}
public void setImage(Image img) {image=img;}
//public void setY(int y) {setPosition(getX(), getY()+y);}
private void setCell(int col, int row, int value)
{
imageMap[col][row]=value;
}
public void setPosition(int x, int y)
{
setX(x);
setY(y);
}
private Image createImage()
{
// allocate memory to store the onscreen background image.
// assuming all tiles are the same size, make the buffer
// the screen size plus one row and column.
// make assumption that all frame dimensions are equal.
this.tileWidth=imageFrames[0].getWidth();
this.tileHeight=imageFrames[0].getHeight();
int columns=(int)(canvasWidth/4/tileWidth)+1;
int rows=20;
imageWidth=columns*tileWidth;
imageHeight=rows*tileHeight;
image=Image.createImage(getWidth(), getHeight());
imageMap = new int[columns][rows];
int tiles=columns*rows;
for (int i = 0; i < tiles; i++)
{
int c = i % columns;
int r = (i - c) / columns;
setCell(c, r, 0);
}
return setTileImages(image, columns, rows);
}
private Image setTileImages(Image image, int columns, int rows)
{
Graphics g = image.getGraphics();
int tiles=columns*rows;
for (int i = 0; i < tiles; i++)
{
int c = i % columns;
int r = (i - c) / columns;
g.drawImage(imageFrames[imageMap[c][r]],c*getTileHeight(),r*getTileWidth(),g.LEFT | g.TOP);
}
return image;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -