#!/usr/bin/perl use strict; use warnings; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; my $rows = 50; ReadMode('noecho'); cls; setscroll (1, $rows); locate 1, 1; my @screenRows; # Create the initial screen push @screenRows, newRow() for 1 .. $rows; print join "\n", @screenRows, ''; my $wait = 1; my $skierx = 40; while (1) { if (defined(my $key = ReadKey(-1))) { if ($key eq "j") { --$skierx; } elsif ($key eq "k") { ++$skierx; } elsif ($key eq "x") { exit; } } # Generate and show a new line shift @screenRows; push @screenRows, newRow(); print $screenRows[-1]; # Collision detection if (' ' ne substr $screenRows[$rows / 2], $skierx - 1, 1) { locate $rows, 1; print "Crash!\n"; exit; } # Show skier's updated position locate $rows / 2, $skierx; print "V"; # wait select(undef, undef, undef, $wait); #pauses here $wait -= 0.003; } sub newRow { my $col = int(rand(80)); return ' ' x $col . 'T' . (' ' x (78 - $col)); }