Skip to content

Commit

Permalink
Refactor horizontal lines and starting points
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Mar 27, 2011
1 parent 91076dd commit f1c6e08
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions week4/lib/Games/ElectricLines.pm
Expand Up @@ -99,30 +99,24 @@ sub _build_sprite {
sub _build_starting_points {
my ($self) = @_;

return [ map { $_->[0] } @{ $self->_horizontal_lines } ];
}

sub _build_horizontal_lines {
my ($self) = @_;

my $count = 4;

my $app = $self->_app;
my $space = $app->h / $count;
my $x = $self->_sprite->rect->w / 2;

my @points;
my $x0 = $self->_sprite->rect->w / 2;
my $x1 = $app->w - $self->_sprite->rect->w / 2;

my @lines;
foreach my $i ( 1 .. $count ) {
my $y = ( $i - 0.5 ) * $space;
push @points, [ $x, $y ];
}

return \@points;
}

sub _build_horizontal_lines {
my ($self) = @_;

my $x = $self->_app->w - $self->_sprite->rect->w / 2;

my @lines;
foreach my $point ( @{ $self->_starting_points } ) {
push @lines, [ $point, [ $x, $point->[1] ] ];
push @lines, [ [ $x0, $y ], [ $x1, $y ] ];
}

return \@lines;
Expand Down

0 comments on commit f1c6e08

Please sign in to comment.