From bcda3f4b2acb70a23548aacabcfa7b8950582d75 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 15 Jul 2011 08:48:30 +0200 Subject: [PATCH] use keycodes as values for direction enum, simplifies the switch --- star.js/js/star.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/star.js/js/star.js b/star.js/js/star.js index f184737..6057b0f 100644 --- a/star.js/js/star.js +++ b/star.js/js/star.js @@ -1,7 +1,7 @@ function initialize_a_star( dom_container, level_index ) { // kinda enums var cell= { WALL: '#', BALL: '@', CUBE: 'H', VOID: ' ', GIFT: 'x' }; - var direction = { UP: 'u', DOWN: 'd', LEFT: 'l', RIGHT: 'r' }; + var direction = { UP: 38, DOWN: 40, LEFT: 37, RIGHT: 39 }; var assets = { sprites: load_sprites( "HP48" ), @@ -273,16 +273,10 @@ function initialize_a_star( dom_container, level_index ) { } else if ( e.type === "keydown" ) { switch( e.keyCode ) { case 38: // UP - state = make_a_move( direction.UP ); - break; case 40: // DOWN - state = make_a_move( direction.DOWN ); - break; case 37: // LEFT - state = make_a_move( direction.LEFT ); - break; case 39: // RIGHT - state = make_a_move( direction.RIGHT ); + state = make_a_move( e.keyCode ); break; case 32: // SPACE state = switch_actor( );