UNPKG

lettuce

Version:

Lettuce JS, Mini Mobile Framework for Romantic with DSL.

49 lines (38 loc) 1.06 kB
game.PlayScreen = me.ScreenObject.extend({ /** * action to perform on state change */ onResetEvent: function() { // load a level me.levelDirector.loadLevel("village"); // subscribe to key down event this.handle = me.event.subscribe(me.event.KEYDOWN, this.keyPressed.bind(this)); }, /** * update function */ keyPressed: function (action, keyCode, edge) { // navigate the map :) if (action == 'left') { me.game.viewport.move(-(me.game.currentLevel.tilewidth/2),0); } else if (action == 'right') { me.game.viewport.move(me.game.currentLevel.tilewidth/2,0); } if (action === 'up') { me.game.viewport.move(0,-(me.game.currentLevel.tileheight/2)); } else if (action === 'down') { me.game.viewport.move(0,me.game.currentLevel.tileheight/2); } if (action === 'enter') { me.game.viewport.shake(16, 500); } // force redraw me.game.repaint(); }, /** * action to perform when leaving this screen (state change) */ onDestroyEvent: function() { me.event.unsubscribe(this.handle); } });