Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic scoring and life loss

  • Loading branch information...
commit 2fd56fa91658934c6b40b74989ce9d01c2313351 1 parent c8e2699
@jtpalmer authored
Showing with 21 additions and 3 deletions.
  1. +21 −3 week4/lib/Games/ElectricLines.pm
View
24 week4/lib/Games/ElectricLines.pm
@@ -215,6 +215,8 @@ sub _store_active_line {
sub handle_move {
my ( $self, $step, $app, $t ) = @_;
+ return unless $self->_lives > 0;
+
if ( $t > $self->_plasma_time + $self->_plasma_frequency ) {
$self->_plasma_time($t);
$self->_add_plasma();
@@ -223,10 +225,26 @@ sub handle_move {
my @plasma;
foreach my $plasma ( @{ $self->_plasma } ) {
$self->_move_plasma( $plasma, $step );
- push @plasma, $plasma
- if $plasma->{x} < $app->w - $self->_sprite->rect->w / 2;
+ if ( $plasma->{x} < $app->w - $self->_sprite->rect->w / 2 ) {
+ push @plasma, $plasma;
+ }
+ else {
+ if ( grep { $plasma->{y} == $_->[1] } @{ $self->_exits } ) {
+ $self->_score( $self->_score + 1 );
+ }
+ else {
+ $self->_lives( $self->_lives - 1 );
+ }
+ }
+ }
+
+ if ( $self->_lives <= 0 ) {
+ $self->_lives(0);
+ @{ $self->_plasma } = ();
+ }
+ else {
+ @{ $self->_plasma } = @plasma;
}
- @{ $self->_plasma } = @plasma;
}
sub handle_show {

0 comments on commit 2fd56fa

Please sign in to comment.
Something went wrong with that request. Please try again.