Permalink
Browse files

Restart when 'r' key is pressed

  • Loading branch information...
1 parent 1f357f7 commit 1aafdf8f1c300b3e2f465d41432c6b61fb738473 @jtpalmer committed Jan 9, 2011
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/Games/Sokoban/SDL.pm
View
@@ -49,6 +49,8 @@ sub init_level {
my $level
= Games::Sokoban->new_from_file( $share_dir->file('level1.sok') );
+ @boxes = ();
+
$background->draw_rect( [ 0, 0, 640, 480 ], 0x000000ff );
my ( $x, $y ) = ( 0, 0 );
foreach my $row ( $level->as_lines ) {
@@ -161,6 +163,8 @@ sub handle_event {
my ( $e, $app ) = @_;
if ( $e->type == SDL_KEYDOWN ) {
+ init_level() if SDL::Events::get_key_name($e->key_sym) eq 'r';
+
if ( !$player_moving && !$player_vx && !$player_vy ) {
move_player('west') if $e->key_sym == SDLK_LEFT;
move_player('east') if $e->key_sym == SDLK_RIGHT;

0 comments on commit 1aafdf8

Please sign in to comment.