Skip to content

Commit

Permalink
Better stopping/turning
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Jan 22, 2011
1 parent 55b1ef4 commit fcb1fac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bin/sokoban.pl
Expand Up @@ -187,7 +187,9 @@ sub move_player {
}

sub stop_player {
$PLAYER{want_direction} = undef;
my ($direction) = @_;

$PLAYER{want_direction} = undef if $PLAYER{want_direction} eq $direction;
}

sub wall_at {
Expand Down Expand Up @@ -218,10 +220,10 @@ sub handle_event {
move_player('south') if $event->key_sym == SDLK_DOWN;
}
elsif ( $event->type == SDL_KEYUP ) {
stop_player() if $event->key_sym == SDLK_LEFT;
stop_player() if $event->key_sym == SDLK_RIGHT;
stop_player() if $event->key_sym == SDLK_UP;
stop_player() if $event->key_sym == SDLK_DOWN;
stop_player('west') if $event->key_sym == SDLK_LEFT;
stop_player('east') if $event->key_sym == SDLK_RIGHT;
stop_player('north') if $event->key_sym == SDLK_UP;
stop_player('south') if $event->key_sym == SDLK_DOWN;
}
}

Expand Down

0 comments on commit fcb1fac

Please sign in to comment.