📄 backdrop.java
字号:
package npc7776;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
/******************************************
* 类功能介绍:设置背景及清除屏幕
*****************************************/
public class backdrop {
private static final int[][] map1 = {
{
0, 0, 0, 0, 0, 0, 0, 0}
, {
3, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 1, 2}
, {
6, 0, 0, 0, 0, 0, 4, 5}
, {
6, 0, 0, 0, 0, 0, 7, 8}
, {
6, 0, 0, 0, 0, 0, 0, 0}
, {
9, 0, 0, 0, 1, 2, 3, 0}
, {
0, 0, 0, 0, 4, 5, 6, 0}
, {
0, 0, 0, 0, 7, 8, 9, 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}
, {
3, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 1, 2}
, {
6, 0, 0, 0, 0, 0, 4, 5}
, {
6, 0, 0, 0, 0, 0, 7, 8}
, {
6, 0, 0, 0, 0, 0, 0, 0, }
, {
9, 0, 0, 0, 1, 2, 3, 0}
, {
0, 0, 0, 0, 4, 5, 6, 0}
, {
0, 0, 0, 0, 7, 8, 9, 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}
, {
3, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 0, 0}
, {
6, 0, 0, 0, 0, 0, 1, 2}
, {
6, 0, 0, 0, 0, 0, 4, 5}
, {
6, 0, 0, 0, 0, 0, 7, 8}
, {
6, 0, 0, 0, 0, 0, 0, 0}
, {
9, 0, 0, 0, 0, 0, 0, 0}
, {
0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 1}
};
private static final int TILE_WIDTH = 32; //图片宽
private static final int TILE_HIEGHT = 32; //图片高
private static final int TILE_NUM_COL = 8; //列
private static final int TILE_NUM_ROW = 36; //排
private int[][] currentMap; //地图
private TiledLayer dixing; // 地形
private int groundColor; // 背景颜色
private int screenHeight; // 计算Y 轴
private int dixingScroll; //屏幕Y 位置
public backdrop(int screenHeight) {
this.screenHeight = screenHeight;
try {
setMap(2);
}
catch (Exception e) {}
}
public void setMap(int LeveL) throws Exception {
Image tiledImages = null;
switch (LeveL) {
case 1:
tiledImages = Image.createImage("/res/terrain1.png");
currentMap = map1;
groundColor = 0xF8DDBE;
break;
case 2:
tiledImages = Image.createImage("/res/terrain2.png");
currentMap = map2;
groundColor = 0xF8DDBE;
break;
default:
tiledImages = Image.createImage("/res/terrain1.png");
currentMap = map1;
groundColor = 0xF8DDBE;
break;
}
dixing = new TiledLayer(TILE_NUM_COL, TILE_NUM_ROW, tiledImages, TILE_WIDTH,
TILE_HIEGHT);
for (int row = 0; row < TILE_NUM_ROW; row++) {
for (int col = 0; col < TILE_NUM_COL; col++) {
dixing.setCell(col, row, currentMap[row][col]);
}
}
/* dixingScroll = 1 - dixing.getCellHeight() * dixing.getRows() +
this.screenHeight;
dixing.setPosition(0, dixingScroll); */
dixing.setPosition(0, 0);
}
public void scrollTerrain(Graphics g) {
/*if (dixingScroll < 0) {
dixingScroll += 2;
dixing.setPosition(0, dixingScroll);
dixing.paint(g);
}
else if (dixingScroll == 0) {
dixing.setPosition(0, 0);
dixing.paint(g);
}*/
if (dixingScroll > (this.screenHeight-dixing.getCellHeight()*dixing.getRows()-1)) {
dixingScroll -= 2;
dixing.setPosition(0, dixingScroll);
dixing.paint(g);
}
else if (dixingScroll == (this.screenHeight-dixing.getCellHeight()*dixing.getRows()-1)) {
dixing.setPosition(0, dixingScroll);
dixing.paint(g);
}
}
public TiledLayer getTerrain() {
return dixing;
}
public int getGroundColor() {
return groundColor;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -