Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor horizontal lines and starting points

  • Loading branch information...
commit f1c6e0857f1421617e5fae23b5e3b005de77e28e 1 parent 91076dd
@jtpalmer authored
Showing with 10 additions and 16 deletions.
  1. +10 −16 week4/lib/Games/ElectricLines.pm
View
26 week4/lib/Games/ElectricLines.pm
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.