基于J2ME WTK的2D手机游戏开发(英文文献翻译) 第13页
break;
case Tools.LIFT_TYPE:
if (state != JUMP) {
setNextState(WALK);
setNextDir(Tools.LEFT);
}
break;
case Tools.RIGHT_TYPE:
if (state != JUMP) {
setNextState(WALK);
setNextDir(Tools.RIGHT);
}
break;
case Tools.ATTACK_TYPE:
break;
}
}
public void collide(int num) {// 碰撞层判断
switch (num) {
case 13:
switch (state_c) {
case foot_block:
case down_block:
this.setPosition(this.getX(), (this.getY() + getHeight()) / 32
* 32 - this.getHeight());
if (state != WALK) {
this.setNextState(STOP);
}
break;
case up_block:
this.setNextState(JUMP);
vy = 0;
state_c = down_block;
break;
case left_block:
this.setPosition(this.getX(), this.getY());
if (state != JUMP) {
this.setNextState(STOP);
}
break;
case right_block:
this.setPosition((this.getX() + this.getWidth()) / 32 * 32
- this.getWidth() - 3, this.getY());
if (state != JUMP) {
this.setNextState(STOP);
}
break;
}
break;
case 0:
if (state != JUMP && p == 0 && state_c == foot_block) {
this.setNextState(JUMP);
vy = 0;
}
break;
}
}
public int getMap(byte state_c) {// 读取玩家在图层第几块位置
man_x = (this.getX() + this.getWidth() / 2 + 3) / 32;
man_y = (this.getY() + this.getHeight()) / 32;
switch (state_c) {
case up_block:
man_x = (this.getX() + this.getWidth() / 2 + 3) / 32;
man_y = (this.getY() + this.getHeight()) / 32 - 1;
if (man_y < 0) {
man_y = (this.getY() + this.getHeight()) / 32;
}
break;
case down_block:
man_x = (this.getX() + this.getWidth() / 2 + 3) / 32;
man_y = (this.getY() + this.getHeight()) / 32;
if (man_y >= GamePlay.map_hit.getRows()) {// 得到图层中单元格的行数
man_y = GamePlay.map_hit.getRows();
}
break;
case left_block:
man_x = this.getX() / 32 - 1;
man_y = (this.getY() + this.getHeight() / 2) / 32;
if (man_x < 0) {
man_x = this.getX() / 32;
}
break;
case right_block:
man_x = (this.getX() + this.getWidth()) / 32;
man_y = (this.getY() + this.getHeight() / 2) / 32;
if (man_x > GamePlay.map_hit.getColumns()) {// 得到图层中单元格的列数
man_x = this.getX() / 32;
}
break;
case foot_block:
man_y = (this.getY() + this.getHeight()) / 32;
man_x = (this.getX() + this.getWidth() / 2 + 3) / 32;
break;
}
if ((man_y >= 0 && man_y <= GamePlay.map_hit.getRows() - 1)
&& (man_x >= 0 && man_x <= GamePlay.map_hit.getColumns() - 1)) {
return GamePlay.map_hit.getCell(man_x, man_y);
} else {
return -1;
}
}
public void free() {
}
}
Map类
import java.io.DataInputStream;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
public class Map extends TiledLayer {
int[] AIN = new int[6];
byte[][] data = null;
int[] map_num = { 55, 56, 65, 66, 75, 76 };
int aniCounter = 0;
public Map(int cols, int row, Image img, int tiledWidth, int tiledHeight,
int level, int mapIndex) {
super(cols, row, img, tiledWidth, tiledHeight);
readMap(level, mapIndex);
}
public void readMap(int level, int mapIndex) {
byte[][] map = null;
int no = 1;
String fileName = "/map/map" + level + "_" + mapIndex + ".txt";
map = readFile(fileName);
for (int i = 0; i < AIN.length; i++) {
AIN[i] = this.createAnimatedTile(no++);// 第一次的为-1,第二次为-2...
}
getAnimation();
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[0].length; j++) {
setCell(j, i, map[i][j]);
}
}
}
public byte[][] readFile(String URL) {
InputStream is = this.getClass().getResourceAsStream(URL);
DataInputStream data1 = new DataInputStream(is);
short hang = 0;
short lie = 0;
try {
hang = data1.readShort();
lie = data1.readShort();
data = new byte[hang][lie];
for (int i = 0; i < hang; i++) {
for (int j = 0; j < lie; j++) {
data[i][j] = data1.readByte();
}
System.out.println();
}
is.close();
} catch (Exception e) {
}
return data;
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] 下一页
基于J2ME WTK的2D手机游戏开发(英文文献翻译) 第13页下载如图片无法显示或论文不完整,请联系qq752018766