Skip to content

Commit

Permalink
Omit rectangles where optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Jan 10, 2011
1 parent a6c8bd0 commit 8e2713b
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/Games/Sokoban/SDL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,20 @@ sub init_level {

@boxes = ();

$background->draw_rect( [ 0, 0, 640, 480 ], 0x000000ff );
$background->draw_rect( undef, 0x000000ff );
my ( $x, $y ) = ( 0, 0 );
foreach my $row ( $level->as_lines ) {
$x = 0;
foreach my $element ( split //, $row ) {
given ($element) {
$grid->[$x][$y] = $_;
when ('#') {
$wall->blit(
$background,
[ 0, 0, $size, $size ],
[ $x * $size, $y * $size, $size, $size ]
);
$wall->blit( $background, undef,
[ $x * $size, $y * $size, $size, $size ] );
}
when ('.') {
$goal->blit(
$background,
[ 0, 0, $size, $size ],
[ $x * $size, $y * $size, $size, $size ]
);
$goal->blit( $background, undef,
[ $x * $size, $y * $size, $size, $size ] );
}
when ('$') {
push @boxes,
Expand All @@ -94,7 +88,6 @@ sub init_level {
}
$y++;
}

}

sub move_player {
Expand Down Expand Up @@ -163,7 +156,7 @@ sub handle_event {
my ( $e, $app ) = @_;

if ( $e->type == SDL_KEYDOWN ) {
init_level() if SDL::Events::get_key_name($e->key_sym) eq 'r';
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;
Expand Down

0 comments on commit 8e2713b

Please sign in to comment.