Acme-Monkey

 view release on metacpan or  search on metacpan

bin/monkey_life.pl  view on Meta::CPAN

use Acme::Monkey::Frame::Layer;
use Term::ANSIColor qw( :constants );
use Time::HiRes qw( sleep );
use Term::ReadKey;

my $frame = Acme::Monkey::Frame->new(
    width  => 20,
    height => 10,
);

my $background = Acme::Monkey::Frame::Layer->new(
    width  => $frame->width(),
    height => $frame->height(),
    color  => GREEN,
);

foreach my $x (1..$background->width()) {
foreach my $y (1..$background->height()) {
    my $folliage = int( rand() * 12) -6;
    if ($folliage < 3) {
        $background->set( $x, $y, '.' );
    }
    elsif ($folliage==3) {
        $background->set( $x, $y, '%' );
    }
    elsif ($folliage==4) {
        $background->set( $x, $y, 'X' );
    }
    else {
        $background->set( $x, $y, '+' );
    }
}
}

$frame->layers->{z} = $background;

my $food = Acme::Monkey::Frame::Layer->new(
    width  => $frame->width(),
    height => $frame->height(),
    color  => BOLD.YELLOW,
);
$frame->layers->{x} = $food;

my %monkeys;
my $monkey_id = 1;

bin/monkey_ship.pl  view on Meta::CPAN

use Acme::Monkey::Frame::Layer;
use Term::ReadKey;
use Term::ANSIColor qw( :constants );
use Time::HiRes qw( sleep );

my $frame = Acme::Monkey::Frame->new(
    width  => 30,
    height => 11,
);

my $background = Acme::Monkey::Frame::Layer->new(
    width  => $frame->width() * 20,
    height => $frame->height(),
);

foreach (1..int( ($background->width() * $background->height()) / 8 )) {
    my $x = (int( rand() * $background->width() ) * 2) + 1;
    my $y = int( rand() * $background->height() ) + 1;
    my $char = ($background->get($x, $y)) ? 'o' : '.';
    $background->set( $x, $y, $char );
}

$frame->layers->{z} = $background;

my $ship = Acme::Monkey::Frame::Layer->new(
    x => 2,
    y => 4,
    width  => 4,
    height => 3,
    color  => BOLD.CYAN,
);
$ship->set(
    1, 1,

bin/monkey_ship.pl  view on Meta::CPAN

        }
        if ($laser->y() == $enemy->y() and $laser->x() >= $enemy->x()-1) {
            $laser->hidden( 1 );
            $enemy->hidden( 1 );
            $boom->y( $enemy->y() - 1 );
            $boom->x( $enemy->x() - 2 );
            $boom->hidden( 0 );
        }
    }

    $background->move_left();
    $frame->draw();

    if (!$boom->hidden()) {
        print "\n\nYOU WON!!!\n";
        last;
    }

    print "\nw = Up.  s = Down.  a = Left.  d = Right.\n<space> = Shoot.\nx = Exit.";

    sleep .2;



( run in 0.575 second using v1.01-cache-2.11-cpan-d8267643d1d )