Of course, scripts like this might have a limited audience...
The Lunar Lander is actually a suite of 4 perl scripts, written to run in a UNIX environment. It takes unfair advantage of the UNIX system process ps() to provide control to the lunar module.
Open up one terminal window for the lunar module and one window for the user input.
Run lander.pl in the first tty. If your tty is not 25 rows by 80 columns, specify your view like so:
To fire one of the lander's rockets, run one of the other commands:lander.pl rows columns
I know: it's an absurd, kludgey misuse (abuse?) of a perfectly good UNIX command. But it was fun to write.
rje
P.S. There's quite a bit of room for performance improvement and expansion... for instance, there are no obstacles...
h:
k:#!/usr/bin/perl print "fire right retros...\n"; select undef, undef, undef, 0.1;
l:#!/usr/bin/perl print "fire main thrusters...\n"; select undef, undef, undef, 0.1;
lander.pl:#!/usr/bin/perl print "fire left retros...\n"; select undef, undef, undef, 0.1;
#!/usr/bin/perl my $theight = shift || 25; my $twidth = shift || 80; my @lm = ( ' o ', '/ \\' ); my $play = 'y'; while( $play =~ /y/i ) { my $x = 20; my $y = 5; my $dx = 0; my $dy = -0.01; # forever! { &draw( $x, $dx, $y, $dy ); $dy += 0.005; $dx *= 0.98; $x += $dx unless $x > $twidth - 5; $y += $dy; $dy = -0.1 if $dy < -0.1; $y = 1 if $y < 1; $pids = `ps -e`; $dx -= 0.05 if $pids =~ /\bh\b/; $dx += 0.05 if $pids =~ /\bl\b/; $dy -= 0.05 if $pids =~ /\bk\b/; redo unless $theight - $y < 4; } print "\nVelocity: ", $dy * 100, " m/s\n"; if ( $dy > 0.1 ) { print "I'm sorry, you have crashed!\n"; } else { print "Congratulations, you are an ace Lunar pilot!\n"; } print "Play Again?"; $play = <STDIN>; } sub draw { my ($x, $dx, $y, $dy ) = @_; `clear`; print "x: ", int($x*100), " dx: ", int($dx*100), " y: ", int(($theight-$y-4)*100), " m dy: ", int($dy*100), " m/s\n"; if ( $y > 1 ) { print "\n" x $y; print " " x $x; print $lm[0], "\n"; print " " x $x; print $lm[1]; print "\n" x ($theight - $y - 2); } else { print "\n" x ($theight-2); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
ANSI based game graphics ...
by johanvdb (Beadle) on Jan 15, 2002 at 07:31 UTC | |
by libero (Initiate) on Jan 17, 2002 at 21:07 UTC |