2014年2月23日 星期日

【Java分享】怪物不穿門

文章出處:浪漫物語網路社區  作者:faraki 


主要是isPassable少了對door的辨識...

L1V1Map.java
搜尋public boolean isPassable(int x, int y, int heading) {

==============原始=====================
if (heading == 0) {
tile2 = accessTile(x, y - 1);
}
else if (heading == 1) {
tile2 = accessTile(x + 1, y - 1);
}
else if (heading == 2) {
tile2 = accessTile(x + 1, y);
newX = x + 1;
newY = y;
}
else if (heading == 3) {
tile2 = accessTile(x + 1, y + 1);
newX = x + 1;
newY = y + 1;
}
else if (heading == 4) {
tile2 = accessTile(x, y + 1);
}
else if (heading == 5) {
tile2 = accessTile(x - 1, y + 1);
}
else if (heading == 6) {
tile2 = accessTile(x - 1, y);
}
else if (heading == 7) {
tile2 = accessTile(x - 1, y - 1);
}
else {
return false;
}
==============替換以下===================
int newX;
int newY;

if (heading == 0) {
tile2 = accessTile(x, y - 1);
newX = x;
newY = y - 1;
}
else if (heading == 1) {
tile2 = accessTile(x + 1, y - 1);
newX = x + 1;
newY = y - 1;
}
else if (heading == 2) {
tile2 = accessTile(x + 1, y);
newX = x + 1;
newY = y;
}
else if (heading == 3) {
tile2 = accessTile(x + 1, y + 1);
newX = x + 1;
newY = y + 1;
}
else if (heading == 4) {
tile2 = accessTile(x, y + 1);
newX = x;
newY = y + 1;
}
else if (heading == 5) {
tile2 = accessTile(x - 1, y + 1);
newX = x - 1;
newY = y + 1;
}
else if (heading == 6) {
tile2 = accessTile(x - 1, y);
newX = x - 1;
newY = y;
}
else if (heading == 7) {
tile2 = accessTile(x - 1, y - 1);
newX = x - 1;
newY = y - 1;
}
else {
return false;
}

if (isExistDoor(newX, newY)) {
return false;
}

==============完畢=====================

沒有留言:

張貼留言