Mercurial > qqw
changeset 52:3aa372c789a6
Update js, move the map key into the map
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 16 Feb 2013 18:01:44 +0100 |
| parents | 4af42930a7c9 |
| children | 8a73f8cdbba1 |
| files | dw.js |
| diffstat | 1 files changed, 24 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.js Sat Feb 16 17:58:03 2013 +0100 +++ b/dw.js Sat Feb 16 18:01:44 2013 +0100 @@ -1,115 +1,16 @@ var Game = function () { var module = {}; module.baseurl = baseurl || ''; module.key = map_key || { - ' ': { - 'block': true, - 'wall': true, - }, - ':': { - 'tileset': "wall.png", - 'tile_x': 0, - 'tile_y': 3, - }, - '`': { - 'tileset': "wall.png", - 'tile_x': 2, - 'tile_y': 3, - }, - 'W': { - 'block': true, - 'wall': 'W', - 'tileset': "wall.png", - }, - 'X': { - 'block': true, - 'wall': 'X', - 'tileset': "ground.png", - }, - '.': { - 'tileset': "ground.png", - 'tile_x': 0, - 'tile_y': 3, - }, - ',': { - 'tileset': "ground.png", - 'tile_x': 1, - 'tile_y': 3, - }, - ';': { - 'tileset': "ground.png", - 'tile_x': 2, - 'tile_y': 3, - }, - '"': { - 'tileset': "ground.png", - 'tile_x': 3, - 'tile_y': 3, - }, - '=': { - 'tileset': "ground.png", - 'tile_x': 1, - 'tile_y': 1, - }, - '0': { - 'tileset': "ground.png", - 'tile_x': 0, - 'tile_y': 3, - }, - '1': { - 'tileset': "wall.png", - 'tile_x': 3, - 'tile_y': 3, - 'url': 'map.html' - }, - '2': { - 'tile': ':', - 'sprite': "ladder.png", - 'url': 'index.html#3', - }, - '3': { - 'tileset': "wall.png", - 'tile_x': 1, - 'tile_y': 3, - 'url': 'map.html#2', - }, - 'S': { - 'tile': '.', - 'block': true, - 'sprite': "skeleton.png", - }, - 'B': { - 'tile': '.', - 'block': true, - 'sprite': "boy.png", - 'message': 'Welcome!', - }, - 'Z': { - 'tile': ':', - 'block': true, - 'sprite': "zombie.png", - }, - 'x': { - 'tile': '=', - 'block': true, - 'sprite': "caution.png", - 'message': 'Beware of the undead!', - }, - 'b': { - 'tile': ':', - 'sprite': "box.png", - 'block': true, - }, - 'h': { - 'tile': ':', - 'sprite': "hammer.png", - }, - 'l': { - 'tile': 'W', - 'sprite': "light.png", - 'block': true, - 'noshadow': true, - wall: 'W', - }, + ' ': { 'block': true, 'wall': true, }, + ':': { 'tileset': "wall.png", 'tile_x': 0, 'tile_y': 3, + }, '`': { 'tileset': "wall.png", 'tile_x': 2, 'tile_y': 3, }, + 'W': { 'block': true, 'wall': 'W', 'tileset': "wall.png", }, + 'X': { 'block': true, 'wall': 'X', 'tileset': "ground.png", }, + '.': { 'tileset': "ground.png", 'tile_x': 0, 'tile_y': 3, }, + ',': { 'tileset': "ground.png", 'tile_x': 1, 'tile_y': 3, }, + ';': { 'tileset': "ground.png", 'tile_x': 2, 'tile_y': 3, }, + '"': { 'tileset': "ground.png", 'tile_x': 3, 'tile_y': 3, }, + '=': { 'tileset': "ground.png", 'tile_x': 1, 'tile_y': 1, }, }; @@ -432,9 +333,20 @@ return false; }; + module.loop = function () { + // The main game loop. + + module.player.control(); + for (var i=0; i<module.sprites.length; ++i) { + var sprite = module.sprites[i]; + sprite.update(); + } + setTimeout(module.loop, 50); + }; + module.init = function () { - document.onkeydown = module.keydown; - document.onkeyup = module.keyup; + window.onkeydown = module.keydown; + window.onkeyup = module.keyup; module.sprites = []; module.field = module.Field(); module.field.redraw(); @@ -447,15 +359,6 @@ y = pos[1]; } module.player = module.Player(x, y); - setInterval(function () { - // The main game loop. - - module.player.control(); - for (var i=0; i<module.sprites.length; ++i) { - var sprite = module.sprites[i]; - sprite.update(); - } - }, 50); }; module.init(); @@ -464,5 +367,5 @@ }; -Game() +Game().loop();
