mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
use keycodes as values for direction enum, simplifies the switch
This commit is contained in:
parent
2bd110a87b
commit
bcda3f4b2a
1 changed files with 2 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
function initialize_a_star( dom_container, level_index ) {
|
function initialize_a_star( dom_container, level_index ) {
|
||||||
// kinda enums
|
// kinda enums
|
||||||
var cell= { WALL: '#', BALL: '@', CUBE: 'H', VOID: ' ', GIFT: 'x' };
|
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 = {
|
var assets = {
|
||||||
sprites: load_sprites( "HP48" ),
|
sprites: load_sprites( "HP48" ),
|
||||||
|
@ -273,16 +273,10 @@ function initialize_a_star( dom_container, level_index ) {
|
||||||
} else if ( e.type === "keydown" ) {
|
} else if ( e.type === "keydown" ) {
|
||||||
switch( e.keyCode ) {
|
switch( e.keyCode ) {
|
||||||
case 38: // UP
|
case 38: // UP
|
||||||
state = make_a_move( direction.UP );
|
|
||||||
break;
|
|
||||||
case 40: // DOWN
|
case 40: // DOWN
|
||||||
state = make_a_move( direction.DOWN );
|
|
||||||
break;
|
|
||||||
case 37: // LEFT
|
case 37: // LEFT
|
||||||
state = make_a_move( direction.LEFT );
|
|
||||||
break;
|
|
||||||
case 39: // RIGHT
|
case 39: // RIGHT
|
||||||
state = make_a_move( direction.RIGHT );
|
state = make_a_move( e.keyCode );
|
||||||
break;
|
break;
|
||||||
case 32: // SPACE
|
case 32: // SPACE
|
||||||
state = switch_actor( );
|
state = switch_actor( );
|
||||||
|
|
Loading…
Reference in a new issue