
function __d(m)
{
var msgd = new Message('debug');
msgd.print(m + "\n");
}


Function.prototype.bind = function() {
var __method = this, args = $A(arguments), object = args.shift();
return function() {
return __method.apply(object, args.concat($A(arguments)));
}
};
Array.prototype.has = function(value) {
for(var v in this) {
if(this[v] == value) return true;
}
return false;
};
Array.prototype.shuffle = function() {
var i = this.length;
while(i){
var j = Math.floor(Math.random()*i);
var t = this[--i];
this[i] = this[j];
this[j] = t;
}
return this;
};

var $ = function(id) {
return document.getElementById(id);
};
var $A = function(iterable) {
if (!iterable) return [];
if (iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0, length = iterable.length; i < length; i++)
results.push(iterable[i]);
return results;
}
};
Object.extend = function(dst, obj) {
for(var p in obj) dst[p] = obj[p];
};
var $F = function(id) {
var f = $(id);
switch(f.type.toLowerCase()) {
case 'select-one':
return $(id).options[$(id).selectedIndex].value;
break;
}
return null;
};
function alertError()
{
alert('エラーが発生しました。')
}

var Scheduler =
{
tasks: [],
looping: null,
loopCounter: 1,
loop: function()
{
if (Scheduler.tasks.length == 0) {
clearInterval(Scheduler.looping);
Scheduler.looping = null;
Scheduler.loopCounter = 1;
return;
}
var _continuationTasks = [];
while (task = Scheduler.tasks.shift()) {
if (!task.name) continue;
if (Scheduler.loopCounter % task.interval == task.execTime) task.execute();
if(!task.hasFinished) {
_continuationTasks.push(task);
} else {
task.hasFinished = false;
}
if (task.type == Task.TYPE_PRIMARY) {
_continuationTasks = _continuationTasks.concat(Scheduler.tasks);
break;
}
}
Scheduler.tasks = _continuationTasks;
Scheduler.loopCounter++;
},
addTask: function(task)
{
if (!task) return false;
task.execTime = Scheduler.loopCounter % task.interval;
switch (task.type) {
case Task.TYPE_PRIMARY:
var _tasks = [];
var added = false;
while (t = Scheduler.tasks.shift()) {
if (t.type == Task.TYPE_PRIMARY) {
_tasks.push(t);
} else {
_tasks.push(task);
_tasks.push(t);
_tasks = _tasks.concat(Scheduler.tasks);
added = true;
break;
}
}
if(!added) _tasks.push(task);
Scheduler.tasks = _tasks;
break;
case Task.TYPE_UNIQUE:
for (var i = Scheduler.tasks.length - 1; 0 <= i; i--) {
if (Scheduler.tasks[i].type == Task.TYPE_UNIQUE) return false;
}
Scheduler.tasks.push(task);
break;
default:
Scheduler.tasks.push(task);
break;
}
if(!Scheduler.looping) Scheduler.looping = setInterval(Scheduler.loop.bind(this), 10);
return true;
},
removeTask: function(name)
{
if (Scheduler.tasks.length == 0) return;
var tasks = [];
for (var i = 0, l = Scheduler.tasks.length; i < l; i++) {
if (Scheduler.tasks[i].name == name) continue;
tasks.push(Scheduler.tasks[i]);
}
Scheduler.tasks = tasks;
},
clearTasks: function()
{
Scheduler.tasks = [];
}
};
var DOM =
{
show: function(elms)
{
for (i=0, n=elms.length; i < n; i++) {
$(elms[i]).style.display = 'block';
}
},
hide: function(elms)
{
for (i=0, n=elms.length; i < n; i++) {
$(elms[i]).style.display = 'none';
}
}
};
var Dialog =
{
alert: function(msg)
{
var hm = new Message('help_message');
hm.clear();
hm.print(msg);
}
};
var API = function(api, method)
{
this._api    = api;
this._tryNum = 0;
this._json   = null;
this._loaded = false;
this._params = [];
this._method = method;
this._callback  = function(){};
this._eCallback = function(){};
};
API.prototype =
{
setCallback: function(callback)
{
this._callback = callback;
},
setErrorCallback: function(callback)
{
this._eCallback = callback;
},
setParam: function(key, value)
{
if (!key) return;
this._params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
},
request: function()
{
if (!this._api) return;
if(!this._loaded) {
if(this._tryNum < 3) {
this._request();
} else {
this._eCallback();
}
} else {
this._callback(this._json);
}
},
_request: function()
{
if (window.XMLHttpRequest) {
var xobj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
var xobj = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
var xobj = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
return null;
}
xobj.onreadystatechange = (function() {
if (xobj.readyState == 4) {
this._tryNum++;
if (xobj.status == 200) {
eval("this._json = " + xobj.responseText);
this._loaded = true;
} else {
}
this.request();
}
}).bind(this);
var path = '/api/' + this._api + '/';
var body = null;
if (this._params.length != 0) {
var params = this._params.join('&');
if (this._method == 'get') {
path = path + '?' + params;
} else {
body = params;
}
}
xobj.open(this._method, path, true);
if (this._method == 'post') {
xobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
xobj.setRequestHeader('If-Modified-Since', 'Thu, 1 Jun 1970 00:00:00 GMT');
xobj.send(body);
}
};
function keyCodeIs(code, e) {
if(document.all)
return event.keyCode == code;
else if(document.getElementById)
return (e.keyCode != 0) ? e.keyCode == code
: e.charCode == code;
else if(document.layers)
return e.which == code;
}
function getKeyCode(e)
{
if(document.all)
return event.keyCode;
else if(document.getElementById)
return (e.keyCode != 0) ? e.keyCode
: e.charCode;
else if(document.layers)
return e.which;
}
function getClickedCoord(e)
{
if (!e) { e = window.event; }
var x, y;
if (document.all) {
x = e.offsetX;
y = e.offsetY;
} else {
x = e.layerX;
y = e.layerY;
}
return [x,y];
}

var Game =
{
version: '0.30',
data: {},
init: function(data)
{
if (data) Game.data = data;
msg = new Message('game_message_text');
msg.clear();
Display.init();
Field.init(Game.data);
Events.init(Game.data.events);
Player.init({ x : Game.data.init_x, y : Game.data.init_y });
Map.init(Game.data.width, Game.data.height);
Display.renderWalls(Field.getViewData(Player.x, Player.y, Player.d));
Display.setFrontAction('click', function(e)
{
Player.action.click(getClickedCoord(e));
});
Controller.on();
Scheduler.addTask(new Task_Message(msg, 'ダンジョン習作', true));
Scheduler.addTask(new Task_Message(msg, '上下キー：移動　左右キー：方向転換', true));
},
suspend: function()
{
Controller.off();
},
resume: function()
{
Controller.on();
}
};
var Const =
{
D_UP: 0,
D_RIGHT: 1,
D_DOWN: 2,
D_LEFT: 3
};

var Display =
{
width: 320,
height: 240,
container: null,
initialized: false,
init: function()
{
if (Display.initialized) return;
Display.initialized = true;
Display.container = $('game_display');
Display.ceiling = $('game_display_ceiling');
Display.floor = $('game_display_floor');
Display.lf3 = $('game_display_lf3');
Display.c3 = $('game_display_c3');
Display.rf3 = $('game_display_rf3');
Display.ls2 = $('game_display_ls2');
Display.rs2 = $('game_display_rs2');
Display.lf2 = $('game_display_lf2');
Display.c2 = $('game_display_c2');
Display.rf2 = $('game_display_rf2');
Display.ls1 = $('game_display_ls1');
Display.rs1 = $('game_display_rs1');
Display.lf1 = $('game_display_lf1');
Display.c1 = $('game_display_c1');
Display.rf1 = $('game_display_rf1');
Display.ls0 = $('game_display_ls0');
Display.rs0 = $('game_display_rs0');
},
setFrontAction: function(type, f)
{
switch (type) {
case 'click':
$('game_display_front').onclick = f;
break;
}
},
textureSwitcher: 0,
renderWalls: function(data)
{
for (var i = 0; i < data.length; i++) {
switch (i) {
case 0:
Display.lf3.style.display = (data[i]) ? 'block' : 'none';
break;
case 1:
Display.c3.style.display = (data[i]) ? 'block' : 'none';
break;
case 2:
Display.rf3.style.display = (data[i]) ? 'block' : 'none';
break;
case 3:
Display.ls2.style.display = (data[i]) ? 'block' : 'none';
Display.lf2.style.display = (data[i]) ? 'block' : 'none';
break;
case 4:
Display.c2.style.display = (data[i]) ? 'block' : 'none';
break;
case 5:
Display.rs2.style.display = (data[i]) ? 'block' : 'none';
Display.rf2.style.display = (data[i]) ? 'block' : 'none';
break;
case 6:
Display.ls1.style.display = (data[i]) ? 'block' : 'none';
Display.lf1.style.display = (data[i]) ? 'block' : 'none';
break;
case 7:
Display.c1.style.display = (data[i]) ? 'block' : 'none';
break;
case 8:
Display.rs1.style.display = (data[i]) ? 'block' : 'none';
Display.rf1.style.display = (data[i]) ? 'block' : 'none';
break;
case 9:
Display.ls0.style.display = (data[i]) ? 'block' : 'none';
break;
case 10:
Display.rs0.style.display = (data[i]) ? 'block' : 'none';
break;
default:
break;
}
}
if (Display.textureSwitcher == 0) {
Display.ls0.style.backgroundPosition = '-52px 0';
Display.rs0.style.backgroundPosition = '-52px 0';
Display.ls1.style.backgroundPosition = '-54px 0';
Display.rs1.style.backgroundPosition = '-54px 0';
Display.ls2.style.backgroundPosition = '-26px 0';
Display.rs2.style.backgroundPosition = '-26px 0';
Display.ceiling.style.backgroundPosition = '0 -99px';
Display.floor.style.backgroundPosition = '0 -99px';
Display.textureSwitcher = 1;
} else {
Display.ls0.style.backgroundPosition = '0 0';
Display.rs0.style.backgroundPosition = '0 0';
Display.ls1.style.backgroundPosition = '0 0';
Display.rs1.style.backgroundPosition = '0 0';
Display.ls2.style.backgroundPosition = '0 0';
Display.rs2.style.backgroundPosition = '0 0';
Display.ceiling.style.backgroundPosition = '0 0';
Display.floor.style.backgroundPosition = '0 0';
Display.textureSwitcher = 0;
}
}
};
var Controller =
{
up: false,
right: false,
down: false,
left: false,
keyPressed: false,
on: function()
{
document.onkeydown = function(e)
{
if (Controller.keyPressed) return;
Controller.keyPressed = true;
switch (getKeyCode(e)) {
case 38:
Controller.up = true;
break;
case 39:
Controller.right = true;
break;
case 40:
Controller.down = true;
break;
case 37:
Controller.left = true;
break;
}
Scheduler.addTask(new Task_Move());
}
document.onkeyup = function(e)
{
if (!Controller.keyPressed) return;
Controller.up = false;
Controller.right = false;
Controller.down = false;
Controller.left = false;
Scheduler.removeTask('Move');
Controller.keyPressed = false;
}
},
off: function()
{
Scheduler.removeTask('Move');
document.onkeyup = null;
document.onkeydown = null;
}
};
var Field =
{
data: null,
blocks: [],
init: function(data)
{
Field.data   = data;
Field.width  = data.width;
Field.height = data.height;
Field.prepareBlocks(data.blocks);
if (Game.isDemo) {
Field.width    = 20;
Field.height   = 20;
Field.data.map = Field.generateMap(Field.width, Field.height, 2, 1);
}
},
prepareBlocks: function(data)
{
Field.blocks[0] = new Block();
for (var i = 0, l = data.length; i < l; i++) {
var b = new Block(data[i]);
Field.blocks[b.id] = b;
}
},
isWalkable: function(x, y, d)
{
return Field.getNextBlock(x, y, d).isWalkable();
},
getBlock: function(x, y)
{
if (x < 0 || Field.width <= x || y < 0 || Field.height <= y) return Field.blocks[0];
return Field.blocks[Field.data.map[y * Field.height + x]];
},
getNextBlock: function(x, y, d)
{
switch (d) {
case Const.D_UP:
y -= 1;
break;
case Const.D_RIGHT:
x += 1;
break;
case Const.D_DOWN:
y += 1;
break;
case Const.D_LEFT:
x -= 1;
break;
}
return Field.getBlock(x, y);
},
getViewData: function(x, y, d)
{
var data = [];
switch (d) {
case Const.D_UP:
data.push(Field.getBlock(x-1, y-3).hasWall());
data.push(Field.getBlock(x  , y-3).hasWall());
data.push(Field.getBlock(x+1, y-3).hasWall());
data.push(Field.getBlock(x-1, y-2).hasWall());
data.push(Field.getBlock(x  , y-2).hasWall());
data.push(Field.getBlock(x+1, y-2).hasWall());
data.push(Field.getBlock(x-1, y-1).hasWall());
data.push(Field.getBlock(x  , y-1).hasWall());
data.push(Field.getBlock(x+1, y-1).hasWall());
data.push(Field.getBlock(x-1, y).hasWall());
data.push(Field.getBlock(x+1, y).hasWall());
break;
case Const.D_RIGHT:
data.push(Field.getBlock(x+3, y-1).hasWall());
data.push(Field.getBlock(x+3, y  ).hasWall());
data.push(Field.getBlock(x+3, y+1).hasWall());
data.push(Field.getBlock(x+2, y-1).hasWall());
data.push(Field.getBlock(x+2, y  ).hasWall());
data.push(Field.getBlock(x+2, y+1).hasWall());
data.push(Field.getBlock(x+1, y-1).hasWall());
data.push(Field.getBlock(x+1, y  ).hasWall());
data.push(Field.getBlock(x+1, y+1).hasWall());
data.push(Field.getBlock(x  , y-1).hasWall());
data.push(Field.getBlock(x  , y+1).hasWall());
break;
case Const.D_DOWN:
data.push(Field.getBlock(x+1, y+3).hasWall());
data.push(Field.getBlock(x  , y+3).hasWall());
data.push(Field.getBlock(x-1, y+3).hasWall());
data.push(Field.getBlock(x+1, y+2).hasWall());
data.push(Field.getBlock(x  , y+2).hasWall());
data.push(Field.getBlock(x-1, y+2).hasWall());
data.push(Field.getBlock(x+1, y+1).hasWall());
data.push(Field.getBlock(x  , y+1).hasWall());
data.push(Field.getBlock(x-1, y+1).hasWall());
data.push(Field.getBlock(x+1, y).hasWall());
data.push(Field.getBlock(x-1, y).hasWall());
break;
case Const.D_LEFT:
data.push(Field.getBlock(x-3, y+1).hasWall());
data.push(Field.getBlock(x-3, y  ).hasWall());
data.push(Field.getBlock(x-3, y-1).hasWall());
data.push(Field.getBlock(x-2, y+1).hasWall());
data.push(Field.getBlock(x-2, y  ).hasWall());
data.push(Field.getBlock(x-2, y-1).hasWall());
data.push(Field.getBlock(x-1, y+1).hasWall());
data.push(Field.getBlock(x-1, y  ).hasWall());
data.push(Field.getBlock(x-1, y-1).hasWall());
data.push(Field.getBlock(x  , y+1).hasWall());
data.push(Field.getBlock(x  , y-1).hasWall());
break;
}
return data;
},
generateMap: function(width, height, walkableBlockID, notWalkableBlockID)
{
if (width < 3 || height < 3) return [[1,1,1],[1,0,1],[1,1,1]];
var m = new Array(width * height), d = [0,1,2,3], x = 1, y = 1, checked = [];
for (var i = m.length - 1; 0 <= i; i--) m[i] = 1;
function isWall(x,y,d)
{
var _d = d + 2
if(_d > 3) _d -= 4;
if (x < 1 || width - 2 < x || y < 1 || height - 2 < y) return false;
if (m[y * height + x] != 1) return false;
if (_d != Const.D_UP    && m[(y - 1) * height + x] != 1) return false;
if (_d != Const.D_RIGHT && m[y * height + x + 1]   != 1) return false;
if (_d != Const.D_DOWN  && m[(y + 1) * height + x] != 1) return false;
if (_d != Const.D_LEFT  && m[y * height + x - 1]   != 1) return false;
return true;
}
while (true) {
var n = y * height + x;
m[n] = 0;
d.shuffle();
for (var i = 0; i < 4; i++) {
var _x = x;
var _y = y;
switch (d[i]) {
case Const.D_UP:
_y -= 1;
break;
case Const.D_RIGHT:
_x += 1;
break;
case Const.D_DOWN:
_y += 1;
break;
case Const.D_LEFT:
_x -= 1;
break;
}
if (isWall(_x,_y,d[i])) {
x = _x;
y = _y;
break;
}
}
if (i >= 4) {
checked[n] = true;
for (var i = 0; i < 4; i++) {
var _x = x;
var _y = y;
switch (d[i]) {
case Const.D_UP:
_y -= 1;
break;
case Const.D_RIGHT:
_x += 1;
break;
case Const.D_DOWN:
_y += 1;
break;
case Const.D_LEFT:
_x -= 1;
break;
}
var t = _y * height + _x;
if (m[t] == 0 && !checked[t]) {
x = _x;
y = _y;
break;
}
}
if (i >= 4) break;
}
}
for (var i = m.length - 1; 0 <= i; i--) {
m[i] = (m[i] == 0) ? walkableBlockID : notWalkableBlockID;
}
return m;
}
};
var Map =
{
viewer: null,
blocks: [],
player: null,
containerWidth: 320,
containerHeight: 240,
blockWidth: 10,
blockHeight: 10,
init: function(width, height)
{
Map.viewer = $('game_map_viewer');
Map.createBlocks(width, height);
Map.center = Math.round((Map.containerWidth / 2) - (Map.blockWidth / 2));
Map.middle = Math.round((Map.containerHeight / 2) - (Map.blockHeight / 2));
Map.player = $('game_map_player');
Map.player.style.width  = Map.blockWidth  + 'px';
Map.player.style.height = Map.blockHeight + 'px';
Map.player.style.left = Map.center + 'px';
Map.player.style.top  = Map.middle + 'px';
},
createBlocks: function(width, height)
{
Map.viewer.innerHTML = '';
Map.viewer.style.width  = Map.blockWidth * width;
Map.viewer.style.height = Map.blockHeight * height;
Map.blocks = [];
for (var x = 0; x < width; x++) {
if (!Map.blocks[x]) Map.blocks[x] = [];
for (var y = 0; y < height; y++) {
var div = document.createElement('DIV');
div.className    = 'block';
div.style.width  = Map.blockWidth  + 'px';
div.style.height = Map.blockHeight + 'px';
div.style.left   = (x * Map.blockWidth)  + 'px';
div.style.top    = (y * Map.blockHeight) + 'px';
Map.viewer.appendChild(div);
Map.blocks[x][y] = div;
}
}
},
draw: function(x, y, d, type)
{
Map.blocks[x][y].style.backgroundColor = '#FFF';
switch (d) {
case Const.D_UP:
var p = '0 0';
break;
case Const.D_RIGHT:
var p = '-10px 0';
break;
case Const.D_DOWN:
var p = '-20px 0';
break;
case Const.D_LEFT:
var p = '-30px 0';
break;
}
Map.player.style.backgroundPosition = p;
},
focus: function(x, y)
{
Map.viewer.style.left = Map.center - x * Map.blockWidth  + 'px';
Map.viewer.style.top  = Map.middle - y * Map.blockHeight + 'px';
}
};
var Player =
{
x: 0,
y: 0,
d: 0,
light: 0,
dark: 0,
action: null,
init: function(op)
{
Player.x = op.x;
Player.y = op.y;
Player.light = op.light || 50;
Player.dark = op.dark || 50;
Player.updateStatusTable();
Player.action = new Action_Attack_Gun(new Task_Effect_Display_Blink(false,3,'#FFF',1,true));
},
changeDirection: function(d)
{
if (d == Const.D_RIGHT)
Player.d++;
else
Player.d--;
if (Player.d > 3) Player.d = 0;
else if (0 > Player.d) Player.d = 3;
},
move: function(d)
{
switch (d) {
case Const.D_UP:
Player.y -= 1;
break;
case Const.D_RIGHT:
Player.x += 1;
break;
case Const.D_DOWN:
Player.y += 1;
break;
case Const.D_LEFT:
Player.x -= 1;
break;
}
},
incrementPower: function(type, v)
{
if (!v) v = 1;
if (type == 'light') {
Player.light += v;
Player.dark -= v;
} else {
Player.light -= v;
Player.dark += v;
}
if (Player.light > 100 || Player.dark < 0) {
Player.light = 100;
Player.dark = 0;
}
if (Player.dark > 100 || Player.light < 0) {
Player.light = 0;
Player.dark = 100;
}
},
updateStatusTable: function()
{
var lv = $('game_player_light_value');
lv.style.width = Player.light + '%';
lv.innerHTML = Player.light;
var dv = $('game_player_dark_value');
dv.style.width = Player.dark + '%';
dv.innerHTML = Player.dark;
}
};
var Events =
{
progs: {},
init: function(e)
{
if (e != '') {
eval('var e = ' + e.replace(/\n/g, '\\n'));
if (e) {
for (var i = 0, n = e.length; i < n; i++) {
var c = e[i].x + ',' + e[i].y;
Events.progs[c] = new Program(e[i].x, e[i].y, e[i].c, e[i].s);
}
}
} else {
Events.progs = {};
}
},
check: function(x, y, c)
{
if (Events.exists(x, y)) {
Events.get(x, y).run(c);
}
},
exists: function(x, y)
{
return (Events.progs[(x + ',' + y)]) ? true : false;
},
get: function(x, y)
{
return (Events.progs[(x + ',' + y)]) ? Events.progs[(x + ',' + y)] : null;
}
};
var Program = function(x, y, c, s) {
this.x = x;
this.y = y;
this.cond = c;
this.script = s;
}
Program.COND_ONOVER    = 1;
Program.COND_ONOUT     = 2;
Program.COND_ONCHECK_U = 4;
Program.COND_ONCHECK_R = 8;
Program.COND_ONCHECK_D = 16;
Program.COND_ONCHECK_L = 32;
Program.COND_ONCHECK_I = 64;
Program.prototype =
{
run: function(c)
{
if (this.cond & c) {
this.parse();
}
},
parse: function()
{
var rows = this.script.split("\n");
while (rows.length) {
var row = rows.shift();
if (!row.match(/^(\S+)/)) continue;
var directive = RegExp.$1.toLowerCase();
row = row.replace(/\s+/g, ' ');
switch (directive) {
case 'e':
this.effect(row);
break;
default:
this.msg(row);
break;
}
}
},


msg: function(d)
{
Scheduler.addTask(new Task_Message(msg, d, true));
},

effect: function(d)
{
d = d.split(' ');
d.shift();
switch (d[0]) {
case 'spread':
Scheduler.addTask(new Task_Effect_Display_Spread(40,40,'',1));
break;
case 'stripe':
Scheduler.addTask(new Task_Effect_Display_Stripe('row','random','random',2));
break;
case 'blink':
Scheduler.addTask(new Task_Effect_Display_Blink(false,15,'#FFF',1));
break;
}
}
};

var Message = function(container) {
this.container = $(container);
}
Message.prototype =
{
print: function(msg, br)
{
if(br) msg += "\n";
this.container.value += msg;
},
clear: function(id)
{
this.container.value = '';
}
};

var Block = function(data) {
if (data) {
this.id       = data[0];
this.name     = data[1];
this.walkable = data[2];
this.wall     = data[3];
}
};
Block.prototype =
{
id       : 0,
name     : 'blackhole',
walkable : false,
wall     : false,
isWalkable: function()
{
return this.walkable;
},
hasWall: function()
{
return this.wall;
},
fireEvent: function()
{
}
};
var Task = function() {};
Task.TYPE_NORMAL = 0;
Task.TYPE_PRIMARY = 1;
Task.TYPE_UNIQUE = 2;
Task.prototype =
{
hasFinished: false,
name: '',
type: Task.TYPE_NORMAL,
interval: 1,
execute: function()
{
this.finish();
},
remove: function()
{
},
finish: function()
{
this.hasFinished = true;
}
};var Task_Move = function() {};
Task_Move.prototype = new Task;
Object.extend(Task_Move.prototype, {
name: 'Move',
type: Task.TYPE_UNIQUE,
interval: 15,
execute: function()
{
var _draw = false;
if(Controller.up) {
if (Field.isWalkable(Player.x, Player.y, Player.d)) {
Events.check(Player.x, Player.y, Program.COND_ONOUT);
Player.move(Player.d);
Events.check(Player.x, Player.y, Program.COND_ONOVER);
_draw = true;
}
} else if(Controller.right) {
Player.changeDirection(Const.D_RIGHT);
_draw = true;
} else if(Controller.down) {
var d = Player.d + 2
if(d > 3) d -= 4;
if (Field.isWalkable(Player.x, Player.y, d)) {
Events.check(Player.x, Player.y, Program.COND_ONOUT);
Player.move(d);
Events.check(Player.x, Player.y, Program.COND_ONOVER);
_draw = true;
}
} else if(Controller.left) {
Player.changeDirection(Const.D_LEFT);
_draw = true;
}
if(_draw) {
Display.renderWalls(Field.getViewData(Player.x, Player.y, Player.d));
Map.draw(Player.x, Player.y, Player.d);
Map.focus(Player.x, Player.y);
}
}
});
var Task_Message = function(target, msg, spl, no_br) {
this.target = target;
this.msg    = (spl)    ? msg.split('') : [msg];
this.br     = (no_br)  ? false  : true;
};
Task_Message.prototype = new Task;
Object.extend(Task_Message.prototype, {
name: 'Message',
type: Task.TYPE_PRIMARY,
interval: 1,
execute: function()
{
var msg = this.msg.shift();
this.target.print(msg);
if (this.msg.length <= 0) {
if (this.br) this.target.print("\n");
this.finish();
}
}
});
var Task_Effect_Display_Spread = function(width, height, type, speed) {
var e = document.createElement('DIV');
e.id = 'effect_display_spread';
e.style.position = 'absolute';
e.style.left = '0';
e.style.top = '0';
this.p = [];
for (var y = 0, h = Display.height / height; y < h; y++) {
for (var x = 0, w = Display.width / width; x < w; x++) {
var b = document.createElement('DIV');
b.style.display = 'none';
b.style.backgroundColor  = '#000';
b.style.position  = 'absolute';
b.style.width  = width  + 'px';
b.style.height = height + 'px';
b.style.left   = (x * width)  + 'px';
b.style.top    = (y * height) + 'px';
e.appendChild(b);
this.p.push(b);
}
}
Display.container.appendChild(e);
switch (type) {
case 'random':
this.p.shuffle();
break;
case 'reverse':
this.p.reverse();
break;
default:
break;
}
this.interval = speed;
};
Task_Effect_Display_Spread.prototype = new Task;
Object.extend(Task_Effect_Display_Spread.prototype, {
name: 'Effect_Display_Spread',
type: Task.TYPE_PRIMARY,
interval: 2,

execute: function()
{
var b = this.p.shift();
if (!b) {
this.finish();
return;
}
b.style.display = 'block';
}
});

var Task_Effect_Display_Stripe = function(d, type, size, speed) {
var e = document.createElement('DIV');
e.id = 'effect_display_stripe';
e.style.position = 'absolute';
e.style.left = '0';
e.style.top = '0';
this.p = [];
if (d == 'row') {
var max = Display.width;
var fix = Display.height;
} else {
var max = Display.height;
var fix = Display.width;
}
var l = 0;
while (l < max) {
var r = (size == 'random') ? parseInt(Math.random() * 20 + 5) : size;
var b = document.createElement('DIV');
b.style.display = 'none';
b.style.backgroundColor  = '#000';
b.style.position  = 'absolute';
if (d == 'row') {
b.style.width  = r  + 'px';
b.style.height = fix + 'px';
b.style.left   = l  + 'px';
b.style.top    = '0px';
} else {
b.style.width  = fix  + 'px';
b.style.height = r + 'px';
b.style.left   = '0px';
b.style.top    = l  + 'px';
}
e.appendChild(b);
this.p.push(b);
l += r;
}
Display.container.appendChild(e);
switch (type) {
case 'random':
this.p.shuffle();
break;
case 'reverse':
this.p.reverse();
break;
default:
break;
}
this.interval = speed;
};
Task_Effect_Display_Stripe.prototype = new Task;
Object.extend(Task_Effect_Display_Stripe.prototype, {
name: 'Effect_Display_Stripe',
type: Task.TYPE_PRIMARY,
interval: 2,

execute: function()
{
var b = this.p.shift();
if (!b) {
this.finish();
return;
}
b.style.display = 'block';
}
});

var Task_Effect_Display_Blink = function(smooth, n, color, speed, noPri) {
var e = document.createElement('DIV');
e.id = 'effect_display_blink';
e.style.position = 'absolute';
e.style.width    = Display.width + 'px';
e.style.height   = Display.height + 'px';
e.style.left     = '0';
e.style.top      = '0';
e.style.display  = 'none';
e.style.backgroundColor = color || '#FFF';
Display.container.appendChild(e);
this.interval = speed || 2;
this.elm    = e;
this.n      = n;
this.smooth = smooth;
if (noPri) {
this.type = Task.TYPE_NORMAL;
}
};
Task_Effect_Display_Blink.prototype = new Task;
Object.extend(Task_Effect_Display_Blink.prototype, {
name: 'Effect_Display_Blink',
type: Task.TYPE_PRIMARY,
interval: 2,
finish: function()
{

this.i = 1;
this.hasFinished = true;
},
i: 1,
execute: function()
{
if (this.smooth) {
} else {
this.elm.style.display = (this.i % 2) ? 'block' : 'none';
}
if (this.i > this.n) {
this.finish();
return;
}
this.i++;
}
});

var Action = function() {};
Action.prototype =
{
click: function(c)
{
__d('noop')
},
dblclick: function(c)
{
},
mousedown: function(c)
{
},
mouseup: function(c)
{
},
mouseover: function(c)
{
},
mouseout: function(c)
{
}
};var Action_Attack_Gun = function(hitTask) {
this.hitTask = hitTask;
};
Action_Attack_Gun.prototype = new Action;
Object.extend(Action_Attack_Gun.prototype, {
click: function(c)
{
Player.incrementPower('dark');
Player.updateStatusTable();
Scheduler.addTask(this.hitTask);
}
});
function boot(mode)
{
__d('Game version:' + Game.version);
if (mode == 'edit') {
E_Panel.init();
} else {
Game.isDemo = true;
var api = new API('data', 'get');
api.setParam('id', 1);
api.setCallback(Game.init);
api.request();
$('game').style.display = 'block';
}
}
/*@cc_on _d=document;eval('var document=_d')@*/

