To calm crazyinsomniac's fears about holding true to the Space Invader's memory. Here's the kind of patches you can add to the code. This one limits the number of onscreen shots for the player to 4 and adds new functionality: a callback mechanism for when missles get destroyed. (It's also a nice demonstration of a closure.)
Inside of missles() add one line:
if ($t::x<$left or $t::y<$top or
$t::x>$right or $t::y>$bot) {
&{$_->{callback}} if ($_->{callback}); #NEW
$_->{sprite}->remove;
There's the callback handler. And then change the anonymous subroutine that handles the ship controls to something like this:
$mw->bind('<Key>', [ sub {
my $curshot=0 if 0; # NEW
# Later in that code block...
elsif ($_[1] == $Sprite::keycode::fire ) {
return if $curshot>3; #NEW
$curshot++; #NEW
my $gun=new Sprite($c);
$gun->image($img{"missle.gif"});
$gun->names("missle","weapon");
$gun->place($t::x, $t::y);
push(@missles, {
direction => -1,
callback => sub {$curshot--}, #NEW
sprite => $gun,
});
}
And so in 5 lines we can control the number of shots fired by the hero. This can also be used to modify the number of shots fired by the aliens.
And that's why this is a demo. It's for modifying and playing with, and only a framework.